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

Side by Side Diff: chrome/browser/extensions/api/idle/idle_manager.h

Issue 275383002: Use ExtensionRegistryObserver instead of deprecated extension notification from c/b/e/api. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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
OLDNEW
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/threading/thread_checker.h" 15 #include "base/threading/thread_checker.h"
15 #include "base/timer/timer.h" 16 #include "base/timer/timer.h"
16 #include "chrome/browser/idle.h" 17 #include "chrome/browser/idle.h"
17 #include "components/keyed_service/core/keyed_service.h" 18 #include "components/keyed_service/core/keyed_service.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h"
20 #include "extensions/browser/event_router.h" 19 #include "extensions/browser/event_router.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 class Profile;
27 27
28 namespace extensions { 28 namespace extensions {
29 class ExtensionRegistry;
29 30
30 typedef base::Callback<void(IdleState)> QueryStateCallback; 31 typedef base::Callback<void(IdleState)> QueryStateCallback;
31 32
32 struct IdleMonitor { 33 struct IdleMonitor {
33 explicit IdleMonitor(IdleState initial_state); 34 explicit IdleMonitor(IdleState initial_state);
34 35
35 IdleState last_state; 36 IdleState last_state;
36 int listeners; 37 int listeners;
37 int threshold; 38 int threshold;
38 }; 39 };
39 40
40 class IdleManager : public content::NotificationObserver, 41 class IdleManager : public ExtensionRegistryObserver,
41 public EventRouter::Observer, 42 public EventRouter::Observer,
42 public KeyedService { 43 public KeyedService {
43 public: 44 public:
44 class IdleTimeProvider { 45 class IdleTimeProvider {
45 public: 46 public:
46 IdleTimeProvider() {} 47 IdleTimeProvider() {}
47 virtual ~IdleTimeProvider() {} 48 virtual ~IdleTimeProvider() {}
48 virtual void CalculateIdleState(int idle_threshold, 49 virtual void CalculateIdleState(int idle_threshold,
49 IdleCallback notify) = 0; 50 IdleCallback notify) = 0;
50 virtual void CalculateIdleTime(IdleTimeCallback notify) = 0; 51 virtual void CalculateIdleTime(IdleTimeCallback notify) = 0;
(...skipping 17 matching lines...) Expand all
68 }; 69 };
69 70
70 explicit IdleManager(Profile* profile); 71 explicit IdleManager(Profile* profile);
71 virtual ~IdleManager(); 72 virtual ~IdleManager();
72 73
73 void Init(); 74 void Init();
74 75
75 // KeyedService implementation. 76 // KeyedService implementation.
76 virtual void Shutdown() OVERRIDE; 77 virtual void Shutdown() OVERRIDE;
77 78
78 // content::NotificationDelegate implementation. 79 // ExtensionRegistryObserver implementation.
79 virtual void Observe(int type, 80 virtual void OnExtensionUnloaded(
80 const content::NotificationSource& source, 81 content::BrowserContext* browser_context,
81 const content::NotificationDetails& details) OVERRIDE; 82 const Extension* extension,
83 UnloadedExtensionInfo::Reason reason) OVERRIDE;
82 84
83 // EventRouter::Observer implementation. 85 // EventRouter::Observer implementation.
84 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; 86 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE;
85 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE; 87 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE;
86 88
87 void QueryState(int threshold, QueryStateCallback notify); 89 void QueryState(int threshold, QueryStateCallback notify);
88 void SetThreshold(const std::string& extension_id, int threshold); 90 void SetThreshold(const std::string& extension_id, int threshold);
89 static base::StringValue* CreateIdleValue(IdleState idle_state); 91 static base::StringValue* CreateIdleValue(IdleState idle_state);
90 92
91 // Override default event class. Callee assumes ownership. Used for testing. 93 // Override default event class. Callee assumes ownership. Used for testing.
(...skipping 26 matching lines...) Expand all
118 void UpdateIdleState(); 120 void UpdateIdleState();
119 void UpdateIdleStateCallback(int idle_time); 121 void UpdateIdleStateCallback(int idle_time);
120 122
121 Profile* profile_; 123 Profile* profile_;
122 124
123 IdleState last_state_; 125 IdleState last_state_;
124 MonitorMap monitors_; 126 MonitorMap monitors_;
125 127
126 base::RepeatingTimer<IdleManager> poll_timer_; 128 base::RepeatingTimer<IdleManager> poll_timer_;
127 base::WeakPtrFactory<IdleManager> weak_factory_; 129 base::WeakPtrFactory<IdleManager> weak_factory_;
128 content::NotificationRegistrar registrar_;
129 130
130 scoped_ptr<IdleTimeProvider> idle_time_provider_; 131 scoped_ptr<IdleTimeProvider> idle_time_provider_;
131 scoped_ptr<EventDelegate> event_delegate_; 132 scoped_ptr<EventDelegate> event_delegate_;
132 133
133 base::ThreadChecker thread_checker_; 134 base::ThreadChecker thread_checker_;
134 135
136 // Listen to extension unloaded notification.
137 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
138 extension_registry_observer_;
139
135 DISALLOW_COPY_AND_ASSIGN(IdleManager); 140 DISALLOW_COPY_AND_ASSIGN(IdleManager);
136 }; 141 };
137 142
138 } // namespace extensions 143 } // namespace extensions
139 144
140 #endif // CHROME_BROWSER_EXTENSIONS_API_IDLE_IDLE_MANAGER_H_ 145 #endif // CHROME_BROWSER_EXTENSIONS_API_IDLE_IDLE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698