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

Side by Side Diff: chrome/browser/extensions/api/push_messaging/push_messaging_api.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_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__
6 #define CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ 6 #define CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/scoped_observer.h"
14 #include "chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetche r.h" 15 #include "chrome/browser/extensions/api/push_messaging/obfuscated_gaia_id_fetche r.h"
15 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati on_handler_delegate.h" 16 #include "chrome/browser/extensions/api/push_messaging/push_messaging_invalidati on_handler_delegate.h"
16 #include "chrome/browser/extensions/chrome_extension_function.h" 17 #include "chrome/browser/extensions/chrome_extension_function.h"
17 #include "chrome/browser/ui/webui/signin/login_ui_service.h" 18 #include "chrome/browser/ui/webui/signin/login_ui_service.h"
18 #include "content/public/browser/notification_observer.h" 19 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h" 20 #include "content/public/browser/notification_registrar.h"
20 #include "extensions/browser/browser_context_keyed_api_factory.h" 21 #include "extensions/browser/browser_context_keyed_api_factory.h"
22 #include "extensions/browser/extension_registry_observer.h"
21 #include "google_apis/gaia/google_service_auth_error.h" 23 #include "google_apis/gaia/google_service_auth_error.h"
22 #include "google_apis/gaia/oauth2_token_service.h" 24 #include "google_apis/gaia/oauth2_token_service.h"
23 25
24 class Profile; 26 class Profile;
25 27
26 namespace content { 28 namespace content {
27 class BrowserContext; 29 class BrowserContext;
28 } 30 }
29 31
30 namespace extensions { 32 namespace extensions {
31 33 class ExtensionRegistry;
32 class PushMessagingInvalidationMapper; 34 class PushMessagingInvalidationMapper;
33 35
34 // Observes a single InvalidationHandler and generates onMessage events. 36 // Observes a single InvalidationHandler and generates onMessage events.
35 class PushMessagingEventRouter 37 class PushMessagingEventRouter
36 : public PushMessagingInvalidationHandlerDelegate { 38 : public PushMessagingInvalidationHandlerDelegate {
37 public: 39 public:
38 explicit PushMessagingEventRouter(Profile* profile); 40 explicit PushMessagingEventRouter(Profile* profile);
39 virtual ~PushMessagingEventRouter(); 41 virtual ~PushMessagingEventRouter();
40 42
41 // For testing purposes. 43 // For testing purposes.
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 const GoogleServiceAuthError& error) OVERRIDE; 104 const GoogleServiceAuthError& error) OVERRIDE;
103 105
104 scoped_ptr<ObfuscatedGaiaIdFetcher> fetcher_; 106 scoped_ptr<ObfuscatedGaiaIdFetcher> fetcher_;
105 bool interactive_; 107 bool interactive_;
106 scoped_ptr<OAuth2TokenService::Request> fetcher_access_token_request_; 108 scoped_ptr<OAuth2TokenService::Request> fetcher_access_token_request_;
107 109
108 DISALLOW_COPY_AND_ASSIGN(PushMessagingGetChannelIdFunction); 110 DISALLOW_COPY_AND_ASSIGN(PushMessagingGetChannelIdFunction);
109 }; 111 };
110 112
111 class PushMessagingAPI : public BrowserContextKeyedAPI, 113 class PushMessagingAPI : public BrowserContextKeyedAPI,
112 public content::NotificationObserver { 114 public content::NotificationObserver,
115 public ExtensionRegistryObserver {
113 public: 116 public:
114 explicit PushMessagingAPI(content::BrowserContext* context); 117 explicit PushMessagingAPI(content::BrowserContext* context);
115 virtual ~PushMessagingAPI(); 118 virtual ~PushMessagingAPI();
116 119
117 // Convenience method to get the PushMessagingAPI for a profile. 120 // Convenience method to get the PushMessagingAPI for a profile.
118 static PushMessagingAPI* Get(content::BrowserContext* context); 121 static PushMessagingAPI* Get(content::BrowserContext* context);
119 122
120 // KeyedService implementation. 123 // KeyedService implementation.
121 virtual void Shutdown() OVERRIDE; 124 virtual void Shutdown() OVERRIDE;
122 125
(...skipping 16 matching lines...) Expand all
139 static const char* service_name() { 142 static const char* service_name() {
140 return "PushMessagingAPI"; 143 return "PushMessagingAPI";
141 } 144 }
142 static const bool kServiceIsNULLWhileTesting = true; 145 static const bool kServiceIsNULLWhileTesting = true;
143 146
144 // content::NotificationDelegate implementation. 147 // content::NotificationDelegate implementation.
145 virtual void Observe(int type, 148 virtual void Observe(int type,
146 const content::NotificationSource& source, 149 const content::NotificationSource& source,
147 const content::NotificationDetails& details) OVERRIDE; 150 const content::NotificationDetails& details) OVERRIDE;
148 151
152 // Overridden from ExtensionRegistryObserver.
153 virtual void OnExtensionLoaded(content::BrowserContext* browser_context,
154 const Extension* extension) OVERRIDE;
155 virtual void OnExtensionUnloaded(
156 content::BrowserContext* browser_context,
157 const Extension* extension,
158 UnloadedExtensionInfo::Reason reason) OVERRIDE;
159
149 // Created lazily when an app or extension with the push messaging permission 160 // Created lazily when an app or extension with the push messaging permission
150 // is loaded. 161 // is loaded.
151 scoped_ptr<PushMessagingEventRouter> event_router_; 162 scoped_ptr<PushMessagingEventRouter> event_router_;
152 scoped_ptr<PushMessagingInvalidationMapper> handler_; 163 scoped_ptr<PushMessagingInvalidationMapper> handler_;
153 164
154 content::NotificationRegistrar registrar_; 165 content::NotificationRegistrar registrar_;
155 166
167 // Listen to extension load, unload notifications.
168 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
169 extension_registry_observer_;
170
156 Profile* profile_; 171 Profile* profile_;
157 172
158 DISALLOW_COPY_AND_ASSIGN(PushMessagingAPI); 173 DISALLOW_COPY_AND_ASSIGN(PushMessagingAPI);
159 }; 174 };
160 175
161 template <> 176 template <>
162 void BrowserContextKeyedAPIFactory< 177 void BrowserContextKeyedAPIFactory<
163 PushMessagingAPI>::DeclareFactoryDependencies(); 178 PushMessagingAPI>::DeclareFactoryDependencies();
164 179
165 } // namespace extensions 180 } // namespace extensions
166 181
167 #endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__ 182 #endif // CHROME_BROWSER_EXTENSIONS_API_PUSH_MESSAGING_PUSH_MESSAGING_API_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698