Chromium Code Reviews| Index: chrome/browser/chromeos/dbus/display_power_service_provider.cc |
| diff --git a/chrome/browser/chromeos/dbus/display_power_service_provider.cc b/chrome/browser/chromeos/dbus/display_power_service_provider.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..578601498ec7b86123565ea728bf4c841b89aa8f |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/dbus/display_power_service_provider.cc |
| @@ -0,0 +1,75 @@ |
| +// 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. |
| + |
| +#include "chrome/browser/chromeos/dbus/display_power_service_provider.h" |
| + |
| +#include "ash/shell.h" |
| +#include "ash/wm/user_activity_detector.h" |
| +#include "base/bind.h" |
| +#include "chromeos/display/output_configurator.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "dbus/bus.h" |
| +#include "dbus/message.h" |
| +#include "third_party/cros_system_api/dbus/service_constants.h" |
| + |
| +using content::BrowserThread; |
| + |
| +namespace chromeos { |
| + |
| +DisplayPowerServiceProvider::DisplayPowerServiceProvider() |
| + : weak_ptr_factory_(this) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| +} |
| + |
| +DisplayPowerServiceProvider::~DisplayPowerServiceProvider() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| +} |
| + |
| +void DisplayPowerServiceProvider::Start( |
| + scoped_refptr<dbus::ExportedObject> exported_object) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + exported_object->ExportMethod( |
| + kLibCrosServiceInterface, |
| + kSetDisplayPower, |
| + base::Bind(&DisplayPowerServiceProvider::SetDisplayPower, |
| + weak_ptr_factory_.GetWeakPtr()), |
| + base::Bind(&DisplayPowerServiceProvider::OnExported, |
| + weak_ptr_factory_.GetWeakPtr())); |
| +} |
| + |
| +void DisplayPowerServiceProvider::OnExported(const std::string& interface_name, |
| + const std::string& method_name, |
| + bool success) { |
| + if (!success) { |
| + LOG(ERROR) << "Failed to export " << interface_name << "." |
| + << method_name; |
| + } |
| +} |
| + |
| +void DisplayPowerServiceProvider::SetDisplayPower( |
| + dbus::MethodCall* method_call, |
| + dbus::ExportedObject::ResponseSender response_sender) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + |
| + dbus::MessageReader reader(method_call); |
| + int int_state = 0; |
| + if (reader.PopInt32(&int_state)) { |
| + DisplayPowerState state = static_cast<DisplayPowerState>(int_state); |
| + if (state == DISPLAY_POWER_ALL_OFF) { |
| + // All displays are turned off when the device becomes idle, which |
| + // may trigger a mouse move. Let the UserActivityDetector know so |
| + // that it can ignore such events. |
|
marcheu
2013/02/28 04:58:59
So I think this applies to all root window resizes
Daniel Erat
2013/02/28 18:13:13
Probably; I was just copying over the existing log
|
| + ash::Shell::GetInstance()->user_activity_detector()-> |
| + OnAllOutputsTurnedOff(); |
| + } |
| + ash::Shell::GetInstance()->output_configurator()->SetDisplayPowerState( |
| + state); |
| + } else { |
| + LOG(ERROR) << "Unable to parse " << kSetDisplayPower << " request"; |
| + } |
| + |
| + response_sender.Run(dbus::Response::FromMethodCall(method_call)); |
| +} |
| + |
| +} // namespace chromeos |