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 #ifndef EXTENSIONS_BROWSER_API_POWER_POWER_API_MANAGER_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_POWER_POWER_API_MANAGER_H_ |
6 #define EXTENSIONS_BROWSER_API_POWER_POWER_API_MANAGER_H_ | 6 #define EXTENSIONS_BROWSER_API_POWER_POWER_API_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 // Removes an extension lock for an extension. Calling this for an | 45 // Removes an extension lock for an extension. Calling this for an |
46 // extension id without a lock will do nothing. | 46 // extension id without a lock will do nothing. |
47 void RemoveRequest(const std::string& extension_id); | 47 void RemoveRequest(const std::string& extension_id); |
48 | 48 |
49 // Replaces the function that will be called to create PowerSaveBlocker | 49 // Replaces the function that will be called to create PowerSaveBlocker |
50 // objects. Passing an empty callback will revert to the default. | 50 // objects. Passing an empty callback will revert to the default. |
51 void SetCreateBlockerFunctionForTesting(CreateBlockerFunction function); | 51 void SetCreateBlockerFunctionForTesting(CreateBlockerFunction function); |
52 | 52 |
53 // Overridden from extensions::ExtensionRegistryObserver. | 53 // Overridden from extensions::ExtensionRegistryObserver. |
54 virtual void OnExtensionUnloaded(content::BrowserContext* browser_context, | 54 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
55 const Extension* extension, | 55 const Extension* extension, |
56 UnloadedExtensionInfo::Reason reason) | 56 UnloadedExtensionInfo::Reason reason) override; |
57 override; | |
58 | 57 |
59 private: | 58 private: |
60 friend class BrowserContextKeyedAPIFactory<PowerApiManager>; | 59 friend class BrowserContextKeyedAPIFactory<PowerApiManager>; |
61 | 60 |
62 explicit PowerApiManager(content::BrowserContext* context); | 61 explicit PowerApiManager(content::BrowserContext* context); |
63 virtual ~PowerApiManager(); | 62 ~PowerApiManager() override; |
64 | 63 |
65 // Updates |power_save_blocker_| and |current_level_| after iterating | 64 // Updates |power_save_blocker_| and |current_level_| after iterating |
66 // over |extension_levels_|. | 65 // over |extension_levels_|. |
67 void UpdatePowerSaveBlocker(); | 66 void UpdatePowerSaveBlocker(); |
68 | 67 |
69 // BrowserContextKeyedAPI implementation. | 68 // BrowserContextKeyedAPI implementation. |
70 static const char* service_name() { return "PowerApiManager"; } | 69 static const char* service_name() { return "PowerApiManager"; } |
71 static const bool kServiceRedirectedInIncognito = true; | 70 static const bool kServiceRedirectedInIncognito = true; |
72 static const bool kServiceIsCreatedWithBrowserContext = false; | 71 static const bool kServiceIsCreatedWithBrowserContext = false; |
73 virtual void Shutdown() override; | 72 void Shutdown() override; |
74 | 73 |
75 content::BrowserContext* browser_context_; | 74 content::BrowserContext* browser_context_; |
76 | 75 |
77 // Function that should be called to create PowerSaveBlocker objects. | 76 // Function that should be called to create PowerSaveBlocker objects. |
78 // Tests can change this to record what would've been done instead of | 77 // Tests can change this to record what would've been done instead of |
79 // actually changing the system power-saving settings. | 78 // actually changing the system power-saving settings. |
80 CreateBlockerFunction create_blocker_function_; | 79 CreateBlockerFunction create_blocker_function_; |
81 | 80 |
82 scoped_ptr<content::PowerSaveBlocker> power_save_blocker_; | 81 scoped_ptr<content::PowerSaveBlocker> power_save_blocker_; |
83 | 82 |
84 // Current level used by |power_save_blocker_|. Meaningless if | 83 // Current level used by |power_save_blocker_|. Meaningless if |
85 // |power_save_blocker_| is NULL. | 84 // |power_save_blocker_| is NULL. |
86 core_api::power::Level current_level_; | 85 core_api::power::Level current_level_; |
87 | 86 |
88 // Map from extension ID to the corresponding level for each extension | 87 // Map from extension ID to the corresponding level for each extension |
89 // that has an outstanding request. | 88 // that has an outstanding request. |
90 typedef std::map<std::string, core_api::power::Level> ExtensionLevelMap; | 89 typedef std::map<std::string, core_api::power::Level> ExtensionLevelMap; |
91 ExtensionLevelMap extension_levels_; | 90 ExtensionLevelMap extension_levels_; |
92 | 91 |
93 DISALLOW_COPY_AND_ASSIGN(PowerApiManager); | 92 DISALLOW_COPY_AND_ASSIGN(PowerApiManager); |
94 }; | 93 }; |
95 | 94 |
96 } // namespace extensions | 95 } // namespace extensions |
97 | 96 |
98 #endif // EXTENSIONS_BROWSER_API_POWER_POWER_API_MANAGER_H_ | 97 #endif // EXTENSIONS_BROWSER_API_POWER_POWER_API_MANAGER_H_ |
OLD | NEW |