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. 4 5#ifndef CHROME_BROWSER_CHROMEOS_DBUS_DISPLAY_POWER_SERVICE_PROVIDER_H_ 6#define CHROME_BROWSER_CHROMEOS_DBUS_DISPLAY_POWER_SERVICE_PROVIDER_H_ 7 8#include <string> 9 10#include "base/basictypes.h" 11#include "base/compiler_specific.h" 12#include "base/memory/ref_counted.h" 13#include "base/memory/weak_ptr.h" 14#include "chrome/browser/chromeos/dbus/cros_dbus_service.h" 15#include "dbus/exported_object.h" 16 17namespace dbus { 18class MethodCall; 19class Response; 20} 21 22namespace chromeos { 23 24// This class exports "SetDisplayPower" and "SetDisplaySoftwareDimming" 25// D-Bus methods that the power manager calls to instruct Chrome to turn 26// various displays on or off or dim them. 27class DisplayPowerServiceProvider 28 : public CrosDBusService::ServiceProviderInterface { 29 public: 30 DisplayPowerServiceProvider(); 31 virtual ~DisplayPowerServiceProvider(); 32 33 // CrosDBusService::ServiceProviderInterface overrides: 34 virtual void Start( 35 scoped_refptr<dbus::ExportedObject> exported_object) OVERRIDE; 36 37 private: 38 // Called from ExportedObject when a handler is exported as a D-Bus 39 // method or failed to be exported. 40 void OnExported(const std::string& interface_name, 41 const std::string& method_name, 42 bool success); 43 44 // Called on UI thread in response to D-Bus requests. 45 void SetDisplayPower(dbus::MethodCall* method_call, 46 dbus::ExportedObject::ResponseSender response_sender); 47 void SetDisplaySoftwareDimming( 48 dbus::MethodCall* method_call, 49 dbus::ExportedObject::ResponseSender response_sender); 50 51 // Keep this last so that all weak pointers will be invalidated at the 52 // beginning of destruction. 53 base::WeakPtrFactory<DisplayPowerServiceProvider> weak_ptr_factory_; 54 55 DISALLOW_COPY_AND_ASSIGN(DisplayPowerServiceProvider); 56}; 57 58} // namespace chromeos 59 60#endif // CHROME_BROWSER_CHROMEOS_DBUS_DISPLAY_POWER_SERVICE_PROVIDER_H_ 61