Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(360)

Side by Side Diff: chrome/browser/chromeos/extensions/power/power_api_manager.cc

Issue 12576018: Add chrome.power extension API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update PermissionsTest.PermissionMessages Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/extensions/power/power_api_manager.h"
6
7 #include "chrome/common/chrome_notification_types.h"
8 #include "chrome/common/extensions/extension.h"
9 #include "chromeos/power/power_state_override.h"
10 #include "content/public/browser/notification_service.h"
11
12 namespace extensions {
13 namespace power {
14
15 // static
16 PowerApiManager* PowerApiManager::GetInstance() {
17 return Singleton<PowerApiManager>::get();
18 }
19
20 void PowerApiManager::AddExtensionLock(const std::string& extension_id) {
21 extension_ids_set_.insert(extension_id);
22 UpdatePowerSettings();
23 }
24
25 void PowerApiManager::RemoveExtensionLock(const std::string& extension_id) {
26 extension_ids_set_.erase(extension_id);
27 UpdatePowerSettings();
28 }
29
30 void PowerApiManager::Observe(int type,
31 const content::NotificationSource& source,
32 const content::NotificationDetails& details) {
33 if (type == chrome::NOTIFICATION_EXTENSION_UNLOADED) {
34 RemoveExtensionLock(
35 content::Details<extensions::UnloadedExtensionInfo>(details)->
36 extension->id());
37 UpdatePowerSettings();
38 } else if (type == chrome::NOTIFICATION_APP_TERMINATING) {
39 // If the Chrome app is terminating, ensure we release our power overrides.
40 power_state_override_ = NULL;
41 } else {
42 NOTREACHED() << "Unexpected notification " << type;
43 }
44 }
45
46 PowerApiManager::PowerApiManager()
47 : power_state_override_(NULL) {
48 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
49 content::NotificationService::AllSources());
50 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING,
51 content::NotificationService::AllSources());
52 UpdatePowerSettings();
53 }
54
55 PowerApiManager::~PowerApiManager() {}
56
57 void PowerApiManager::UpdatePowerSettings() {
58 // If we have a wake lock and don't have the power state overriden.
59 if (extension_ids_set_.size() && !power_state_override_.get()) {
60 power_state_override_ = new chromeos::PowerStateOverride(
61 chromeos::PowerStateOverride::BLOCK_DISPLAY_SLEEP);
62 // else, if we don't have any wake locks and do have a power override.
63 } else if (extension_ids_set_.empty() && power_state_override_.get()) {
64 power_state_override_ = NULL;
65 }
66 }
67
68 } // namespace power
69 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698