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 "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 Loading... | |
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); |
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 iter = app_handlers_.begin(); | |
fgorski
2014/06/17 17:24:00
nit: any reason not to put it in the for header?
Michael van Ouwerkerk
2014/06/17 19:22:05
Done.
| |
168 for (; iter != app_handlers_.end(); ++iter) { | |
169 if (iter->second->CanHandle(app_id)) | |
170 return iter->second; | |
171 } | |
172 | |
173 return &default_app_handler_; | |
163 } | 174 } |
164 | 175 |
165 bool GCMDriver::HasRegisterCallback(const std::string& app_id) { | 176 bool GCMDriver::HasRegisterCallback(const std::string& app_id) { |
166 return register_callbacks_.find(app_id) != register_callbacks_.end(); | 177 return register_callbacks_.find(app_id) != register_callbacks_.end(); |
167 } | 178 } |
168 | 179 |
169 void GCMDriver::ClearCallbacks() { | 180 void GCMDriver::ClearCallbacks() { |
170 register_callbacks_.clear(); | 181 register_callbacks_.clear(); |
171 unregister_callbacks_.clear(); | 182 unregister_callbacks_.clear(); |
172 send_callbacks_.clear(); | 183 send_callbacks_.clear(); |
173 } | 184 } |
174 | 185 |
175 bool GCMDriver::IsAsyncOperationPending(const std::string& app_id) const { | 186 bool GCMDriver::IsAsyncOperationPending(const std::string& app_id) const { |
176 return register_callbacks_.find(app_id) != register_callbacks_.end() || | 187 return register_callbacks_.find(app_id) != register_callbacks_.end() || |
177 unregister_callbacks_.find(app_id) != unregister_callbacks_.end(); | 188 unregister_callbacks_.find(app_id) != unregister_callbacks_.end(); |
178 } | 189 } |
179 | 190 |
180 } // namespace gcm | 191 } // namespace gcm |
OLD | NEW |