summaryrefslogtreecommitdiffstats
path: root/chromeos/dbus/services/display_power_service_provider.h
blob: 132c45d88e9f9c4253c42941e1325e760ab1153d (plain)
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
67
68
69
70
71
72
73
74
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_DBUS_SERVICES_DISPLAY_POWER_SERVICE_PROVIDER_H_
#define CHROMEOS_DBUS_SERVICES_DISPLAY_POWER_SERVICE_PROVIDER_H_

#include <string>

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chromeos/chromeos_export.h"
#include "chromeos/dbus/services/cros_dbus_service.h"
#include "dbus/exported_object.h"
#include "third_party/cros_system_api/dbus/service_constants.h"

namespace dbus {
class MethodCall;
}

namespace chromeos {

// This class exports "SetDisplayPower" and "SetDisplaySoftwareDimming"
// D-Bus methods that the power manager calls to instruct Chrome to turn
// various displays on or off or dim them.
class CHROMEOS_EXPORT DisplayPowerServiceProvider
    : public CrosDBusService::ServiceProviderInterface {
 public:
  class Delegate {
   public:
    virtual ~Delegate() {}

    // Sets the display power state.
    virtual void SetDisplayPower(DisplayPowerState power_state) = 0;

    // Dims or undims the screen.
    virtual void SetDimming(bool dimmed) = 0;
  };

  explicit DisplayPowerServiceProvider(scoped_ptr<Delegate> delegate);
  ~DisplayPowerServiceProvider() override;

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

 private:
  // Called from ExportedObject when a handler is exported as a D-Bus
  // method or failed to be exported.
  void OnExported(const std::string& interface_name,
                  const std::string& method_name,
                  bool success);

  // Called on UI thread in response to D-Bus requests.
  void SetDisplayPower(dbus::MethodCall* method_call,
                       dbus::ExportedObject::ResponseSender response_sender);
  void SetDisplaySoftwareDimming(
      dbus::MethodCall* method_call,
      dbus::ExportedObject::ResponseSender response_sender);

  scoped_ptr<Delegate> delegate_;

  // Keep this last so that all weak pointers will be invalidated at the
  // beginning of destruction.
  base::WeakPtrFactory<DisplayPowerServiceProvider> weak_ptr_factory_;

  DISALLOW_COPY_AND_ASSIGN(DisplayPowerServiceProvider);
};

}  // namespace chromeos

#endif  // CHROMEOS_DBUS_SERVICES_DISPLAY_POWER_SERVICE_PROVIDER_H_