Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/dbus/power_manager_client.h" | 5 #include "chrome/browser/chromeos/dbus/power_manager_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 base::Bind(&PowerManagerClientImpl::OnIncreaseScreenBrightness, | 121 base::Bind(&PowerManagerClientImpl::OnIncreaseScreenBrightness, |
| 122 weak_ptr_factory_.GetWeakPtr())); | 122 weak_ptr_factory_.GetWeakPtr())); |
| 123 } | 123 } |
| 124 | 124 |
| 125 virtual void RequestStatusUpdate() OVERRIDE { | 125 virtual void RequestStatusUpdate() OVERRIDE { |
| 126 // TODO(stevenjb): chromeos::RetrievePowerInformation has been deprecated; | 126 // TODO(stevenjb): chromeos::RetrievePowerInformation has been deprecated; |
| 127 // we should add a mechanism to immediately request an update, probably | 127 // we should add a mechanism to immediately request an update, probably |
| 128 // when we migrate the DBus code from libcros to here. | 128 // when we migrate the DBus code from libcros to here. |
| 129 } | 129 } |
| 130 | 130 |
| 131 // Requests restart of the system. | |
| 132 virtual void RequestRestart() OVERRIDE { | |
| 133 dbus::MethodCall method_call(power_manager::kPowerManagerInterface, | |
| 134 power_manager::kRequestRestartMethod); | |
| 135 power_manager_proxy_->CallMethod( | |
| 136 &method_call, | |
| 137 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 138 base::Bind(&PowerManagerClientImpl::OnRequestShutdownOrRestart, | |
| 139 weak_ptr_factory_.GetWeakPtr())); | |
|
satorux1
2011/11/11 18:04:59
Please use dbus::ObjectProxy::EmptyResponseCallbac
Simon Que
2011/11/11 18:56:53
Done.
| |
| 140 }; | |
| 141 | |
| 142 // Requests shutdown of the system. | |
| 143 virtual void RequestShutdown() OVERRIDE { | |
| 144 dbus::MethodCall method_call(power_manager::kPowerManagerInterface, | |
| 145 power_manager::kRequestShutdownMethod); | |
| 146 power_manager_proxy_->CallMethod( | |
| 147 &method_call, | |
| 148 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
| 149 base::Bind(&PowerManagerClientImpl::OnRequestShutdownOrRestart, | |
| 150 weak_ptr_factory_.GetWeakPtr())); | |
|
satorux1
2011/11/11 18:04:59
ditto.
Simon Que
2011/11/11 18:56:53
Done.
| |
| 151 } | |
| 152 | |
| 153 | |
| 131 private: | 154 private: |
| 132 // Called when a dbus signal is initially connected. | 155 // Called when a dbus signal is initially connected. |
| 133 void SignalConnected(const std::string& interface_name, | 156 void SignalConnected(const std::string& interface_name, |
| 134 const std::string& signal_name, | 157 const std::string& signal_name, |
| 135 bool success) { | 158 bool success) { |
| 136 LOG_IF(WARNING, !success) << "Failed to connect to signal " | 159 LOG_IF(WARNING, !success) << "Failed to connect to signal " |
| 137 << signal_name << "."; | 160 << signal_name << "."; |
| 138 } | 161 } |
| 139 | 162 |
| 140 // Called when a brightness change signal is received. | 163 // Called when a brightness change signal is received. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 !reader.PopBool(&status.battery_is_full)) { | 236 !reader.PopBool(&status.battery_is_full)) { |
| 214 LOG(ERROR) << "Error reading response from powerd: " | 237 LOG(ERROR) << "Error reading response from powerd: " |
| 215 << response->ToString(); | 238 << response->ToString(); |
| 216 return; | 239 return; |
| 217 } | 240 } |
| 218 | 241 |
| 219 VLOG(1) << "Power status: " << status.ToString(); | 242 VLOG(1) << "Power status: " << status.ToString(); |
| 220 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status)); | 243 FOR_EACH_OBSERVER(Observer, observers_, PowerChanged(status)); |
| 221 } | 244 } |
| 222 | 245 |
| 246 // Dummy callback function for CallMethod. | |
| 247 // TODO(satorux): remove when dbus method call function supports no callback. | |
| 248 void OnRequestShutdownOrRestart(dbus::Response* response) {} | |
|
satorux1
2011/11/11 18:04:59
Remove this now.
Simon Que
2011/11/11 18:56:53
Done.
| |
| 249 | |
| 223 dbus::ObjectProxy* power_manager_proxy_; | 250 dbus::ObjectProxy* power_manager_proxy_; |
| 224 ObserverList<Observer> observers_; | 251 ObserverList<Observer> observers_; |
| 225 base::WeakPtrFactory<PowerManagerClientImpl> weak_ptr_factory_; | 252 base::WeakPtrFactory<PowerManagerClientImpl> weak_ptr_factory_; |
| 226 | 253 |
| 227 DISALLOW_COPY_AND_ASSIGN(PowerManagerClientImpl); | 254 DISALLOW_COPY_AND_ASSIGN(PowerManagerClientImpl); |
| 228 }; | 255 }; |
| 229 | 256 |
| 230 // The PowerManagerClient implementation used on Linux desktop, | 257 // The PowerManagerClient implementation used on Linux desktop, |
| 231 // which does nothing. | 258 // which does nothing. |
| 232 class PowerManagerClientStubImpl : public PowerManagerClient { | 259 class PowerManagerClientStubImpl : public PowerManagerClient { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 264 timer_.Start( | 291 timer_.Start( |
| 265 FROM_HERE, | 292 FROM_HERE, |
| 266 base::TimeDelta::FromMilliseconds(100), | 293 base::TimeDelta::FromMilliseconds(100), |
| 267 this, | 294 this, |
| 268 &PowerManagerClientStubImpl::Update); | 295 &PowerManagerClientStubImpl::Update); |
| 269 } else { | 296 } else { |
| 270 timer_.Stop(); | 297 timer_.Stop(); |
| 271 } | 298 } |
| 272 } | 299 } |
| 273 | 300 |
| 301 virtual void RequestRestart() OVERRIDE {} | |
| 302 | |
| 303 virtual void RequestShutdown() OVERRIDE {} | |
| 304 | |
| 274 private: | 305 private: |
| 275 void Update() { | 306 void Update() { |
| 276 // We pause at 0 and 100% so that it's easier to check those conditions. | 307 // We pause at 0 and 100% so that it's easier to check those conditions. |
| 277 if (pause_count_ > 1) { | 308 if (pause_count_ > 1) { |
| 278 pause_count_--; | 309 pause_count_--; |
| 279 return; | 310 return; |
| 280 } | 311 } |
| 281 | 312 |
| 282 if (battery_percentage_ == 0 || battery_percentage_ == 100) { | 313 if (battery_percentage_ == 0 || battery_percentage_ == 100) { |
| 283 if (pause_count_) { | 314 if (pause_count_) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 | 348 |
| 318 PowerManagerClient* PowerManagerClient::Create(dbus::Bus* bus) { | 349 PowerManagerClient* PowerManagerClient::Create(dbus::Bus* bus) { |
| 319 if (system::runtime_environment::IsRunningOnChromeOS()) { | 350 if (system::runtime_environment::IsRunningOnChromeOS()) { |
| 320 return new PowerManagerClientImpl(bus); | 351 return new PowerManagerClientImpl(bus); |
| 321 } else { | 352 } else { |
| 322 return new PowerManagerClientStubImpl(); | 353 return new PowerManagerClientStubImpl(); |
| 323 } | 354 } |
| 324 } | 355 } |
| 325 | 356 |
| 326 } // namespace chromeos | 357 } // namespace chromeos |
| OLD | NEW |