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_profile_service.h" | 13 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
13 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 14 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
14 #include "content/public/browser/notification_details.h" | 15 #include "content/public/browser/notification_details.h" |
15 #include "content/public/browser/notification_source.h" | 16 #include "content/public/browser/notification_source.h" |
16 #include "extensions/browser/extension_registry.h" | 17 #include "extensions/browser/extension_registry.h" |
17 #include "extensions/browser/extension_system.h" | 18 #include "extensions/browser/extension_system.h" |
18 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
19 #include "extensions/common/permissions/permissions_data.h" | 20 #include "extensions/common/permissions/permissions_data.h" |
20 | 21 |
21 #if !defined(OS_ANDROID) | 22 #if !defined(OS_ANDROID) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 #endif | 57 #endif |
57 } | 58 } |
58 | 59 |
59 ExtensionGCMAppHandler::~ExtensionGCMAppHandler() { | 60 ExtensionGCMAppHandler::~ExtensionGCMAppHandler() { |
60 const ExtensionSet& enabled_extensions = | 61 const ExtensionSet& enabled_extensions = |
61 ExtensionRegistry::Get(profile_)->enabled_extensions(); | 62 ExtensionRegistry::Get(profile_)->enabled_extensions(); |
62 for (ExtensionSet::const_iterator extension = enabled_extensions.begin(); | 63 for (ExtensionSet::const_iterator extension = enabled_extensions.begin(); |
63 extension != enabled_extensions.end(); | 64 extension != enabled_extensions.end(); |
64 ++extension) { | 65 ++extension) { |
65 if (IsGCMPermissionEnabled(extension->get())) | 66 if (IsGCMPermissionEnabled(extension->get())) |
66 GetGCMProfileService()->RemoveAppHandler((*extension)->id()); | 67 GetGCMDriver()->RemoveAppHandler((*extension)->id()); |
67 } | 68 } |
68 } | 69 } |
69 | 70 |
70 void ExtensionGCMAppHandler::ShutdownHandler() { | 71 void ExtensionGCMAppHandler::ShutdownHandler() { |
71 #if !defined(OS_ANDROID) | 72 #if !defined(OS_ANDROID) |
72 js_event_router_.reset(); | 73 js_event_router_.reset(); |
73 #endif | 74 #endif |
74 } | 75 } |
75 | 76 |
76 void ExtensionGCMAppHandler::OnMessage( | 77 void ExtensionGCMAppHandler::OnMessage( |
(...skipping 15 matching lines...) Expand all Loading... |
92 const gcm::GCMClient::SendErrorDetails& send_error_details) { | 93 const gcm::GCMClient::SendErrorDetails& send_error_details) { |
93 #if !defined(OS_ANDROID) | 94 #if !defined(OS_ANDROID) |
94 js_event_router_->OnSendError(app_id, send_error_details); | 95 js_event_router_->OnSendError(app_id, send_error_details); |
95 #endif | 96 #endif |
96 } | 97 } |
97 | 98 |
98 void ExtensionGCMAppHandler::OnExtensionLoaded( | 99 void ExtensionGCMAppHandler::OnExtensionLoaded( |
99 content::BrowserContext* browser_context, | 100 content::BrowserContext* browser_context, |
100 const Extension* extension) { | 101 const Extension* extension) { |
101 if (IsGCMPermissionEnabled(extension)) | 102 if (IsGCMPermissionEnabled(extension)) |
102 GetGCMProfileService()->AddAppHandler(extension->id(), this); | 103 GetGCMDriver()->AddAppHandler(extension->id(), this); |
103 } | 104 } |
104 | 105 |
105 void ExtensionGCMAppHandler::OnExtensionUnloaded( | 106 void ExtensionGCMAppHandler::OnExtensionUnloaded( |
106 content::BrowserContext* browser_context, | 107 content::BrowserContext* browser_context, |
107 const Extension* extension, | 108 const Extension* extension, |
108 UnloadedExtensionInfo::Reason reason) { | 109 UnloadedExtensionInfo::Reason reason) { |
109 if (IsGCMPermissionEnabled(extension)) | 110 if (IsGCMPermissionEnabled(extension)) |
110 GetGCMProfileService()->RemoveAppHandler(extension->id()); | 111 GetGCMDriver()->RemoveAppHandler(extension->id()); |
111 } | 112 } |
112 | 113 |
113 void ExtensionGCMAppHandler::Observe( | 114 void ExtensionGCMAppHandler::Observe( |
114 int type, | 115 int type, |
115 const content::NotificationSource& source, | 116 const content::NotificationSource& source, |
116 const content::NotificationDetails& details) { | 117 const content::NotificationDetails& details) { |
117 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNINSTALLED, type); | 118 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_UNINSTALLED, type); |
118 const Extension* extension = content::Details<Extension>(details).ptr(); | 119 const Extension* extension = content::Details<Extension>(details).ptr(); |
119 if (IsGCMPermissionEnabled(extension)) { | 120 if (IsGCMPermissionEnabled(extension)) { |
120 GetGCMProfileService()->Unregister( | 121 GetGCMDriver()->Unregister( |
121 extension->id(), | 122 extension->id(), |
122 base::Bind(&ExtensionGCMAppHandler::OnUnregisterCompleted, | 123 base::Bind(&ExtensionGCMAppHandler::OnUnregisterCompleted, |
123 weak_factory_.GetWeakPtr(), | 124 weak_factory_.GetWeakPtr(), |
124 extension->id())); | 125 extension->id())); |
125 GetGCMProfileService()->RemoveAppHandler(extension->id()); | 126 GetGCMDriver()->RemoveAppHandler(extension->id()); |
126 } | 127 } |
127 } | 128 } |
128 | 129 |
129 gcm::GCMProfileService* ExtensionGCMAppHandler::GetGCMProfileService() const { | 130 gcm::GCMDriver* ExtensionGCMAppHandler::GetGCMDriver() const { |
130 return gcm::GCMProfileServiceFactory::GetForProfile(profile_); | 131 return gcm::GCMProfileServiceFactory::GetForProfile(profile_)->driver(); |
131 } | 132 } |
132 | 133 |
133 void ExtensionGCMAppHandler::OnUnregisterCompleted( | 134 void ExtensionGCMAppHandler::OnUnregisterCompleted( |
134 const std::string& app_id, gcm::GCMClient::Result result) { | 135 const std::string& app_id, gcm::GCMClient::Result result) { |
135 // Nothing to do. | 136 // Nothing to do. |
136 } | 137 } |
137 | 138 |
138 } // namespace extensions | 139 } // namespace extensions |
OLD | NEW |