1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66

ash / dbus / display_service_provider.h [blame]

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_DBUS_DISPLAY_SERVICE_PROVIDER_H_
#define ASH_DBUS_DISPLAY_SERVICE_PROVIDER_H_

#include <memory>
#include <string>

#include "base/memory/weak_ptr.h"
#include "chromeos/ash/components/dbus/services/cros_dbus_service.h"
#include "dbus/exported_object.h"

namespace ash {

// This class implements org.chromium.DisplayService for chrome.
class DisplayServiceProvider
    : public CrosDBusService::ServiceProviderInterface {
 public:
  // The caller must ensure that |delegate| outlives this object.
  DisplayServiceProvider();

  DisplayServiceProvider(const DisplayServiceProvider&) = delete;
  DisplayServiceProvider& operator=(const DisplayServiceProvider&) = delete;

  ~DisplayServiceProvider() override;

  // CrosDBusService::ServiceProviderInterface overrides:
  void Start(scoped_refptr<dbus::ExportedObject> exported_object) override;

 private:
  class Impl;

  // Forwards DBus calls to DisplayConfigurator::SetDisplayPower.
  void SetDisplayPower(dbus::MethodCall* method_call,
                       dbus::ExportedObject::ResponseSender response_sender);

  // Forwards DBus calls to ScreenDimmer::SetDimming.
  void SetDisplaySoftwareDimming(
      dbus::MethodCall* method_call,
      dbus::ExportedObject::ResponseSender response_sender);

  // Called when a external process no longer needs control of the display and
  // Chrome can take ownership. Forwarded to mojom::AshDisplayController.
  void TakeDisplayOwnership(
      dbus::MethodCall* method_call,
      dbus::ExportedObject::ResponseSender response_sender);

  // Called when a external process needs control of the display and needs
  // Chrome to release ownership. Forwarded to mojom::AshDisplayController.
  void ReleaseDisplayOwnership(
      dbus::MethodCall* method_call,
      dbus::ExportedObject::ResponseSender response_sender);

  void OnExported(const std::string& interface_name,
                  const std::string& method_name,
                  bool success);

  std::unique_ptr<Impl> impl_;
  base::WeakPtrFactory<DisplayServiceProvider> weak_ptr_factory_{this};
};

}  // namespace ash

#endif  // ASH_DBUS_DISPLAY_SERVICE_PROVIDER_H_