| 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 "content/browser/power_save_blocker_impl.h" | 5 #include "content/browser/power_save_blocker_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 class PowerSaveBlockerImpl::Delegate | 38 class PowerSaveBlockerImpl::Delegate |
| 39 : public base::RefCountedThreadSafe<PowerSaveBlockerImpl::Delegate> { | 39 : public base::RefCountedThreadSafe<PowerSaveBlockerImpl::Delegate> { |
| 40 public: | 40 public: |
| 41 Delegate(PowerSaveBlockerType type, | 41 Delegate(PowerSaveBlockerType type, |
| 42 Reason reason, | 42 Reason reason, |
| 43 const std::string& description) | 43 const std::string& description) |
| 44 : type_(type), reason_(reason), description_(description), block_id_(0) {} | 44 : type_(type), reason_(reason), description_(description), block_id_(0) {} |
| 45 | 45 |
| 46 void ApplyBlock() { | 46 void ApplyBlock() { |
| 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 47 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 48 if (!chromeos::PowerPolicyController::IsInitialized()) | 48 if (!chromeos::PowerPolicyController::IsInitialized()) |
| 49 return; | 49 return; |
| 50 | 50 |
| 51 auto* controller = chromeos::PowerPolicyController::Get(); | 51 auto* controller = chromeos::PowerPolicyController::Get(); |
| 52 switch (type_) { | 52 switch (type_) { |
| 53 case kPowerSaveBlockPreventAppSuspension: | 53 case kPowerSaveBlockPreventAppSuspension: |
| 54 block_id_ = controller->AddSystemWakeLock(GetWakeLockReason(reason_), | 54 block_id_ = controller->AddSystemWakeLock(GetWakeLockReason(reason_), |
| 55 description_); | 55 description_); |
| 56 break; | 56 break; |
| 57 case kPowerSaveBlockPreventDisplaySleep: | 57 case kPowerSaveBlockPreventDisplaySleep: |
| 58 block_id_ = controller->AddScreenWakeLock(GetWakeLockReason(reason_), | 58 block_id_ = controller->AddScreenWakeLock(GetWakeLockReason(reason_), |
| 59 description_); | 59 description_); |
| 60 break; | 60 break; |
| 61 default: | 61 default: |
| 62 NOTREACHED() << "Unhandled block type " << type_; | 62 NOTREACHED() << "Unhandled block type " << type_; |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 void RemoveBlock() { | 66 void RemoveBlock() { |
| 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 67 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 68 if (!chromeos::PowerPolicyController::IsInitialized()) | 68 if (!chromeos::PowerPolicyController::IsInitialized()) |
| 69 return; | 69 return; |
| 70 | 70 |
| 71 chromeos::PowerPolicyController::Get()->RemoveWakeLock(block_id_); | 71 chromeos::PowerPolicyController::Get()->RemoveWakeLock(block_id_); |
| 72 } | 72 } |
| 73 | 73 |
| 74 private: | 74 private: |
| 75 friend class base::RefCountedThreadSafe<Delegate>; | 75 friend class base::RefCountedThreadSafe<Delegate>; |
| 76 virtual ~Delegate() {} | 76 virtual ~Delegate() {} |
| 77 | 77 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 92 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 92 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 93 base::Bind(&Delegate::ApplyBlock, delegate_)); | 93 base::Bind(&Delegate::ApplyBlock, delegate_)); |
| 94 } | 94 } |
| 95 | 95 |
| 96 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { | 96 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { |
| 97 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 97 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 98 base::Bind(&Delegate::RemoveBlock, delegate_)); | 98 base::Bind(&Delegate::RemoveBlock, delegate_)); |
| 99 } | 99 } |
| 100 | 100 |
| 101 } // namespace content | 101 } // namespace content |
| OLD | NEW |