Don't preload rarely seen large images
[chromium-blink-merge.git] / chromeos / dbus / services / display_power_service_provider.h
blobbdfc093050ce71c949ef0014e7503fb14de42de9
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROMEOS_DBUS_SERVICES_DISPLAY_POWER_SERVICE_PROVIDER_H_
6 #define CHROMEOS_DBUS_SERVICES_DISPLAY_POWER_SERVICE_PROVIDER_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "chromeos/chromeos_export.h"
16 #include "chromeos/dbus/services/cros_dbus_service.h"
17 #include "dbus/exported_object.h"
18 #include "third_party/cros_system_api/dbus/service_constants.h"
20 namespace dbus {
21 class MethodCall;
24 namespace chromeos {
26 // This class exports "SetDisplayPower" and "SetDisplaySoftwareDimming"
27 // D-Bus methods that the power manager calls to instruct Chrome to turn
28 // various displays on or off or dim them.
29 class CHROMEOS_EXPORT DisplayPowerServiceProvider
30 : public CrosDBusService::ServiceProviderInterface {
31 public:
32 class Delegate {
33 public:
34 typedef base::Callback<void(bool)> ResponseCallback;
36 virtual ~Delegate() {}
38 // Sets the display power state. After the display power is set, |callback|
39 // is called with the operation status.
40 virtual void SetDisplayPower(DisplayPowerState power_state,
41 const ResponseCallback& callback) = 0;
43 // Dims or undims the screen.
44 virtual void SetDimming(bool dimmed) = 0;
47 explicit DisplayPowerServiceProvider(scoped_ptr<Delegate> delegate);
48 ~DisplayPowerServiceProvider() override;
50 // CrosDBusService::ServiceProviderInterface overrides:
51 void Start(scoped_refptr<dbus::ExportedObject> exported_object) override;
53 private:
54 // Called from ExportedObject when a handler is exported as a D-Bus
55 // method or failed to be exported.
56 void OnExported(const std::string& interface_name,
57 const std::string& method_name,
58 bool success);
60 // Called on UI thread in response to D-Bus requests.
61 void SetDisplayPower(dbus::MethodCall* method_call,
62 dbus::ExportedObject::ResponseSender response_sender);
63 void SetDisplaySoftwareDimming(
64 dbus::MethodCall* method_call,
65 dbus::ExportedObject::ResponseSender response_sender);
67 scoped_ptr<Delegate> delegate_;
69 // Keep this last so that all weak pointers will be invalidated at the
70 // beginning of destruction.
71 base::WeakPtrFactory<DisplayPowerServiceProvider> weak_ptr_factory_;
73 DISALLOW_COPY_AND_ASSIGN(DisplayPowerServiceProvider);
76 } // namespace chromeos
78 #endif // CHROMEOS_DBUS_SERVICES_DISPLAY_POWER_SERVICE_PROVIDER_H_