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

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

Issue 338363003: Push API: register PushMessagingServiceImpl as GCMAppHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add as AppHandler before calling Register. Other review issues. 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 "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 "components/gcm_driver/gcm_app_handler.h" 10 #include "components/gcm_driver/gcm_app_handler.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 iter != app_handlers_.end(); ++iter) { 141 iter != app_handlers_.end(); ++iter) {
142 iter->second->ShutdownHandler(); 142 iter->second->ShutdownHandler();
143 } 143 }
144 app_handlers_.clear(); 144 app_handlers_.clear();
145 } 145 }
146 146
147 void GCMDriver::AddAppHandler(const std::string& app_id, 147 void GCMDriver::AddAppHandler(const std::string& app_id,
148 GCMAppHandler* handler) { 148 GCMAppHandler* handler) {
149 DCHECK(!app_id.empty()); 149 DCHECK(!app_id.empty());
150 DCHECK(handler); 150 DCHECK(handler);
151 DCHECK(app_handlers_.find(app_id) == app_handlers_.end()); 151 DCHECK(app_handlers_.count(app_id) == 0);
jochen (gone - plz use gerrit) 2014/06/18 03:58:40 DCHECK_EQ
Michael van Ouwerkerk 2014/06/18 11:17:51 Done.
152 app_handlers_[app_id] = handler; 152 app_handlers_[app_id] = handler;
153 } 153 }
154 154
155 void GCMDriver::RemoveAppHandler(const std::string& app_id) { 155 void GCMDriver::RemoveAppHandler(const std::string& app_id) {
156 DCHECK(!app_id.empty()); 156 DCHECK(!app_id.empty());
157 app_handlers_.erase(app_id); 157 app_handlers_.erase(app_id);
158 } 158 }
159 159
160 GCMAppHandler* GCMDriver::GetAppHandler(const std::string& app_id) { 160 GCMAppHandler* GCMDriver::GetAppHandler(const std::string& app_id) {
161 // Look for exact match.
161 GCMAppHandlerMap::const_iterator iter = app_handlers_.find(app_id); 162 GCMAppHandlerMap::const_iterator iter = app_handlers_.find(app_id);
162 return iter == app_handlers_.end() ? &default_app_handler_ : iter->second; 163 if (iter != app_handlers_.end())
164 return iter->second;
165
166 // Ask the handlers whether they know how to handle it.
167 for (iter = app_handlers_.begin(); iter != app_handlers_.end(); ++iter) {
168 if (iter->second->CanHandle(app_id))
169 return iter->second;
170 }
171
172 return &default_app_handler_;
163 } 173 }
164 174
165 bool GCMDriver::HasRegisterCallback(const std::string& app_id) { 175 bool GCMDriver::HasRegisterCallback(const std::string& app_id) {
166 return register_callbacks_.find(app_id) != register_callbacks_.end(); 176 return register_callbacks_.find(app_id) != register_callbacks_.end();
167 } 177 }
168 178
169 void GCMDriver::ClearCallbacks() { 179 void GCMDriver::ClearCallbacks() {
170 register_callbacks_.clear(); 180 register_callbacks_.clear();
171 unregister_callbacks_.clear(); 181 unregister_callbacks_.clear();
172 send_callbacks_.clear(); 182 send_callbacks_.clear();
173 } 183 }
174 184
175 bool GCMDriver::IsAsyncOperationPending(const std::string& app_id) const { 185 bool GCMDriver::IsAsyncOperationPending(const std::string& app_id) const {
176 return register_callbacks_.find(app_id) != register_callbacks_.end() || 186 return register_callbacks_.find(app_id) != register_callbacks_.end() ||
177 unregister_callbacks_.find(app_id) != unregister_callbacks_.end(); 187 unregister_callbacks_.find(app_id) != unregister_callbacks_.end();
178 } 188 }
179 189
180 } // namespace gcm 190 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698