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

Side by Side Diff: components/gcm_driver/gcm_driver.cc

Issue 618003002: [GCM] Handling connection events in GCMAccountTracker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing to Jian Li's patch and addressing unit tests failures Created 6 years, 2 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
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 "components/gcm_driver/gcm_driver.h" 5 #include "components/gcm_driver/gcm_driver.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/metrics/field_trial.h" 10 #include "base/metrics/field_trial.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 return; 144 return;
145 } 145 }
146 146
147 SendCallback callback = callback_iter->second; 147 SendCallback callback = callback_iter->second;
148 send_callbacks_.erase(callback_iter); 148 send_callbacks_.erase(callback_iter);
149 callback.Run(message_id, result); 149 callback.Run(message_id, result);
150 } 150 }
151 151
152 void GCMDriver::Shutdown() { 152 void GCMDriver::Shutdown() {
153 for (GCMAppHandlerMap::const_iterator iter = app_handlers_.begin(); 153 for (GCMAppHandlerMap::const_iterator iter = app_handlers_.begin();
154 iter != app_handlers_.end(); ++iter) { 154 iter != app_handlers_.end();) {
fgorski 2014/10/03 18:03:32 Jian Li, what do you think about this update?
155 iter->second->ShutdownHandler(); 155 DVLOG(1) << "Calling ShutdownHandler for: " << iter->first;
156 GCMAppHandler* handler = iter->second;
157 // Incrementing here, to make sure calls to RemoveAppHandler from
158 // ShutdownHandler don't invalidate the iterator.
159 ++iter;
160 handler->ShutdownHandler();
156 } 161 }
157 app_handlers_.clear(); 162 app_handlers_.clear();
158 } 163 }
159 164
160 void GCMDriver::AddAppHandler(const std::string& app_id, 165 void GCMDriver::AddAppHandler(const std::string& app_id,
161 GCMAppHandler* handler) { 166 GCMAppHandler* handler) {
162 DCHECK(!app_id.empty()); 167 DCHECK(!app_id.empty());
163 DCHECK(handler); 168 DCHECK(handler);
164 DCHECK_EQ(app_handlers_.count(app_id), 0u); 169 DCHECK_EQ(app_handlers_.count(app_id), 0u);
165 app_handlers_[app_id] = handler; 170 app_handlers_[app_id] = handler;
171 DVLOG(1) << "App handler added for: " << app_id;
166 } 172 }
167 173
168 void GCMDriver::RemoveAppHandler(const std::string& app_id) { 174 void GCMDriver::RemoveAppHandler(const std::string& app_id) {
169 DCHECK(!app_id.empty()); 175 DCHECK(!app_id.empty());
170 app_handlers_.erase(app_id); 176 app_handlers_.erase(app_id);
177 DVLOG(1) << "App handler removed for: " << app_id;
171 } 178 }
172 179
173 GCMAppHandler* GCMDriver::GetAppHandler(const std::string& app_id) { 180 GCMAppHandler* GCMDriver::GetAppHandler(const std::string& app_id) {
174 // Look for exact match. 181 // Look for exact match.
175 GCMAppHandlerMap::const_iterator iter = app_handlers_.find(app_id); 182 GCMAppHandlerMap::const_iterator iter = app_handlers_.find(app_id);
176 if (iter != app_handlers_.end()) 183 if (iter != app_handlers_.end())
177 return iter->second; 184 return iter->second;
178 185
179 // Ask the handlers whether they know how to handle it. 186 // Ask the handlers whether they know how to handle it.
180 for (iter = app_handlers_.begin(); iter != app_handlers_.end(); ++iter) { 187 for (iter = app_handlers_.begin(); iter != app_handlers_.end(); ++iter) {
(...skipping 13 matching lines...) Expand all
194 unregister_callbacks_.clear(); 201 unregister_callbacks_.clear();
195 send_callbacks_.clear(); 202 send_callbacks_.clear();
196 } 203 }
197 204
198 bool GCMDriver::IsAsyncOperationPending(const std::string& app_id) const { 205 bool GCMDriver::IsAsyncOperationPending(const std::string& app_id) const {
199 return register_callbacks_.find(app_id) != register_callbacks_.end() || 206 return register_callbacks_.find(app_id) != register_callbacks_.end() ||
200 unregister_callbacks_.find(app_id) != unregister_callbacks_.end(); 207 unregister_callbacks_.find(app_id) != unregister_callbacks_.end();
201 } 208 }
202 209
203 } // namespace gcm 210 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_account_mapper_unittest.cc ('k') | components/gcm_driver/gcm_driver_desktop.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698