Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chromeos / dbus / services / display_power_service_provider.cc
blob1dc1d688e0e62c8caacd94f90dd060d4b33b2aae
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 #include "chromeos/dbus/services/display_power_service_provider.h"
7 #include "base/bind.h"
8 #include "dbus/message.h"
10 namespace chromeos {
12 namespace {
14 void RunConfigurationCallback(
15 dbus::MethodCall* method_call,
16 dbus::ExportedObject::ResponseSender response_sender,
17 bool status) {
18 response_sender.Run(dbus::Response::FromMethodCall(method_call));
21 } // namespace
23 DisplayPowerServiceProvider::DisplayPowerServiceProvider(
24 scoped_ptr<Delegate> delegate)
25 : delegate_(delegate.Pass()),
26 weak_ptr_factory_(this) {
29 DisplayPowerServiceProvider::~DisplayPowerServiceProvider() {}
31 void DisplayPowerServiceProvider::Start(
32 scoped_refptr<dbus::ExportedObject> exported_object) {
33 exported_object->ExportMethod(
34 kLibCrosServiceInterface,
35 kSetDisplayPower,
36 base::Bind(&DisplayPowerServiceProvider::SetDisplayPower,
37 weak_ptr_factory_.GetWeakPtr()),
38 base::Bind(&DisplayPowerServiceProvider::OnExported,
39 weak_ptr_factory_.GetWeakPtr()));
40 exported_object->ExportMethod(
41 kLibCrosServiceInterface,
42 kSetDisplaySoftwareDimming,
43 base::Bind(&DisplayPowerServiceProvider::SetDisplaySoftwareDimming,
44 weak_ptr_factory_.GetWeakPtr()),
45 base::Bind(&DisplayPowerServiceProvider::OnExported,
46 weak_ptr_factory_.GetWeakPtr()));
49 void DisplayPowerServiceProvider::OnExported(const std::string& interface_name,
50 const std::string& method_name,
51 bool success) {
52 if (!success) {
53 LOG(ERROR) << "Failed to export " << interface_name << "."
54 << method_name;
58 void DisplayPowerServiceProvider::SetDisplayPower(
59 dbus::MethodCall* method_call,
60 dbus::ExportedObject::ResponseSender response_sender) {
61 dbus::MessageReader reader(method_call);
62 int int_state = 0;
63 Delegate::ResponseCallback callback =
64 base::Bind(&RunConfigurationCallback, method_call, response_sender);
65 if (reader.PopInt32(&int_state)) {
66 DisplayPowerState state = static_cast<DisplayPowerState>(int_state);
67 delegate_->SetDisplayPower(state, callback);
68 } else {
69 LOG(ERROR) << "Unable to parse " << kSetDisplayPower << " request";
70 callback.Run(false);
74 void DisplayPowerServiceProvider::SetDisplaySoftwareDimming(
75 dbus::MethodCall* method_call,
76 dbus::ExportedObject::ResponseSender response_sender) {
77 dbus::MessageReader reader(method_call);
78 bool dimmed = false;
79 if (reader.PopBool(&dimmed)) {
80 delegate_->SetDimming(dimmed);
81 } else {
82 LOG(ERROR) << "Unable to parse " << kSetDisplaySoftwareDimming
83 << " request";
85 response_sender.Run(dbus::Response::FromMethodCall(method_call));
88 } // namespace chromeos