Chromium Code Reviews| Index: chrome/browser/extensions/api/push_messaging/push_messaging_api.cc |
| diff --git a/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc b/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc |
| index 95684dd9cdd03156ecbccdd23daa3460e15c7c99..e3dc320aefbf6d259ee5659cf1fea0f9ca90f7ae 100644 |
| --- a/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc |
| +++ b/chrome/browser/extensions/api/push_messaging/push_messaging_api.cc |
| @@ -28,6 +28,7 @@ |
| #include "content/public/browser/notification_details.h" |
| #include "content/public/browser/notification_source.h" |
| #include "extensions/browser/event_router.h" |
| +#include "extensions/browser/extension_registry.h" |
| #include "extensions/browser/extension_system_provider.h" |
| #include "extensions/browser/extensions_browser_client.h" |
| #include "extensions/common/extension.h" |
| @@ -75,8 +76,7 @@ void PushMessagingEventRouter::OnMessage(const std::string& extension_id, |
| << "' extension = '" << extension_id << "'"; |
| scoped_ptr<base::ListValue> args(glue::OnMessage::Create(message)); |
| - scoped_ptr<extensions::Event> event( |
| - new extensions::Event(glue::OnMessage::kEventName, args.Pass())); |
| + scoped_ptr<Event> event(new Event(glue::OnMessage::kEventName, args.Pass())); |
| event->restrict_to_browser_context = profile_; |
| EventRouter::Get(profile_)->DispatchEventToExtension( |
| extension_id, event.Pass()); |
| @@ -287,14 +287,11 @@ void PushMessagingGetChannelIdFunction::OnObfuscatedGaiaIdFetchFailure( |
| } |
| PushMessagingAPI::PushMessagingAPI(content::BrowserContext* context) |
| - : profile_(Profile::FromBrowserContext(context)) { |
| + : extension_registry_observer_(this), |
| + profile_(Profile::FromBrowserContext(context)) { |
| + extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
| registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_INSTALLED, |
| content::Source<Profile>(profile_->GetOriginalProfile())); |
| - registrar_.Add(this, |
| - chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| - content::Source<Profile>(profile_->GetOriginalProfile())); |
| - registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED, |
| - content::Source<Profile>(profile_->GetOriginalProfile())); |
| } |
| PushMessagingAPI::~PushMessagingAPI() { |
| @@ -319,9 +316,50 @@ PushMessagingAPI::GetFactoryInstance() { |
| return g_factory.Pointer(); |
| } |
| +void PushMessagingAPI::OnExtensionLoaded( |
| + content::BrowserContext* browser_context, |
| + const Extension* extension) { |
| + invalidation::InvalidationService* invalidation_service = |
| + invalidation::InvalidationServiceFactory::GetForProfile(profile_); |
| + if (!invalidation_service) |
| + return; |
| + |
| + if (!event_router_) |
| + event_router_.reset(new PushMessagingEventRouter(profile_)); |
| + if (!handler_) { |
| + handler_.reset(new PushMessagingInvalidationHandler(invalidation_service, |
| + event_router_.get())); |
| + } |
|
not at google - send to devlin
2014/05/12 17:53:27
can you pull this initialization code into a funct
limasdf
2014/05/12 23:20:16
Done.
|
| + if (extension->HasAPIPermission(APIPermission::kPushMessaging)) { |
| + handler_->RegisterExtension(extension->id()); |
| + } |
| +} |
| + |
| +void PushMessagingAPI::OnExtensionUnloaded( |
| + content::BrowserContext* browser_context, |
| + const Extension* extension, |
| + UnloadedExtensionInfo::Reason reason) { |
| + invalidation::InvalidationService* invalidation_service = |
| + invalidation::InvalidationServiceFactory::GetForProfile(profile_); |
| + if (!invalidation_service) |
| + return; |
| + |
| + if (!event_router_) |
| + event_router_.reset(new PushMessagingEventRouter(profile_)); |
| + if (!handler_) { |
| + handler_.reset(new PushMessagingInvalidationHandler(invalidation_service, |
| + event_router_.get())); |
| + } |
| + if (extension->HasAPIPermission(APIPermission::kPushMessaging)) { |
| + handler_->UnregisterExtension(extension->id()); |
| + } |
| +} |
| + |
| void PushMessagingAPI::Observe(int type, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) { |
| + DCHECK_EQ(type, chrome::NOTIFICATION_EXTENSION_INSTALLED); |
| + |
| invalidation::InvalidationService* invalidation_service = |
| invalidation::InvalidationServiceFactory::GetForProfile(profile_); |
| if (!invalidation_service) |
| @@ -333,32 +371,11 @@ void PushMessagingAPI::Observe(int type, |
| handler_.reset(new PushMessagingInvalidationHandler( |
| invalidation_service, event_router_.get())); |
| } |
| - switch (type) { |
| - case chrome::NOTIFICATION_EXTENSION_INSTALLED: { |
| - const Extension* extension = |
| - content::Details<const InstalledExtensionInfo>(details)->extension; |
| - if (extension->HasAPIPermission(APIPermission::kPushMessaging)) { |
| - handler_->SuppressInitialInvalidationsForExtension(extension->id()); |
| - } |
| - break; |
| - } |
| - case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: { |
| - const Extension* extension = content::Details<Extension>(details).ptr(); |
| - if (extension->HasAPIPermission(APIPermission::kPushMessaging)) { |
| - handler_->RegisterExtension(extension->id()); |
| - } |
| - break; |
| - } |
| - case chrome::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { |
| - const Extension* extension = |
| - content::Details<UnloadedExtensionInfo>(details)->extension; |
| - if (extension->HasAPIPermission(APIPermission::kPushMessaging)) { |
| - handler_->UnregisterExtension(extension->id()); |
| - } |
| - break; |
| - } |
| - default: |
| - NOTREACHED(); |
| + |
| + const Extension* extension = |
| + content::Details<const InstalledExtensionInfo>(details)->extension; |
| + if (extension->HasAPIPermission(APIPermission::kPushMessaging)) { |
| + handler_->SuppressInitialInvalidationsForExtension(extension->id()); |
| } |
| } |