OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/extensions/api/power/power_api_manager.h" | 5 #include "chrome/browser/extensions/api/power/power_api_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "content/public/browser/notification_service.h" | 9 #include "content/public/browser/notification_service.h" |
10 #include "extensions/common/extension.h" | 10 #include "extensions/common/extension.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 void PowerApiManager::SetCreateBlockerFunctionForTesting( | 49 void PowerApiManager::SetCreateBlockerFunctionForTesting( |
50 CreateBlockerFunction function) { | 50 CreateBlockerFunction function) { |
51 create_blocker_function_ = !function.is_null() ? function : | 51 create_blocker_function_ = !function.is_null() ? function : |
52 base::Bind(&content::PowerSaveBlocker::Create); | 52 base::Bind(&content::PowerSaveBlocker::Create); |
53 } | 53 } |
54 | 54 |
55 void PowerApiManager::Observe(int type, | 55 void PowerApiManager::Observe(int type, |
56 const content::NotificationSource& source, | 56 const content::NotificationSource& source, |
57 const content::NotificationDetails& details) { | 57 const content::NotificationDetails& details) { |
58 switch (type) { | 58 switch (type) { |
59 case chrome::NOTIFICATION_EXTENSION_UNLOADED: | 59 case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: |
60 RemoveRequest(content::Details<extensions::UnloadedExtensionInfo>( | 60 RemoveRequest(content::Details<extensions::UnloadedExtensionInfo>( |
61 details)->extension->id()); | 61 details)->extension->id()); |
62 UpdatePowerSaveBlocker(); | 62 UpdatePowerSaveBlocker(); |
63 break; | 63 break; |
64 case chrome::NOTIFICATION_APP_TERMINATING: | 64 case chrome::NOTIFICATION_APP_TERMINATING: |
65 power_save_blocker_.reset(); | 65 power_save_blocker_.reset(); |
66 break; | 66 break; |
67 default: | 67 default: |
68 NOTREACHED() << "Unexpected notification " << type; | 68 NOTREACHED() << "Unexpected notification " << type; |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 PowerApiManager::PowerApiManager() | 72 PowerApiManager::PowerApiManager() |
73 : create_blocker_function_(base::Bind(&content::PowerSaveBlocker::Create)), | 73 : create_blocker_function_(base::Bind(&content::PowerSaveBlocker::Create)), |
74 current_level_(api::power::LEVEL_SYSTEM) { | 74 current_level_(api::power::LEVEL_SYSTEM) { |
75 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 75 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
76 content::NotificationService::AllSources()); | 76 content::NotificationService::AllSources()); |
77 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, | 77 registrar_.Add(this, chrome::NOTIFICATION_APP_TERMINATING, |
78 content::NotificationService::AllSources()); | 78 content::NotificationService::AllSources()); |
79 } | 79 } |
80 | 80 |
81 PowerApiManager::~PowerApiManager() {} | 81 PowerApiManager::~PowerApiManager() {} |
82 | 82 |
83 void PowerApiManager::UpdatePowerSaveBlocker() { | 83 void PowerApiManager::UpdatePowerSaveBlocker() { |
84 if (extension_levels_.empty()) { | 84 if (extension_levels_.empty()) { |
85 power_save_blocker_.reset(); | 85 power_save_blocker_.reset(); |
(...skipping 14 matching lines...) Expand all Loading... |
100 content::PowerSaveBlocker::PowerSaveBlockerType type = | 100 content::PowerSaveBlocker::PowerSaveBlockerType type = |
101 LevelToPowerSaveBlockerType(new_level); | 101 LevelToPowerSaveBlockerType(new_level); |
102 scoped_ptr<content::PowerSaveBlocker> new_blocker( | 102 scoped_ptr<content::PowerSaveBlocker> new_blocker( |
103 create_blocker_function_.Run(type, kPowerSaveBlockerReason)); | 103 create_blocker_function_.Run(type, kPowerSaveBlockerReason)); |
104 power_save_blocker_.swap(new_blocker); | 104 power_save_blocker_.swap(new_blocker); |
105 current_level_ = new_level; | 105 current_level_ = new_level; |
106 } | 106 } |
107 } | 107 } |
108 | 108 |
109 } // namespace extensions | 109 } // namespace extensions |
OLD | NEW |