OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chromeos/dbus/power_manager_client.h" | 5 #include "chromeos/dbus/power_manager_client.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
41 const char kSuspendDelayDescription[] = "chrome"; | 41 const char kSuspendDelayDescription[] = "chrome"; |
42 | 42 |
43 // The PowerManagerClient implementation used in production. | 43 // The PowerManagerClient implementation used in production. |
44 class PowerManagerClientImpl : public PowerManagerClient { | 44 class PowerManagerClientImpl : public PowerManagerClient { |
45 public: | 45 public: |
46 PowerManagerClientImpl() | 46 PowerManagerClientImpl() |
47 : origin_thread_id_(base::PlatformThread::CurrentId()), | 47 : origin_thread_id_(base::PlatformThread::CurrentId()), |
48 power_manager_proxy_(NULL), | 48 power_manager_proxy_(NULL), |
49 suspend_delay_id_(-1), | 49 suspend_delay_id_(-1), |
50 has_suspend_delay_id_(false), | 50 has_suspend_delay_id_(false), |
51 dark_suspend_delay_id_(-1), | |
52 has_dark_suspend_delay_id_(false), | |
51 pending_suspend_id_(-1), | 53 pending_suspend_id_(-1), |
52 suspend_is_pending_(false), | 54 suspend_is_pending_(false), |
55 suspending_from_dark_resume_(false), | |
53 num_pending_suspend_readiness_callbacks_(0), | 56 num_pending_suspend_readiness_callbacks_(0), |
54 last_is_projecting_(false), | 57 last_is_projecting_(false), |
55 weak_ptr_factory_(this) {} | 58 weak_ptr_factory_(this) {} |
56 | 59 |
57 virtual ~PowerManagerClientImpl() { | 60 virtual ~PowerManagerClientImpl() { |
58 // Here we should unregister suspend notifications from powerd, | 61 // Here we should unregister suspend notifications from powerd, |
59 // however: | 62 // however: |
60 // - The lifetime of the PowerManagerClientImpl can extend past that of | 63 // - The lifetime of the PowerManagerClientImpl can extend past that of |
61 // the objectproxy, | 64 // the objectproxy, |
62 // - power_manager can already detect that the client is gone and | 65 // - power_manager can already detect that the client is gone and |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 210 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
208 dbus::ObjectProxy::EmptyResponseCallback()); | 211 dbus::ObjectProxy::EmptyResponseCallback()); |
209 last_is_projecting_ = is_projecting; | 212 last_is_projecting_ = is_projecting; |
210 } | 213 } |
211 | 214 |
212 virtual base::Closure GetSuspendReadinessCallback() OVERRIDE { | 215 virtual base::Closure GetSuspendReadinessCallback() OVERRIDE { |
213 DCHECK(OnOriginThread()); | 216 DCHECK(OnOriginThread()); |
214 DCHECK(suspend_is_pending_); | 217 DCHECK(suspend_is_pending_); |
215 num_pending_suspend_readiness_callbacks_++; | 218 num_pending_suspend_readiness_callbacks_++; |
216 return base::Bind(&PowerManagerClientImpl::HandleObserverSuspendReadiness, | 219 return base::Bind(&PowerManagerClientImpl::HandleObserverSuspendReadiness, |
217 weak_ptr_factory_.GetWeakPtr(), pending_suspend_id_); | 220 weak_ptr_factory_.GetWeakPtr(), pending_suspend_id_, |
221 suspending_from_dark_resume_); | |
218 } | 222 } |
219 | 223 |
220 virtual int GetNumPendingSuspendReadinessCallbacks() OVERRIDE { | 224 virtual int GetNumPendingSuspendReadinessCallbacks() OVERRIDE { |
221 return num_pending_suspend_readiness_callbacks_; | 225 return num_pending_suspend_readiness_callbacks_; |
222 } | 226 } |
223 | 227 |
224 protected: | 228 protected: |
225 virtual void Init(dbus::Bus* bus) OVERRIDE { | 229 virtual void Init(dbus::Bus* bus) OVERRIDE { |
226 power_manager_proxy_ = bus->GetObjectProxy( | 230 power_manager_proxy_ = bus->GetObjectProxy( |
227 power_manager::kPowerManagerServiceName, | 231 power_manager::kPowerManagerServiceName, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
263 power_manager::kInputEventSignal, | 267 power_manager::kInputEventSignal, |
264 base::Bind(&PowerManagerClientImpl::InputEventReceived, | 268 base::Bind(&PowerManagerClientImpl::InputEventReceived, |
265 weak_ptr_factory_.GetWeakPtr()), | 269 weak_ptr_factory_.GetWeakPtr()), |
266 base::Bind(&PowerManagerClientImpl::SignalConnected, | 270 base::Bind(&PowerManagerClientImpl::SignalConnected, |
267 weak_ptr_factory_.GetWeakPtr())); | 271 weak_ptr_factory_.GetWeakPtr())); |
268 | 272 |
269 power_manager_proxy_->ConnectToSignal( | 273 power_manager_proxy_->ConnectToSignal( |
270 power_manager::kPowerManagerInterface, | 274 power_manager::kPowerManagerInterface, |
271 power_manager::kSuspendImminentSignal, | 275 power_manager::kSuspendImminentSignal, |
272 base::Bind( | 276 base::Bind( |
273 &PowerManagerClientImpl::SuspendImminentReceived, | 277 &PowerManagerClientImpl::HandleSuspendImminent, |
274 weak_ptr_factory_.GetWeakPtr()), | 278 weak_ptr_factory_.GetWeakPtr(), false), |
275 base::Bind(&PowerManagerClientImpl::SignalConnected, | 279 base::Bind(&PowerManagerClientImpl::SignalConnected, |
276 weak_ptr_factory_.GetWeakPtr())); | 280 weak_ptr_factory_.GetWeakPtr())); |
277 | 281 |
278 power_manager_proxy_->ConnectToSignal( | 282 power_manager_proxy_->ConnectToSignal( |
279 power_manager::kPowerManagerInterface, | 283 power_manager::kPowerManagerInterface, |
280 power_manager::kSuspendDoneSignal, | 284 power_manager::kSuspendDoneSignal, |
281 base::Bind(&PowerManagerClientImpl::SuspendDoneReceived, | 285 base::Bind(&PowerManagerClientImpl::SuspendDoneReceived, |
282 weak_ptr_factory_.GetWeakPtr()), | 286 weak_ptr_factory_.GetWeakPtr()), |
283 base::Bind(&PowerManagerClientImpl::SignalConnected, | 287 base::Bind(&PowerManagerClientImpl::SignalConnected, |
284 weak_ptr_factory_.GetWeakPtr())); | 288 weak_ptr_factory_.GetWeakPtr())); |
285 | 289 |
286 power_manager_proxy_->ConnectToSignal( | 290 power_manager_proxy_->ConnectToSignal( |
287 power_manager::kPowerManagerInterface, | 291 power_manager::kPowerManagerInterface, |
292 power_manager::kDarkSuspendImminentSignal, | |
293 base::Bind( | |
294 &PowerManagerClientImpl::HandleSuspendImminent, | |
295 weak_ptr_factory_.GetWeakPtr(), true), | |
296 base::Bind(&PowerManagerClientImpl::SignalConnected, | |
297 weak_ptr_factory_.GetWeakPtr())); | |
298 | |
299 power_manager_proxy_->ConnectToSignal( | |
300 power_manager::kPowerManagerInterface, | |
288 power_manager::kIdleActionImminentSignal, | 301 power_manager::kIdleActionImminentSignal, |
289 base::Bind( | 302 base::Bind( |
290 &PowerManagerClientImpl::IdleActionImminentReceived, | 303 &PowerManagerClientImpl::IdleActionImminentReceived, |
291 weak_ptr_factory_.GetWeakPtr()), | 304 weak_ptr_factory_.GetWeakPtr()), |
292 base::Bind(&PowerManagerClientImpl::SignalConnected, | 305 base::Bind(&PowerManagerClientImpl::SignalConnected, |
293 weak_ptr_factory_.GetWeakPtr())); | 306 weak_ptr_factory_.GetWeakPtr())); |
294 | 307 |
295 power_manager_proxy_->ConnectToSignal( | 308 power_manager_proxy_->ConnectToSignal( |
296 power_manager::kPowerManagerInterface, | 309 power_manager::kPowerManagerInterface, |
297 power_manager::kIdleActionDeferredSignal, | 310 power_manager::kIdleActionDeferredSignal, |
298 base::Bind( | 311 base::Bind( |
299 &PowerManagerClientImpl::IdleActionDeferredReceived, | 312 &PowerManagerClientImpl::IdleActionDeferredReceived, |
300 weak_ptr_factory_.GetWeakPtr()), | 313 weak_ptr_factory_.GetWeakPtr()), |
301 base::Bind(&PowerManagerClientImpl::SignalConnected, | 314 base::Bind(&PowerManagerClientImpl::SignalConnected, |
302 weak_ptr_factory_.GetWeakPtr())); | 315 weak_ptr_factory_.GetWeakPtr())); |
303 | 316 |
304 RegisterSuspendDelay(); | 317 RegisterSuspendDelays(); |
305 } | 318 } |
306 | 319 |
307 private: | 320 private: |
308 // Returns true if the current thread is the origin thread. | 321 // Returns true if the current thread is the origin thread. |
309 bool OnOriginThread() { | 322 bool OnOriginThread() { |
310 return base::PlatformThread::CurrentId() == origin_thread_id_; | 323 return base::PlatformThread::CurrentId() == origin_thread_id_; |
311 } | 324 } |
312 | 325 |
313 // Called when a dbus signal is initially connected. | 326 // Called when a dbus signal is initially connected. |
314 void SignalConnected(const std::string& interface_name, | 327 void SignalConnected(const std::string& interface_name, |
(...skipping 14 matching lines...) Expand all Loading... | |
329 } | 342 } |
330 | 343 |
331 void NameOwnerChangedReceived(const std::string& old_owner, | 344 void NameOwnerChangedReceived(const std::string& old_owner, |
332 const std::string& new_owner) { | 345 const std::string& new_owner) { |
333 VLOG(1) << "Power manager restarted (old owner was " | 346 VLOG(1) << "Power manager restarted (old owner was " |
334 << (old_owner.empty() ? "[none]" : old_owner.c_str()) | 347 << (old_owner.empty() ? "[none]" : old_owner.c_str()) |
335 << ", new owner is " | 348 << ", new owner is " |
336 << (new_owner.empty() ? "[none]" : new_owner.c_str()) << ")"; | 349 << (new_owner.empty() ? "[none]" : new_owner.c_str()) << ")"; |
337 if (!new_owner.empty()) { | 350 if (!new_owner.empty()) { |
338 VLOG(1) << "Sending initial state to power manager"; | 351 VLOG(1) << "Sending initial state to power manager"; |
339 RegisterSuspendDelay(); | 352 RegisterSuspendDelays(); |
340 SetIsProjecting(last_is_projecting_); | 353 SetIsProjecting(last_is_projecting_); |
341 FOR_EACH_OBSERVER(Observer, observers_, PowerManagerRestarted()); | 354 FOR_EACH_OBSERVER(Observer, observers_, PowerManagerRestarted()); |
342 } | 355 } |
343 } | 356 } |
344 | 357 |
345 void BrightnessChangedReceived(dbus::Signal* signal) { | 358 void BrightnessChangedReceived(dbus::Signal* signal) { |
346 dbus::MessageReader reader(signal); | 359 dbus::MessageReader reader(signal); |
347 int32 brightness_level = 0; | 360 int32_t brightness_level = 0; |
348 bool user_initiated = 0; | 361 bool user_initiated = 0; |
349 if (!(reader.PopInt32(&brightness_level) && | 362 if (!(reader.PopInt32(&brightness_level) && |
350 reader.PopBool(&user_initiated))) { | 363 reader.PopBool(&user_initiated))) { |
351 LOG(ERROR) << "Brightness changed signal had incorrect parameters: " | 364 LOG(ERROR) << "Brightness changed signal had incorrect parameters: " |
352 << signal->ToString(); | 365 << signal->ToString(); |
353 return; | 366 return; |
354 } | 367 } |
355 VLOG(1) << "Brightness changed to " << brightness_level | 368 VLOG(1) << "Brightness changed to " << brightness_level |
356 << ": user initiated " << user_initiated; | 369 << ": user initiated " << user_initiated; |
357 FOR_EACH_OBSERVER(Observer, observers_, | 370 FOR_EACH_OBSERVER(Observer, observers_, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 return; | 430 return; |
418 } | 431 } |
419 dbus::MessageReader reader(response); | 432 dbus::MessageReader reader(response); |
420 double percent = 0.0; | 433 double percent = 0.0; |
421 if (!reader.PopDouble(&percent)) | 434 if (!reader.PopDouble(&percent)) |
422 LOG(ERROR) << "Error reading response from powerd: " | 435 LOG(ERROR) << "Error reading response from powerd: " |
423 << response->ToString(); | 436 << response->ToString(); |
424 callback.Run(percent); | 437 callback.Run(percent); |
425 } | 438 } |
426 | 439 |
427 void OnRegisterSuspendDelayReply(dbus::Response* response) { | 440 void HandleRegisterSuspendDelayReply(bool dark_suspend, |
441 dbus::Response* response) { | |
428 if (!response) { | 442 if (!response) { |
429 LOG(ERROR) << "Error calling " | 443 LOG(ERROR) << "Error calling " << response->GetMember(); |
430 << power_manager::kRegisterSuspendDelayMethod; | |
431 return; | 444 return; |
432 } | 445 } |
433 | 446 |
434 dbus::MessageReader reader(response); | 447 dbus::MessageReader reader(response); |
435 power_manager::RegisterSuspendDelayReply protobuf; | 448 power_manager::RegisterSuspendDelayReply protobuf; |
436 if (!reader.PopArrayOfBytesAsProto(&protobuf)) { | 449 if (!reader.PopArrayOfBytesAsProto(&protobuf)) { |
437 LOG(ERROR) << "Unable to parse reply from " | 450 LOG(ERROR) << "Unable to parse reply from " << response->GetMember(); |
438 << power_manager::kRegisterSuspendDelayMethod; | |
439 return; | 451 return; |
440 } | 452 } |
441 | 453 |
442 suspend_delay_id_ = protobuf.delay_id(); | 454 if (dark_suspend) { |
443 has_suspend_delay_id_ = true; | 455 dark_suspend_delay_id_ = protobuf.delay_id(); |
444 VLOG(1) << "Registered suspend delay " << suspend_delay_id_; | 456 has_dark_suspend_delay_id_ = true; |
457 VLOG(1) << "Registered dark suspend delay " << dark_suspend_delay_id_; | |
458 } else { | |
459 suspend_delay_id_ = protobuf.delay_id(); | |
460 has_suspend_delay_id_ = true; | |
461 VLOG(1) << "Registered suspend delay " << suspend_delay_id_; | |
462 } | |
445 } | 463 } |
446 | 464 |
447 void SuspendImminentReceived(dbus::Signal* signal) { | 465 void HandleSuspendImminent(bool in_dark_resume, dbus::Signal* signal) { |
448 if (!has_suspend_delay_id_) { | 466 std::string signal_name = signal->GetMember(); |
449 LOG(ERROR) << "Received unrequested " | 467 if ((in_dark_resume && !has_dark_suspend_delay_id_) || |
450 << power_manager::kSuspendImminentSignal << " signal"; | 468 (!in_dark_resume && !has_suspend_delay_id_)) { |
469 LOG(ERROR) << "Received unrequested " << signal_name << " signal"; | |
451 return; | 470 return; |
452 } | 471 } |
453 | 472 |
454 dbus::MessageReader reader(signal); | 473 dbus::MessageReader reader(signal); |
455 power_manager::SuspendImminent proto; | 474 power_manager::SuspendImminent proto; |
456 if (!reader.PopArrayOfBytesAsProto(&proto)) { | 475 if (!reader.PopArrayOfBytesAsProto(&proto)) { |
457 LOG(ERROR) << "Unable to decode protocol buffer from " | 476 LOG(ERROR) << "Unable to decode protocol buffer from " << signal_name |
458 << power_manager::kSuspendImminentSignal << " signal"; | 477 << " signal"; |
459 return; | 478 return; |
460 } | 479 } |
461 | 480 |
462 VLOG(1) << "Got " << power_manager::kSuspendImminentSignal << " signal " | 481 VLOG(1) << "Got " << signal_name << " signal announcing suspend attempt " |
463 << "announcing suspend attempt " << proto.suspend_id(); | 482 << proto.suspend_id(); |
464 if (suspend_is_pending_) { | 483 |
465 LOG(WARNING) << "Got " << power_manager::kSuspendImminentSignal | 484 // If a previous suspend is pending from the same state we are currently in |
466 << " signal about pending suspend attempt " | 485 // (fully powered on or in dark resume), then something's gone a little |
467 << proto.suspend_id() << " while still waiting " | 486 // wonky. |
468 << "on attempt " << pending_suspend_id_; | 487 if (suspend_is_pending_ && |
488 suspending_from_dark_resume_ == in_dark_resume) { | |
489 LOG(WARNING) << "Got " << signal_name << " signal about pending suspend " | |
490 << "attempt " << proto.suspend_id() << " while still " | |
491 << "waiting on attempt " << pending_suspend_id_; | |
469 } | 492 } |
470 | 493 |
471 pending_suspend_id_ = proto.suspend_id(); | 494 pending_suspend_id_ = proto.suspend_id(); |
472 suspend_is_pending_ = true; | 495 suspend_is_pending_ = true; |
496 suspending_from_dark_resume_ = in_dark_resume; | |
473 num_pending_suspend_readiness_callbacks_ = 0; | 497 num_pending_suspend_readiness_callbacks_ = 0; |
474 FOR_EACH_OBSERVER(Observer, observers_, SuspendImminent()); | 498 if (suspending_from_dark_resume_) |
499 FOR_EACH_OBSERVER(Observer, observers_, DarkSuspendImminent()); | |
500 else | |
501 FOR_EACH_OBSERVER(Observer, observers_, SuspendImminent()); | |
475 MaybeReportSuspendReadiness(); | 502 MaybeReportSuspendReadiness(); |
476 } | 503 } |
477 | 504 |
478 void SuspendDoneReceived(dbus::Signal* signal) { | 505 void SuspendDoneReceived(dbus::Signal* signal) { |
479 dbus::MessageReader reader(signal); | 506 dbus::MessageReader reader(signal); |
480 power_manager::SuspendDone proto; | 507 power_manager::SuspendDone proto; |
481 if (!reader.PopArrayOfBytesAsProto(&proto)) { | 508 if (!reader.PopArrayOfBytesAsProto(&proto)) { |
482 LOG(ERROR) << "Unable to decode protocol buffer from " | 509 LOG(ERROR) << "Unable to decode protocol buffer from " |
483 << power_manager::kSuspendDoneSignal << " signal"; | 510 << power_manager::kSuspendDoneSignal << " signal"; |
484 return; | 511 return; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 case power_manager::InputEvent_Type_LID_CLOSED: { | 576 case power_manager::InputEvent_Type_LID_CLOSED: { |
550 bool open = | 577 bool open = |
551 (proto.type() == power_manager::InputEvent_Type_LID_OPEN); | 578 (proto.type() == power_manager::InputEvent_Type_LID_OPEN); |
552 FOR_EACH_OBSERVER(PowerManagerClient::Observer, observers_, | 579 FOR_EACH_OBSERVER(PowerManagerClient::Observer, observers_, |
553 LidEventReceived(open, timestamp)); | 580 LidEventReceived(open, timestamp)); |
554 break; | 581 break; |
555 } | 582 } |
556 } | 583 } |
557 } | 584 } |
558 | 585 |
559 // Registers a suspend delay with the power manager. This is usually | 586 void RegisterSuspendDelayImpl( |
560 // only called at startup, but if the power manager restarts, we need to | 587 const std::string& method_name, |
561 // create a new delay. | 588 const power_manager::RegisterSuspendDelayRequest& protobuf_request, |
562 void RegisterSuspendDelay() { | 589 dbus::ObjectProxy::ResponseCallback callback) { |
590 dbus::MethodCall method_call( | |
591 power_manager::kPowerManagerInterface, method_name); | |
592 dbus::MessageWriter writer(&method_call); | |
593 | |
594 if (!writer.AppendProtoAsArrayOfBytes(protobuf_request)) { | |
595 LOG(ERROR) << "Error constructing message for " << method_name; | |
596 return; | |
597 } | |
598 | |
599 power_manager_proxy_->CallMethod( | |
600 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, callback); | |
601 } | |
602 | |
603 // Registers suspend delays with the power manager. This is usually only | |
604 // called at startup, but if the power manager restarts, we need to create new | |
605 // delays. | |
606 void RegisterSuspendDelays() { | |
pprabhu
2014/08/26 18:13:18
Fly by late comment: Shouldn't this also reset |su
Daniel Erat
2014/08/26 18:16:33
probably wouldn't hurt to do that here, but i thin
Chirantan Ekbote
2014/08/26 19:10:54
But it looks like |suspend_is_pending_| is not cle
| |
563 // Throw out any old delay that was registered. | 607 // Throw out any old delay that was registered. |
564 suspend_delay_id_ = -1; | 608 suspend_delay_id_ = -1; |
565 has_suspend_delay_id_ = false; | 609 has_suspend_delay_id_ = false; |
566 | 610 dark_suspend_delay_id_ = -1; |
567 dbus::MethodCall method_call( | 611 has_dark_suspend_delay_id_ = false; |
568 power_manager::kPowerManagerInterface, | |
569 power_manager::kRegisterSuspendDelayMethod); | |
570 dbus::MessageWriter writer(&method_call); | |
571 | 612 |
572 power_manager::RegisterSuspendDelayRequest protobuf_request; | 613 power_manager::RegisterSuspendDelayRequest protobuf_request; |
573 base::TimeDelta timeout = | 614 base::TimeDelta timeout = |
574 base::TimeDelta::FromMilliseconds(kSuspendDelayTimeoutMs); | 615 base::TimeDelta::FromMilliseconds(kSuspendDelayTimeoutMs); |
575 protobuf_request.set_timeout(timeout.ToInternalValue()); | 616 protobuf_request.set_timeout(timeout.ToInternalValue()); |
576 protobuf_request.set_description(kSuspendDelayDescription); | 617 protobuf_request.set_description(kSuspendDelayDescription); |
577 | 618 |
578 if (!writer.AppendProtoAsArrayOfBytes(protobuf_request)) { | 619 RegisterSuspendDelayImpl( |
579 LOG(ERROR) << "Error constructing message for " | 620 power_manager::kRegisterSuspendDelayMethod, |
580 << power_manager::kRegisterSuspendDelayMethod; | 621 protobuf_request, |
581 return; | |
582 } | |
583 power_manager_proxy_->CallMethod( | |
584 &method_call, | |
585 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | |
586 base::Bind( | 622 base::Bind( |
587 &PowerManagerClientImpl::OnRegisterSuspendDelayReply, | 623 &PowerManagerClientImpl::HandleRegisterSuspendDelayReply, |
588 weak_ptr_factory_.GetWeakPtr())); | 624 weak_ptr_factory_.GetWeakPtr(), false)); |
625 RegisterSuspendDelayImpl( | |
626 power_manager::kRegisterDarkSuspendDelayMethod, | |
627 protobuf_request, | |
628 base::Bind( | |
629 &PowerManagerClientImpl::HandleRegisterSuspendDelayReply, | |
630 weak_ptr_factory_.GetWeakPtr(), true)); | |
589 } | 631 } |
590 | 632 |
591 // Records the fact that an observer has finished doing asynchronous work | 633 // Records the fact that an observer has finished doing asynchronous work |
592 // that was blocking a pending suspend attempt and possibly reports | 634 // that was blocking a pending suspend attempt and possibly reports |
593 // suspend readiness to powerd. Called by callbacks returned via | 635 // suspend readiness to powerd. Called by callbacks returned via |
594 // GetSuspendReadinessCallback(). | 636 // GetSuspendReadinessCallback(). |
595 void HandleObserverSuspendReadiness(int32 suspend_id) { | 637 void HandleObserverSuspendReadiness(int32_t suspend_id, bool in_dark_resume) { |
596 DCHECK(OnOriginThread()); | 638 DCHECK(OnOriginThread()); |
597 if (!suspend_is_pending_ || suspend_id != pending_suspend_id_) | 639 if (!suspend_is_pending_ || suspend_id != pending_suspend_id_ || |
640 in_dark_resume != suspending_from_dark_resume_) | |
598 return; | 641 return; |
599 | 642 |
600 num_pending_suspend_readiness_callbacks_--; | 643 num_pending_suspend_readiness_callbacks_--; |
601 MaybeReportSuspendReadiness(); | 644 MaybeReportSuspendReadiness(); |
602 } | 645 } |
603 | 646 |
604 // Reports suspend readiness to powerd if no observers are still holding | 647 // Reports suspend readiness to powerd if no observers are still holding |
605 // suspend readiness callbacks. | 648 // suspend readiness callbacks. |
606 void MaybeReportSuspendReadiness() { | 649 void MaybeReportSuspendReadiness() { |
607 if (!suspend_is_pending_ || num_pending_suspend_readiness_callbacks_ > 0) | 650 if (!suspend_is_pending_ || num_pending_suspend_readiness_callbacks_ > 0) |
608 return; | 651 return; |
609 | 652 |
653 std::string method_name; | |
654 int32_t delay_id = -1; | |
655 if (suspending_from_dark_resume_) { | |
656 method_name = power_manager::kHandleDarkSuspendReadinessMethod; | |
657 delay_id = dark_suspend_delay_id_; | |
658 } else { | |
659 method_name = power_manager::kHandleSuspendReadinessMethod; | |
660 delay_id = suspend_delay_id_; | |
661 } | |
662 | |
610 dbus::MethodCall method_call( | 663 dbus::MethodCall method_call( |
611 power_manager::kPowerManagerInterface, | 664 power_manager::kPowerManagerInterface, method_name); |
612 power_manager::kHandleSuspendReadinessMethod); | |
613 dbus::MessageWriter writer(&method_call); | 665 dbus::MessageWriter writer(&method_call); |
614 | 666 |
615 VLOG(1) << "Announcing readiness of suspend delay " << suspend_delay_id_ | 667 VLOG(1) << "Announcing readiness of suspend delay " << delay_id |
616 << " for suspend attempt " << pending_suspend_id_; | 668 << " for suspend attempt " << pending_suspend_id_; |
617 power_manager::SuspendReadinessInfo protobuf_request; | 669 power_manager::SuspendReadinessInfo protobuf_request; |
618 protobuf_request.set_delay_id(suspend_delay_id_); | 670 protobuf_request.set_delay_id(delay_id); |
619 protobuf_request.set_suspend_id(pending_suspend_id_); | 671 protobuf_request.set_suspend_id(pending_suspend_id_); |
620 | 672 |
621 pending_suspend_id_ = -1; | 673 pending_suspend_id_ = -1; |
622 suspend_is_pending_ = false; | 674 suspend_is_pending_ = false; |
623 | 675 |
624 if (!writer.AppendProtoAsArrayOfBytes(protobuf_request)) { | 676 if (!writer.AppendProtoAsArrayOfBytes(protobuf_request)) { |
625 LOG(ERROR) << "Error constructing message for " | 677 LOG(ERROR) << "Error constructing message for " << method_name; |
626 << power_manager::kHandleSuspendReadinessMethod; | |
627 return; | 678 return; |
628 } | 679 } |
629 power_manager_proxy_->CallMethod( | 680 power_manager_proxy_->CallMethod( |
630 &method_call, | 681 &method_call, |
631 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, | 682 dbus::ObjectProxy::TIMEOUT_USE_DEFAULT, |
632 dbus::ObjectProxy::EmptyResponseCallback()); | 683 dbus::ObjectProxy::EmptyResponseCallback()); |
633 } | 684 } |
634 | 685 |
635 // Origin thread (i.e. the UI thread in production). | 686 // Origin thread (i.e. the UI thread in production). |
636 base::PlatformThreadId origin_thread_id_; | 687 base::PlatformThreadId origin_thread_id_; |
637 | 688 |
638 dbus::ObjectProxy* power_manager_proxy_; | 689 dbus::ObjectProxy* power_manager_proxy_; |
639 ObserverList<Observer> observers_; | 690 ObserverList<Observer> observers_; |
640 | 691 |
641 // The delay_id_ obtained from the RegisterSuspendDelay request. | 692 // The delay_id_ obtained from the RegisterSuspendDelay request. |
642 int32 suspend_delay_id_; | 693 int32_t suspend_delay_id_; |
643 bool has_suspend_delay_id_; | 694 bool has_suspend_delay_id_; |
644 | 695 |
696 // The delay_id_ obtained from the RegisterDarkSuspendDelay request. | |
697 int32_t dark_suspend_delay_id_; | |
698 bool has_dark_suspend_delay_id_; | |
699 | |
645 // powerd-supplied ID corresponding to an imminent suspend attempt that is | 700 // powerd-supplied ID corresponding to an imminent suspend attempt that is |
646 // currently being delayed. | 701 // currently being delayed. |
647 int32 pending_suspend_id_; | 702 int32_t pending_suspend_id_; |
648 bool suspend_is_pending_; | 703 bool suspend_is_pending_; |
649 | 704 |
705 // Set to true when the suspend currently being delayed was triggered during a | |
706 // dark resume. Since |pending_suspend_id_| and |suspend_is_pending_| are | |
707 // both shared by normal and dark suspends, |suspending_from_dark_resume_| | |
708 // helps distinguish the context within which these variables are being used. | |
709 bool suspending_from_dark_resume_; | |
710 | |
650 // Number of callbacks that have been returned by | 711 // Number of callbacks that have been returned by |
651 // GetSuspendReadinessCallback() during the currently-pending suspend | 712 // GetSuspendReadinessCallback() during the currently-pending suspend |
652 // attempt but have not yet been called. | 713 // attempt but have not yet been called. |
653 int num_pending_suspend_readiness_callbacks_; | 714 int num_pending_suspend_readiness_callbacks_; |
654 | 715 |
655 // Last state passed to SetIsProjecting(). | 716 // Last state passed to SetIsProjecting(). |
656 bool last_is_projecting_; | 717 bool last_is_projecting_; |
657 | 718 |
658 // Note: This should remain the last member so it'll be destroyed and | 719 // Note: This should remain the last member so it'll be destroyed and |
659 // invalidate its weak pointers before any other members are destroyed. | 720 // invalidate its weak pointers before any other members are destroyed. |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
889 // static | 950 // static |
890 PowerManagerClient* PowerManagerClient::Create( | 951 PowerManagerClient* PowerManagerClient::Create( |
891 DBusClientImplementationType type) { | 952 DBusClientImplementationType type) { |
892 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 953 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
893 return new PowerManagerClientImpl(); | 954 return new PowerManagerClientImpl(); |
894 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 955 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
895 return new PowerManagerClientStubImpl(); | 956 return new PowerManagerClientStubImpl(); |
896 } | 957 } |
897 | 958 |
898 } // namespace chromeos | 959 } // namespace chromeos |
OLD | NEW |