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