OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_POWER_POWER_API_MANAGER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_POWER_POWER_API_MANAGER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 |
| 11 #include "base/callback.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/singleton.h" |
| 14 #include "chrome/common/extensions/api/power.h" |
| 15 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" |
| 17 #include "content/public/browser/power_save_blocker.h" |
| 18 |
| 19 namespace extensions { |
| 20 |
| 21 class PowerApiManager : public content::NotificationObserver { |
| 22 public: |
| 23 typedef base::Callback<scoped_ptr<content::PowerSaveBlocker>( |
| 24 content::PowerSaveBlocker::PowerSaveBlockerType, |
| 25 const std::string&)> CreateBlockerFunction; |
| 26 |
| 27 static PowerApiManager* GetInstance(); |
| 28 |
| 29 // Adds an extension lock at |level| for |extension_id|, replacing the |
| 30 // extension's existing lock, if any. |
| 31 void AddRequest(const std::string& extension_id, api::power::Level level); |
| 32 |
| 33 // Removes an extension lock for an extension. Calling this for an |
| 34 // extension id without a lock will do nothing. |
| 35 void RemoveRequest(const std::string& extension_id); |
| 36 |
| 37 // Replaces the function that will be called to create PowerSaveBlocker |
| 38 // objects. Passing an empty callback will revert to the default. |
| 39 void SetCreateBlockerFunctionForTesting(CreateBlockerFunction function); |
| 40 |
| 41 // Overridden from content::NotificationObserver. |
| 42 virtual void Observe(int type, |
| 43 const content::NotificationSource& source, |
| 44 const content::NotificationDetails& details) OVERRIDE; |
| 45 |
| 46 private: |
| 47 friend struct DefaultSingletonTraits<PowerApiManager>; |
| 48 |
| 49 PowerApiManager(); |
| 50 virtual ~PowerApiManager(); |
| 51 |
| 52 // Updates |power_save_blocker_| and |current_level_| after iterating |
| 53 // over |extension_levels_|. |
| 54 void UpdatePowerSaveBlocker(); |
| 55 |
| 56 content::NotificationRegistrar registrar_; |
| 57 |
| 58 // Function that should be called to create PowerSaveBlocker objects. |
| 59 // Tests can change this to record what would've been done instead of |
| 60 // actually changing the system power-saving settings. |
| 61 CreateBlockerFunction create_blocker_function_; |
| 62 |
| 63 scoped_ptr<content::PowerSaveBlocker> power_save_blocker_; |
| 64 |
| 65 // Current level used by |power_save_blocker_|. Meaningless if |
| 66 // |power_save_blocker_| is NULL. |
| 67 api::power::Level current_level_; |
| 68 |
| 69 // Map from extension ID to the corresponding level for each extension |
| 70 // that has an outstanding request. |
| 71 typedef std::map<std::string, api::power::Level> ExtensionLevelMap; |
| 72 ExtensionLevelMap extension_levels_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(PowerApiManager); |
| 75 }; |
| 76 |
| 77 } // namespace extensions |
| 78 |
| 79 #endif // CHROME_BROWSER_EXTENSIONS_API_POWER_POWER_API_MANAGER_H_ |
OLD | NEW |