| 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_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_POWER_POWER_API_H_ |
| 6 #define EXTENSIONS_BROWSER_API_POWER_POWER_API_H_ | 6 #define EXTENSIONS_BROWSER_API_POWER_POWER_API_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "device/power_save_blocker/power_save_blocker.h" | 14 #include "content/public/browser/power_save_blocker.h" |
| 15 #include "extensions/browser/browser_context_keyed_api_factory.h" | 15 #include "extensions/browser/browser_context_keyed_api_factory.h" |
| 16 #include "extensions/browser/extension_function.h" | 16 #include "extensions/browser/extension_function.h" |
| 17 #include "extensions/browser/extension_registry_observer.h" | 17 #include "extensions/browser/extension_registry_observer.h" |
| 18 #include "extensions/common/api/power.h" | 18 #include "extensions/common/api/power.h" |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 class BrowserContext; | 21 class BrowserContext; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace extensions { | 24 namespace extensions { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 46 // ExtensionFunction: | 46 // ExtensionFunction: |
| 47 bool RunSync() override; | 47 bool RunSync() override; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 // Handles calls made via the chrome.power API. There is a separate instance of | 50 // Handles calls made via the chrome.power API. There is a separate instance of |
| 51 // this class for each profile, as requests are tracked by extension ID, but a | 51 // this class for each profile, as requests are tracked by extension ID, but a |
| 52 // regular and incognito profile will share the same instance. | 52 // regular and incognito profile will share the same instance. |
| 53 class PowerAPI : public BrowserContextKeyedAPI, | 53 class PowerAPI : public BrowserContextKeyedAPI, |
| 54 public extensions::ExtensionRegistryObserver { | 54 public extensions::ExtensionRegistryObserver { |
| 55 public: | 55 public: |
| 56 typedef base::Callback<std::unique_ptr<device::PowerSaveBlocker>( | 56 typedef base::Callback<std::unique_ptr<content::PowerSaveBlocker>( |
| 57 device::PowerSaveBlocker::PowerSaveBlockerType, | 57 content::PowerSaveBlocker::PowerSaveBlockerType, |
| 58 device::PowerSaveBlocker::Reason, | 58 content::PowerSaveBlocker::Reason, |
| 59 const std::string&, | 59 const std::string&)> |
| 60 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, | |
| 61 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner)> | |
| 62 CreateBlockerFunction; | 60 CreateBlockerFunction; |
| 63 | 61 |
| 64 static PowerAPI* Get(content::BrowserContext* context); | 62 static PowerAPI* Get(content::BrowserContext* context); |
| 65 | 63 |
| 66 // BrowserContextKeyedAPI implementation. | 64 // BrowserContextKeyedAPI implementation. |
| 67 static BrowserContextKeyedAPIFactory<PowerAPI>* GetFactoryInstance(); | 65 static BrowserContextKeyedAPIFactory<PowerAPI>* GetFactoryInstance(); |
| 68 | 66 |
| 69 // Adds an extension lock at |level| for |extension_id|, replacing the | 67 // Adds an extension lock at |level| for |extension_id|, replacing the |
| 70 // extension's existing lock, if any. | 68 // extension's existing lock, if any. |
| 71 void AddRequest(const std::string& extension_id, api::power::Level level); | 69 void AddRequest(const std::string& extension_id, api::power::Level level); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 99 static const bool kServiceIsCreatedWithBrowserContext = false; | 97 static const bool kServiceIsCreatedWithBrowserContext = false; |
| 100 void Shutdown() override; | 98 void Shutdown() override; |
| 101 | 99 |
| 102 content::BrowserContext* browser_context_; | 100 content::BrowserContext* browser_context_; |
| 103 | 101 |
| 104 // Function that should be called to create PowerSaveBlocker objects. | 102 // Function that should be called to create PowerSaveBlocker objects. |
| 105 // Tests can change this to record what would've been done instead of | 103 // Tests can change this to record what would've been done instead of |
| 106 // actually changing the system power-saving settings. | 104 // actually changing the system power-saving settings. |
| 107 CreateBlockerFunction create_blocker_function_; | 105 CreateBlockerFunction create_blocker_function_; |
| 108 | 106 |
| 109 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker_; | 107 std::unique_ptr<content::PowerSaveBlocker> power_save_blocker_; |
| 110 | 108 |
| 111 // Current level used by |power_save_blocker_|. Meaningless if | 109 // Current level used by |power_save_blocker_|. Meaningless if |
| 112 // |power_save_blocker_| is NULL. | 110 // |power_save_blocker_| is NULL. |
| 113 api::power::Level current_level_; | 111 api::power::Level current_level_; |
| 114 | 112 |
| 115 // Map from extension ID to the corresponding level for each extension | 113 // Map from extension ID to the corresponding level for each extension |
| 116 // that has an outstanding request. | 114 // that has an outstanding request. |
| 117 typedef std::map<std::string, api::power::Level> ExtensionLevelMap; | 115 typedef std::map<std::string, api::power::Level> ExtensionLevelMap; |
| 118 ExtensionLevelMap extension_levels_; | 116 ExtensionLevelMap extension_levels_; |
| 119 | 117 |
| 120 DISALLOW_COPY_AND_ASSIGN(PowerAPI); | 118 DISALLOW_COPY_AND_ASSIGN(PowerAPI); |
| 121 }; | 119 }; |
| 122 | 120 |
| 123 } // namespace extensions | 121 } // namespace extensions |
| 124 | 122 |
| 125 #endif // EXTENSIONS_BROWSER_API_POWER_POWER_API_H_ | 123 #endif // EXTENSIONS_BROWSER_API_POWER_POWER_API_H_ |
| OLD | NEW |