Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: chrome/browser/extensions/api/power/power_api_manager.h

Issue 12576018: Add chrome.power extension API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update PermissionsTest.PermissionMessages Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "content/public/browser/notification_observer.h"
15 #include "content/public/browser/notification_registrar.h"
16 #include "content/public/browser/power_save_blocker.h"
17
18 namespace extensions {
19
20 class PowerApiManager : public content::NotificationObserver {
21 public:
22 // Different levels of power-management-overriding. Keep in ascending
23 // order so that higher-valued levels' behavior subsumes lower-valued
24 // ones' behavior.
25 enum Level {
26 // Prevents the system from sleeping due to user inactivity.
27 LEVEL_SYSTEM = 0,
28
29 // Prevents the system from dimming the display, turning the display
30 // off, or sleeping due to user inactivity.
31 LEVEL_DISPLAY = 1,
not at google - send to devlin 2013/03/19 21:16:39 if it were an enum, you wouldn't need this definit
Daniel Erat 2013/03/19 23:39:38 Done.
32 };
33
34 typedef base::Callback<scoped_ptr<content::PowerSaveBlocker>(
35 content::PowerSaveBlocker::PowerSaveBlockerType,
36 const std::string&)> CreateBlockerFunction;
37
38 static PowerApiManager* GetInstance();
39
40 void set_create_blocker_function_for_testing(
41 scoped_ptr<CreateBlockerFunction> function) {
42 create_blocker_function_.swap(function);
43 }
44
45 // Adds an extension lock at |level| for |extension_id|, replacing the
46 // extension's existing lock, if any.
47 void AddRequest(const std::string& extension_id, Level level);
48
49 // Removes an extension lock for an extension. Calling this for an
50 // extension id without a lock will do nothing.
51 void RemoveRequest(const std::string& extension_id);
52
53 // Overridden from content::NotificationObserver.
54 virtual void Observe(int type,
55 const content::NotificationSource& source,
56 const content::NotificationDetails& details) OVERRIDE;
57
58 private:
59 friend struct DefaultSingletonTraits<PowerApiManager>;
60
61 PowerApiManager();
62 virtual ~PowerApiManager();
63
64 // Updates |power_save_blocker_| and |current_level_| after iterating
65 // over |extension_levels_|.
66 void UpdatePowerSaveBlocker();
67
68 content::NotificationRegistrar registrar_;
69
70 // Alternate function that should be called to create PowerSaveBlocker
71 // objects. Tests can use this to override what would've been done
72 // instead of actually changing the system power-saving settings. If
73 // NULL, content::PowerSaveBlocker::Create() is used.
74 scoped_ptr<CreateBlockerFunction> create_blocker_function_;
75
76 scoped_ptr<content::PowerSaveBlocker> power_save_blocker_;
77
78 // Current level used by |power_save_blocker_|. Meaningless if
79 // |power_save_blocker_| is NULL.
80 Level current_level_;
81
82 // Make from extension ID to the corresponding level for each extension
83 // that has an outstanding request.
84 typedef std::map<std::string, Level> ExtensionLevelMap;
85 ExtensionLevelMap extension_levels_;
86
87 DISALLOW_COPY_AND_ASSIGN(PowerApiManager);
88 };
89
90 } // namespace extensions
91
92 #endif // CHROME_BROWSER_EXTENSIONS_API_POWER_POWER_API_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698