| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "chrome/browser/extensions/extension_gcm_app_handler.h" | 5 #include "chrome/browser/extensions/extension_gcm_app_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/services/gcm/gcm_driver.h" | 12 #include "chrome/browser/services/gcm/gcm_driver.h" |
| 13 #include "chrome/browser/services/gcm/gcm_profile_service.h" | 13 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
| 14 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 14 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 15 #include "content/public/browser/notification_details.h" | |
| 16 #include "content/public/browser/notification_source.h" | |
| 17 #include "extensions/browser/extension_registry.h" | 15 #include "extensions/browser/extension_registry.h" |
| 18 #include "extensions/browser/extension_system.h" | 16 #include "extensions/browser/extension_system.h" |
| 19 #include "extensions/common/extension.h" | 17 #include "extensions/common/extension.h" |
| 20 #include "extensions/common/permissions/permissions_data.h" | 18 #include "extensions/common/permissions/permissions_data.h" |
| 21 | 19 |
| 22 #if !defined(OS_ANDROID) | 20 #if !defined(OS_ANDROID) |
| 23 #include "chrome/browser/extensions/api/gcm/gcm_api.h" | 21 #include "chrome/browser/extensions/api/gcm/gcm_api.h" |
| 24 #endif | 22 #endif |
| 25 | 23 |
| 26 namespace extensions { | 24 namespace extensions { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 41 BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>* | 39 BrowserContextKeyedAPIFactory<ExtensionGCMAppHandler>* |
| 42 ExtensionGCMAppHandler::GetFactoryInstance() { | 40 ExtensionGCMAppHandler::GetFactoryInstance() { |
| 43 return g_factory.Pointer(); | 41 return g_factory.Pointer(); |
| 44 } | 42 } |
| 45 | 43 |
| 46 ExtensionGCMAppHandler::ExtensionGCMAppHandler(content::BrowserContext* context) | 44 ExtensionGCMAppHandler::ExtensionGCMAppHandler(content::BrowserContext* context) |
| 47 : profile_(Profile::FromBrowserContext(context)), | 45 : profile_(Profile::FromBrowserContext(context)), |
| 48 extension_registry_observer_(this), | 46 extension_registry_observer_(this), |
| 49 weak_factory_(this) { | 47 weak_factory_(this) { |
| 50 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); | 48 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
| 51 registrar_.Add(this, | |
| 52 chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | |
| 53 content::Source<Profile>(profile_)); | |
| 54 | |
| 55 #if !defined(OS_ANDROID) | 49 #if !defined(OS_ANDROID) |
| 56 js_event_router_.reset(new extensions::GcmJsEventRouter(profile_)); | 50 js_event_router_.reset(new extensions::GcmJsEventRouter(profile_)); |
| 57 #endif | 51 #endif |
| 58 } | 52 } |
| 59 | 53 |
| 60 ExtensionGCMAppHandler::~ExtensionGCMAppHandler() { | 54 ExtensionGCMAppHandler::~ExtensionGCMAppHandler() { |
| 61 const ExtensionSet& enabled_extensions = | 55 const ExtensionSet& enabled_extensions = |
| 62 ExtensionRegistry::Get(profile_)->enabled_extensions(); | 56 ExtensionRegistry::Get(profile_)->enabled_extensions(); |
| 63 for (ExtensionSet::const_iterator extension = enabled_extensions.begin(); | 57 for (ExtensionSet::const_iterator extension = enabled_extensions.begin(); |
| 64 extension != enabled_extensions.end(); | 58 extension != enabled_extensions.end(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 } | 98 } |
| 105 | 99 |
| 106 void ExtensionGCMAppHandler::OnExtensionUnloaded( | 100 void ExtensionGCMAppHandler::OnExtensionUnloaded( |
| 107 content::BrowserContext* browser_context, | 101 content::BrowserContext* browser_context, |
| 108 const Extension* extension, | 102 const Extension* extension, |
| 109 UnloadedExtensionInfo::Reason reason) { | 103 UnloadedExtensionInfo::Reason reason) { |
| 110 if (IsGCMPermissionEnabled(extension)) | 104 if (IsGCMPermissionEnabled(extension)) |
| 111 GetGCMDriver()->RemoveAppHandler(extension->id()); | 105 GetGCMDriver()->RemoveAppHandler(extension->id()); |
| 112 } | 106 } |
| 113 | 107 |
| 114 void ExtensionGCMAppHandler::Observe( | 108 void ExtensionGCMAppHandler::OnExtensionUninstalled( |
| 115 int type, | 109 content::BrowserContext* browser_context, |
| 116 const content::NotificationSource& source, | 110 const Extension* extension) { |
| 117 const content::NotificationDetails& details) { | |
| 118 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNINSTALLED, type); | |
| 119 const Extension* extension = content::Details<Extension>(details).ptr(); | |
| 120 if (IsGCMPermissionEnabled(extension)) { | 111 if (IsGCMPermissionEnabled(extension)) { |
| 121 GetGCMDriver()->Unregister( | 112 GetGCMDriver()->Unregister( |
| 122 extension->id(), | 113 extension->id(), |
| 123 base::Bind(&ExtensionGCMAppHandler::OnUnregisterCompleted, | 114 base::Bind(&ExtensionGCMAppHandler::OnUnregisterCompleted, |
| 124 weak_factory_.GetWeakPtr(), | 115 weak_factory_.GetWeakPtr(), |
| 125 extension->id())); | 116 extension->id())); |
| 126 GetGCMDriver()->RemoveAppHandler(extension->id()); | 117 GetGCMDriver()->RemoveAppHandler(extension->id()); |
| 127 } | 118 } |
| 128 } | 119 } |
| 129 | 120 |
| 130 gcm::GCMDriver* ExtensionGCMAppHandler::GetGCMDriver() const { | 121 gcm::GCMDriver* ExtensionGCMAppHandler::GetGCMDriver() const { |
| 131 return gcm::GCMProfileServiceFactory::GetForProfile(profile_)->driver(); | 122 return gcm::GCMProfileServiceFactory::GetForProfile(profile_)->driver(); |
| 132 } | 123 } |
| 133 | 124 |
| 134 void ExtensionGCMAppHandler::OnUnregisterCompleted( | 125 void ExtensionGCMAppHandler::OnUnregisterCompleted( |
| 135 const std::string& app_id, gcm::GCMClient::Result result) { | 126 const std::string& app_id, gcm::GCMClient::Result result) { |
| 136 // Nothing to do. | 127 // Nothing to do. |
| 137 } | 128 } |
| 138 | 129 |
| 139 } // namespace extensions | 130 } // namespace extensions |
| OLD | NEW |