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

Side by Side Diff: chrome/browser/extensions/extension_gcm_app_handler.cc

Issue 913943002: Unregister from GCM when the only GCM app is removed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test Created 5 years, 10 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
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_gcm_app_handler_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // the update process since unloading and reloading extension are done in 117 // the update process since unloading and reloading extension are done in
118 // the single function ExtensionService::AddExtension. 118 // the single function ExtensionService::AddExtension.
119 AddDummyAppHandler(); 119 AddDummyAppHandler();
120 120
121 base::MessageLoop::current()->PostTask( 121 base::MessageLoop::current()->PostTask(
122 FROM_HERE, 122 FROM_HERE,
123 base::Bind(&ExtensionGCMAppHandler::RemoveDummyAppHandler, 123 base::Bind(&ExtensionGCMAppHandler::RemoveDummyAppHandler,
124 weak_factory_.GetWeakPtr())); 124 weak_factory_.GetWeakPtr()));
125 } 125 }
126 126
127 RemoveAppHandler(extension->id()); 127 // When the extention is being uninstalled, it will be unloaded first. We
128 // should not remove the app handler in this case and it will be handled
129 // in OnExtensionUninstalled.
130 if (reason != UnloadedExtensionInfo::REASON_UNINSTALL)
131 RemoveAppHandler(extension->id());
128 } 132 }
129 133
130 void ExtensionGCMAppHandler::OnExtensionUninstalled( 134 void ExtensionGCMAppHandler::OnExtensionUninstalled(
131 content::BrowserContext* browser_context, 135 content::BrowserContext* browser_context,
132 const Extension* extension, 136 const Extension* extension,
133 extensions::UninstallReason reason) { 137 extensions::UninstallReason reason) {
134 if (IsGCMPermissionEnabled(extension)) { 138 if (IsGCMPermissionEnabled(extension)) {
135 GetGCMDriver()->Unregister( 139 GetGCMDriver()->Unregister(
136 extension->id(), 140 extension->id(),
137 base::Bind(&ExtensionGCMAppHandler::OnUnregisterCompleted, 141 base::Bind(&ExtensionGCMAppHandler::OnUnregisterCompleted,
138 weak_factory_.GetWeakPtr(), 142 weak_factory_.GetWeakPtr(),
139 extension->id())); 143 extension->id()));
140 RemoveAppHandler(extension->id());
141 } 144 }
142 } 145 }
143 146
144 void ExtensionGCMAppHandler::AddDummyAppHandler() { 147 void ExtensionGCMAppHandler::AddDummyAppHandler() {
145 AddAppHandler(kDummyAppId); 148 AddAppHandler(kDummyAppId);
146 } 149 }
147 150
148 void ExtensionGCMAppHandler::RemoveDummyAppHandler() { 151 void ExtensionGCMAppHandler::RemoveDummyAppHandler() {
149 RemoveAppHandler(kDummyAppId); 152 RemoveAppHandler(kDummyAppId);
150 } 153 }
151 154
152 gcm::GCMDriver* ExtensionGCMAppHandler::GetGCMDriver() const { 155 gcm::GCMDriver* ExtensionGCMAppHandler::GetGCMDriver() const {
153 return gcm::GCMProfileServiceFactory::GetForProfile(profile_)->driver(); 156 return gcm::GCMProfileServiceFactory::GetForProfile(profile_)->driver();
154 } 157 }
155 158
156 void ExtensionGCMAppHandler::OnUnregisterCompleted( 159 void ExtensionGCMAppHandler::OnUnregisterCompleted(
157 const std::string& app_id, gcm::GCMClient::Result result) { 160 const std::string& app_id, gcm::GCMClient::Result result) {
158 // Nothing to do. 161 RemoveAppHandler(app_id);
159 } 162 }
160 163
161 void ExtensionGCMAppHandler::AddAppHandler(const std::string& app_id) { 164 void ExtensionGCMAppHandler::AddAppHandler(const std::string& app_id) {
162 GetGCMDriver()->AddAppHandler(app_id, this); 165 GetGCMDriver()->AddAppHandler(app_id, this);
163 } 166 }
164 167
165 void ExtensionGCMAppHandler::RemoveAppHandler(const std::string& app_id) { 168 void ExtensionGCMAppHandler::RemoveAppHandler(const std::string& app_id) {
166 GetGCMDriver()->RemoveAppHandler(app_id); 169 GetGCMDriver()->RemoveAppHandler(app_id);
167 } 170 }
168 171
169 } // namespace extensions 172 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_gcm_app_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698