OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/power/power_api.h" | 5 #include "extensions/browser/api/power/power_api.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "content/public/browser/browser_thread.h" | 9 #include "content/public/browser/browser_thread.h" |
10 #include "device/power_save_blocker/power_save_blocker.h" | 10 #include "device/power_save_blocker/power_save_blocker.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 // If the level changed and we need to create a new blocker, do a swap | 120 // If the level changed and we need to create a new blocker, do a swap |
121 // to ensure that there isn't a brief period where power management is | 121 // to ensure that there isn't a brief period where power management is |
122 // unblocked. | 122 // unblocked. |
123 if (!power_save_blocker_ || new_level != current_level_) { | 123 if (!power_save_blocker_ || new_level != current_level_) { |
124 device::PowerSaveBlocker::PowerSaveBlockerType type = | 124 device::PowerSaveBlocker::PowerSaveBlockerType type = |
125 LevelToPowerSaveBlockerType(new_level); | 125 LevelToPowerSaveBlockerType(new_level); |
126 std::unique_ptr<device::PowerSaveBlocker> new_blocker( | 126 std::unique_ptr<device::PowerSaveBlocker> new_blocker( |
127 create_blocker_function_.Run( | 127 create_blocker_function_.Run( |
128 type, device::PowerSaveBlocker::kReasonOther, | 128 type, device::PowerSaveBlocker::kReasonOther, |
129 kPowerSaveBlockerDescription, | 129 kPowerSaveBlockerDescription, |
130 content::BrowserThread::GetMessageLoopProxyForThread( | 130 content::BrowserThread::GetTaskRunnerForThread( |
131 content::BrowserThread::UI), | 131 content::BrowserThread::UI), |
132 content::BrowserThread::GetMessageLoopProxyForThread( | 132 content::BrowserThread::GetTaskRunnerForThread( |
133 content::BrowserThread::FILE))); | 133 content::BrowserThread::FILE))); |
134 power_save_blocker_.swap(new_blocker); | 134 power_save_blocker_.swap(new_blocker); |
135 current_level_ = new_level; | 135 current_level_ = new_level; |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 void PowerAPI::Shutdown() { | 139 void PowerAPI::Shutdown() { |
140 // Unregister here rather than in the d'tor; otherwise this call will recreate | 140 // Unregister here rather than in the d'tor; otherwise this call will recreate |
141 // the already-deleted ExtensionRegistry. | 141 // the already-deleted ExtensionRegistry. |
142 ExtensionRegistry::Get(browser_context_)->RemoveObserver(this); | 142 ExtensionRegistry::Get(browser_context_)->RemoveObserver(this); |
143 power_save_blocker_.reset(); | 143 power_save_blocker_.reset(); |
144 } | 144 } |
145 | 145 |
146 } // namespace extensions | 146 } // namespace extensions |
OLD | NEW |