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

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

Issue 335693003: Don't stop and restart GCM when extension/app is being updated (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 const std::string& app_id, 86 const std::string& app_id,
87 const gcm::GCMClient::SendErrorDetails& send_error_details) { 87 const gcm::GCMClient::SendErrorDetails& send_error_details) {
88 #if !defined(OS_ANDROID) 88 #if !defined(OS_ANDROID)
89 js_event_router_->OnSendError(app_id, send_error_details); 89 js_event_router_->OnSendError(app_id, send_error_details);
90 #endif 90 #endif
91 } 91 }
92 92
93 void ExtensionGCMAppHandler::OnExtensionLoaded( 93 void ExtensionGCMAppHandler::OnExtensionLoaded(
94 content::BrowserContext* browser_context, 94 content::BrowserContext* browser_context,
95 const Extension* extension) { 95 const Extension* extension) {
96 if (IsGCMPermissionEnabled(extension)) 96 // See OnExtensionUnloaded for the reason for checking if the app handler
97 GetGCMDriver()->AddAppHandler(extension->id(), this); 97 // has already been added.
98 if (IsGCMPermissionEnabled(extension) &&
99 !GetGCMDriver()->app_handlers().count(extension->id()))
100 AddAppHandler(extension->id());
98 } 101 }
99 102
100 void ExtensionGCMAppHandler::OnExtensionUnloaded( 103 void ExtensionGCMAppHandler::OnExtensionUnloaded(
101 content::BrowserContext* browser_context, 104 content::BrowserContext* browser_context,
102 const Extension* extension, 105 const Extension* extension,
103 UnloadedExtensionInfo::Reason reason) { 106 UnloadedExtensionInfo::Reason reason) {
104 if (IsGCMPermissionEnabled(extension)) 107 // When the extension is being updated, it will be first unloaded and then
105 GetGCMDriver()->RemoveAppHandler(extension->id()); 108 // loaded again. We don't want to remove and re-add the app handler that
109 // could cause the GCM service being stopped and restarted unnecessarily.
110 if (IsGCMPermissionEnabled(extension) &&
111 reason != UnloadedExtensionInfo::REASON_UPDATE)
112 RemoveAppHandler(extension->id());
fgorski 2014/06/12 21:38:32 If we are unlucky enough to get a message for the
jianli 2014/06/12 21:48:30 We hit DCHECK_EQ(LOADING, state_) in GCMClientImpl
fgorski 2014/06/13 15:20:21 I am with you on not restarting GCM connection. W
jianli 2014/06/17 00:41:56 The message routing will not be interrupted since
106 } 113 }
107 114
108 void ExtensionGCMAppHandler::OnExtensionUninstalled( 115 void ExtensionGCMAppHandler::OnExtensionUninstalled(
109 content::BrowserContext* browser_context, 116 content::BrowserContext* browser_context,
110 const Extension* extension) { 117 const Extension* extension) {
111 if (IsGCMPermissionEnabled(extension)) { 118 if (IsGCMPermissionEnabled(extension)) {
112 GetGCMDriver()->Unregister( 119 GetGCMDriver()->Unregister(
113 extension->id(), 120 extension->id(),
114 base::Bind(&ExtensionGCMAppHandler::OnUnregisterCompleted, 121 base::Bind(&ExtensionGCMAppHandler::OnUnregisterCompleted,
115 weak_factory_.GetWeakPtr(), 122 weak_factory_.GetWeakPtr(),
116 extension->id())); 123 extension->id()));
117 GetGCMDriver()->RemoveAppHandler(extension->id()); 124 RemoveAppHandler(extension->id());
118 } 125 }
119 } 126 }
120 127
121 gcm::GCMDriver* ExtensionGCMAppHandler::GetGCMDriver() const { 128 gcm::GCMDriver* ExtensionGCMAppHandler::GetGCMDriver() const {
122 return gcm::GCMProfileServiceFactory::GetForProfile(profile_)->driver(); 129 return gcm::GCMProfileServiceFactory::GetForProfile(profile_)->driver();
123 } 130 }
124 131
125 void ExtensionGCMAppHandler::OnUnregisterCompleted( 132 void ExtensionGCMAppHandler::OnUnregisterCompleted(
126 const std::string& app_id, gcm::GCMClient::Result result) { 133 const std::string& app_id, gcm::GCMClient::Result result) {
127 // Nothing to do. 134 // Nothing to do.
128 } 135 }
129 136
137 void ExtensionGCMAppHandler::AddAppHandler(const std::string& app_id) {
138 GetGCMDriver()->AddAppHandler(app_id, this);
139 }
140
141 void ExtensionGCMAppHandler::RemoveAppHandler(const std::string& app_id) {
142 GetGCMDriver()->RemoveAppHandler(app_id);
143 }
144
130 } // namespace extensions 145 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698