OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_EXTENSIONS_API_IDLE_IDLE_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_IDLE_IDLE_MANAGER_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_API_IDLE_IDLE_MANAGER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_IDLE_IDLE_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/scoped_observer.h" | 14 #include "base/scoped_observer.h" |
15 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
16 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
17 #include "chrome/browser/idle.h" | 17 #include "chrome/browser/idle.h" |
18 #include "components/keyed_service/core/keyed_service.h" | 18 #include "components/keyed_service/core/keyed_service.h" |
19 #include "extensions/browser/event_router.h" | 19 #include "extensions/browser/event_router.h" |
20 #include "extensions/browser/extension_registry_observer.h" | 20 #include "extensions/browser/extension_registry_observer.h" |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 class StringValue; | 23 class StringValue; |
24 } // namespace base | 24 } // namespace base |
25 | 25 |
26 class Profile; | 26 namespace content { |
27 class BrowserContext; | |
28 } // namespace content | |
27 | 29 |
28 namespace extensions { | 30 namespace extensions { |
29 class ExtensionRegistry; | 31 class ExtensionRegistry; |
30 | 32 |
31 typedef base::Callback<void(IdleState)> QueryStateCallback; | 33 typedef base::Callback<void(IdleState)> QueryStateCallback; |
32 | 34 |
33 struct IdleMonitor { | 35 struct IdleMonitor { |
34 explicit IdleMonitor(IdleState initial_state); | 36 explicit IdleMonitor(IdleState initial_state); |
35 | 37 |
36 IdleState last_state; | 38 IdleState last_state; |
(...skipping 24 matching lines...) Expand all Loading... | |
61 virtual ~EventDelegate() {} | 63 virtual ~EventDelegate() {} |
62 virtual void OnStateChanged(const std::string& extension_id, | 64 virtual void OnStateChanged(const std::string& extension_id, |
63 IdleState new_state) = 0; | 65 IdleState new_state) = 0; |
64 virtual void RegisterObserver(EventRouter::Observer* observer) = 0; | 66 virtual void RegisterObserver(EventRouter::Observer* observer) = 0; |
65 virtual void UnregisterObserver(EventRouter::Observer* observer) = 0; | 67 virtual void UnregisterObserver(EventRouter::Observer* observer) = 0; |
66 | 68 |
67 private: | 69 private: |
68 DISALLOW_COPY_AND_ASSIGN(EventDelegate); | 70 DISALLOW_COPY_AND_ASSIGN(EventDelegate); |
69 }; | 71 }; |
70 | 72 |
71 explicit IdleManager(Profile* profile); | 73 explicit IdleManager(content::BrowserContext* context); |
72 ~IdleManager() override; | 74 ~IdleManager() override; |
73 | 75 |
74 void Init(); | 76 void Init(); |
75 | 77 |
76 // KeyedService implementation. | 78 // KeyedService implementation. |
77 void Shutdown() override; | 79 void Shutdown() override; |
78 | 80 |
79 // ExtensionRegistryObserver implementation. | 81 // ExtensionRegistryObserver implementation. |
80 void OnExtensionUnloaded(content::BrowserContext* browser_context, | 82 void OnExtensionUnloaded(content::BrowserContext* browser_context, |
81 const Extension* extension, | 83 const Extension* extension, |
(...skipping 30 matching lines...) Expand all Loading... | |
112 FRIEND_TEST_ALL_PREFIXES(IdleTest, UnloadCleanup); | 114 FRIEND_TEST_ALL_PREFIXES(IdleTest, UnloadCleanup); |
113 | 115 |
114 typedef std::map<const std::string, IdleMonitor> MonitorMap; | 116 typedef std::map<const std::string, IdleMonitor> MonitorMap; |
115 | 117 |
116 IdleMonitor* GetMonitor(const std::string& extension_id); | 118 IdleMonitor* GetMonitor(const std::string& extension_id); |
117 void StartPolling(); | 119 void StartPolling(); |
118 void StopPolling(); | 120 void StopPolling(); |
119 void UpdateIdleState(); | 121 void UpdateIdleState(); |
120 void UpdateIdleStateCallback(int idle_time); | 122 void UpdateIdleStateCallback(int idle_time); |
121 | 123 |
122 Profile* profile_; | 124 content::BrowserContext* context_; |
dcheng
2015/01/06 18:49:05
While you're changing this, mind making it content
Daniel Erat
2015/01/06 18:52:09
Done.
| |
123 | 125 |
124 IdleState last_state_; | 126 IdleState last_state_; |
125 MonitorMap monitors_; | 127 MonitorMap monitors_; |
126 | 128 |
127 base::RepeatingTimer<IdleManager> poll_timer_; | 129 base::RepeatingTimer<IdleManager> poll_timer_; |
128 | 130 |
129 scoped_ptr<IdleTimeProvider> idle_time_provider_; | 131 scoped_ptr<IdleTimeProvider> idle_time_provider_; |
130 scoped_ptr<EventDelegate> event_delegate_; | 132 scoped_ptr<EventDelegate> event_delegate_; |
131 | 133 |
132 base::ThreadChecker thread_checker_; | 134 base::ThreadChecker thread_checker_; |
133 | 135 |
134 // Listen to extension unloaded notification. | 136 // Listen to extension unloaded notification. |
135 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 137 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
136 extension_registry_observer_; | 138 extension_registry_observer_; |
137 | 139 |
138 base::WeakPtrFactory<IdleManager> weak_factory_; | 140 base::WeakPtrFactory<IdleManager> weak_factory_; |
139 | 141 |
140 DISALLOW_COPY_AND_ASSIGN(IdleManager); | 142 DISALLOW_COPY_AND_ASSIGN(IdleManager); |
141 }; | 143 }; |
142 | 144 |
143 } // namespace extensions | 145 } // namespace extensions |
144 | 146 |
145 #endif // CHROME_BROWSER_EXTENSIONS_API_IDLE_IDLE_MANAGER_H_ | 147 #endif // CHROME_BROWSER_EXTENSIONS_API_IDLE_IDLE_MANAGER_H_ |
OLD | NEW |