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_profile_service.h" | 12 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
13 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 13 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
14 #include "chrome/browser/services/gcm/gcm_service.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) |
22 #include "chrome/browser/extensions/api/gcm/gcm_api.h" | 23 #include "chrome/browser/extensions/api/gcm/gcm_api.h" |
23 #endif | 24 #endif |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 #endif | 62 #endif |
62 } | 63 } |
63 | 64 |
64 ExtensionGCMAppHandler::~ExtensionGCMAppHandler() { | 65 ExtensionGCMAppHandler::~ExtensionGCMAppHandler() { |
65 const ExtensionSet& enabled_extensions = | 66 const ExtensionSet& enabled_extensions = |
66 ExtensionRegistry::Get(profile_)->enabled_extensions(); | 67 ExtensionRegistry::Get(profile_)->enabled_extensions(); |
67 for (ExtensionSet::const_iterator extension = enabled_extensions.begin(); | 68 for (ExtensionSet::const_iterator extension = enabled_extensions.begin(); |
68 extension != enabled_extensions.end(); | 69 extension != enabled_extensions.end(); |
69 ++extension) { | 70 ++extension) { |
70 if (IsGCMPermissionEnabled(extension->get())) | 71 if (IsGCMPermissionEnabled(extension->get())) |
71 GetGCMProfileService()->RemoveAppHandler((*extension)->id()); | 72 GetGCMService()->RemoveAppHandler((*extension)->id()); |
jianli
2014/04/10 20:39:56
Why? Extension is tied with profile.
bartfab (slow)
2014/04/11 16:58:52
I had made the change here to make it explicit tha
| |
72 } | 73 } |
73 } | 74 } |
74 | 75 |
75 void ExtensionGCMAppHandler::ShutdownHandler() { | 76 void ExtensionGCMAppHandler::ShutdownHandler() { |
76 #if !defined(OS_ANDROID) | 77 #if !defined(OS_ANDROID) |
77 js_event_router_.reset(); | 78 js_event_router_.reset(); |
78 #endif | 79 #endif |
79 } | 80 } |
80 | 81 |
81 void ExtensionGCMAppHandler::OnMessage( | 82 void ExtensionGCMAppHandler::OnMessage( |
(...skipping 19 matching lines...) Expand all Loading... | |
101 } | 102 } |
102 | 103 |
103 void ExtensionGCMAppHandler::Observe( | 104 void ExtensionGCMAppHandler::Observe( |
104 int type, | 105 int type, |
105 const content::NotificationSource& source, | 106 const content::NotificationSource& source, |
106 const content::NotificationDetails& details) { | 107 const content::NotificationDetails& details) { |
107 switch (type) { | 108 switch (type) { |
108 case chrome:: NOTIFICATION_EXTENSION_LOADED: { | 109 case chrome:: NOTIFICATION_EXTENSION_LOADED: { |
109 const Extension* extension = content::Details<Extension>(details).ptr(); | 110 const Extension* extension = content::Details<Extension>(details).ptr(); |
110 if (IsGCMPermissionEnabled(extension)) | 111 if (IsGCMPermissionEnabled(extension)) |
111 GetGCMProfileService()->AddAppHandler(extension->id(), this); | 112 GetGCMService()->AddAppHandler(extension->id(), this); |
112 break; | 113 break; |
113 } | 114 } |
114 case chrome:: NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { | 115 case chrome:: NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: { |
115 const Extension* extension = | 116 const Extension* extension = |
116 content::Details<UnloadedExtensionInfo>(details)->extension; | 117 content::Details<UnloadedExtensionInfo>(details)->extension; |
117 if (IsGCMPermissionEnabled(extension)) | 118 if (IsGCMPermissionEnabled(extension)) |
118 GetGCMProfileService()->RemoveAppHandler(extension->id()); | 119 GetGCMService()->RemoveAppHandler(extension->id()); |
119 break; | 120 break; |
120 } | 121 } |
121 case chrome:: NOTIFICATION_EXTENSION_UNINSTALLED: { | 122 case chrome:: NOTIFICATION_EXTENSION_UNINSTALLED: { |
122 const Extension* extension = content::Details<Extension>(details).ptr(); | 123 const Extension* extension = content::Details<Extension>(details).ptr(); |
123 if (IsGCMPermissionEnabled(extension)) { | 124 if (IsGCMPermissionEnabled(extension)) { |
124 GetGCMProfileService()->Unregister( | 125 GetGCMService()->Unregister( |
125 extension->id(), | 126 extension->id(), |
126 base::Bind(&ExtensionGCMAppHandler::OnUnregisterCompleted, | 127 base::Bind(&ExtensionGCMAppHandler::OnUnregisterCompleted, |
127 weak_factory_.GetWeakPtr(), | 128 weak_factory_.GetWeakPtr(), |
128 extension->id())); | 129 extension->id())); |
129 GetGCMProfileService()->RemoveAppHandler(extension->id()); | 130 GetGCMService()->RemoveAppHandler(extension->id()); |
130 } | 131 } |
131 break; | 132 break; |
132 } | 133 } |
133 default: | 134 default: |
134 NOTREACHED(); | 135 NOTREACHED(); |
135 } | 136 } |
136 } | 137 } |
137 | 138 |
138 gcm::GCMProfileService* ExtensionGCMAppHandler::GetGCMProfileService() const { | 139 gcm::GCMService* ExtensionGCMAppHandler::GetGCMService() const { |
139 return gcm::GCMProfileServiceFactory::GetForProfile(profile_); | 140 return gcm::GCMProfileServiceFactory::GetForProfile(profile_); |
140 } | 141 } |
141 | 142 |
142 void ExtensionGCMAppHandler::OnUnregisterCompleted( | 143 void ExtensionGCMAppHandler::OnUnregisterCompleted( |
143 const std::string& app_id, gcm::GCMClient::Result result) { | 144 const std::string& app_id, gcm::GCMClient::Result result) { |
144 // Nothing to do. | 145 // Nothing to do. |
145 } | 146 } |
146 | 147 |
147 } // namespace extensions | 148 } // namespace extensions |
OLD | NEW |