Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(688)

Side by Side Diff: chrome/browser/chromeos/dbus/display_power_service_provider.cc

Issue 12391004: chromeos: Add DisplayPowerServiceProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ugh, TrayDisplay was including output_configurator.h on windows Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 #include "chrome/browser/chromeos/dbus/display_power_service_provider.h"
6
7 #include "ash/shell.h"
8 #include "ash/wm/user_activity_detector.h"
9 #include "base/bind.h"
10 #include "chromeos/display/output_configurator.h"
11 #include "dbus/bus.h"
12 #include "dbus/message.h"
13 #include "third_party/cros_system_api/dbus/service_constants.h"
14
15 namespace chromeos {
16
17 DisplayPowerServiceProvider::DisplayPowerServiceProvider()
18 : weak_ptr_factory_(this) {
19 }
20
21 DisplayPowerServiceProvider::~DisplayPowerServiceProvider() {}
22
23 void DisplayPowerServiceProvider::Start(
24 scoped_refptr<dbus::ExportedObject> exported_object) {
25 exported_object->ExportMethod(
26 kLibCrosServiceInterface,
27 kSetDisplayPower,
28 base::Bind(&DisplayPowerServiceProvider::SetDisplayPower,
29 weak_ptr_factory_.GetWeakPtr()),
30 base::Bind(&DisplayPowerServiceProvider::OnExported,
31 weak_ptr_factory_.GetWeakPtr()));
32 }
33
34 void DisplayPowerServiceProvider::OnExported(const std::string& interface_name,
35 const std::string& method_name,
36 bool success) {
37 if (!success) {
38 LOG(ERROR) << "Failed to export " << interface_name << "."
39 << method_name;
40 }
41 }
42
43 void DisplayPowerServiceProvider::SetDisplayPower(
44 dbus::MethodCall* method_call,
45 dbus::ExportedObject::ResponseSender response_sender) {
46 dbus::MessageReader reader(method_call);
47 int int_state = 0;
48 if (reader.PopInt32(&int_state)) {
49 // Turning displays off when the device becomes idle or on just before
50 // we suspend may trigger a mouse move, which would then be incorrectly
51 // reported as user activity. Let the UserActivityDetector
52 // know so that it can ignore such events.
53 ash::Shell::GetInstance()->user_activity_detector()->
54 OnDisplayPowerChanging();
55
56 DisplayPowerState state = static_cast<DisplayPowerState>(int_state);
57 ash::Shell::GetInstance()->output_configurator()->SetDisplayPower(
58 state, false);
59 } else {
60 LOG(ERROR) << "Unable to parse " << kSetDisplayPower << " request";
61 }
62
63 response_sender.Run(dbus::Response::FromMethodCall(method_call));
64 }
65
66 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698