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 void GCMDriver::AddWildcardAppHandler(GCMWildcardAppHandler* handler) { |
| 161 DCHECK(handler); |
| 162 DCHECK(wildcard_app_handlers_.count(handler) == 0); |
| 163 wildcard_app_handlers_.insert(handler); |
| 164 } |
| 165 |
| 166 void GCMDriver::RemoveWildcardAppHandler(GCMWildcardAppHandler* handler) { |
| 167 wildcard_app_handlers_.erase(handler); |
| 168 } |
| 169 |
160 GCMAppHandler* GCMDriver::GetAppHandler(const std::string& app_id) { | 170 GCMAppHandler* GCMDriver::GetAppHandler(const std::string& app_id) { |
161 GCMAppHandlerMap::const_iterator iter = app_handlers_.find(app_id); | 171 GCMAppHandlerMap::const_iterator iter = app_handlers_.find(app_id); |
162 return iter == app_handlers_.end() ? &default_app_handler_ : iter->second; | 172 if (iter != app_handlers_.end()) |
| 173 return iter->second; |
| 174 GCMWildcardAppHandlerSet::const_iterator it = wildcard_app_handlers_.begin(); |
| 175 for (; it != wildcard_app_handlers_.end(); ++it) { |
| 176 if ((*it)->CanHandle(app_id)) |
| 177 return *it; |
| 178 } |
| 179 return &default_app_handler_; |
163 } | 180 } |
164 | 181 |
165 bool GCMDriver::HasRegisterCallback(const std::string& app_id) { | 182 bool GCMDriver::HasRegisterCallback(const std::string& app_id) { |
166 return register_callbacks_.find(app_id) != register_callbacks_.end(); | 183 return register_callbacks_.find(app_id) != register_callbacks_.end(); |
167 } | 184 } |
168 | 185 |
169 void GCMDriver::ClearCallbacks() { | 186 void GCMDriver::ClearCallbacks() { |
170 register_callbacks_.clear(); | 187 register_callbacks_.clear(); |
171 unregister_callbacks_.clear(); | 188 unregister_callbacks_.clear(); |
172 send_callbacks_.clear(); | 189 send_callbacks_.clear(); |
173 } | 190 } |
174 | 191 |
175 bool GCMDriver::IsAsyncOperationPending(const std::string& app_id) const { | 192 bool GCMDriver::IsAsyncOperationPending(const std::string& app_id) const { |
176 return register_callbacks_.find(app_id) != register_callbacks_.end() || | 193 return register_callbacks_.find(app_id) != register_callbacks_.end() || |
177 unregister_callbacks_.find(app_id) != unregister_callbacks_.end(); | 194 unregister_callbacks_.find(app_id) != unregister_callbacks_.end(); |
178 } | 195 } |
179 | 196 |
180 } // namespace gcm | 197 } // namespace gcm |
OLD | NEW |