| 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 "base/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(); ++iter) { |
| 155 DVLOG(1) << "Calling ShutdownHandler for: " << iter->first; |
| 155 iter->second->ShutdownHandler(); | 156 iter->second->ShutdownHandler(); |
| 156 } | 157 } |
| 157 app_handlers_.clear(); | 158 app_handlers_.clear(); |
| 158 } | 159 } |
| 159 | 160 |
| 160 void GCMDriver::AddAppHandler(const std::string& app_id, | 161 void GCMDriver::AddAppHandler(const std::string& app_id, |
| 161 GCMAppHandler* handler) { | 162 GCMAppHandler* handler) { |
| 162 DCHECK(!app_id.empty()); | 163 DCHECK(!app_id.empty()); |
| 163 DCHECK(handler); | 164 DCHECK(handler); |
| 164 DCHECK_EQ(app_handlers_.count(app_id), 0u); | 165 DCHECK_EQ(app_handlers_.count(app_id), 0u); |
| 165 app_handlers_[app_id] = handler; | 166 app_handlers_[app_id] = handler; |
| 167 DVLOG(1) << "App handler added for: " << app_id; |
| 166 } | 168 } |
| 167 | 169 |
| 168 void GCMDriver::RemoveAppHandler(const std::string& app_id) { | 170 void GCMDriver::RemoveAppHandler(const std::string& app_id) { |
| 169 DCHECK(!app_id.empty()); | 171 DCHECK(!app_id.empty()); |
| 170 app_handlers_.erase(app_id); | 172 app_handlers_.erase(app_id); |
| 173 DVLOG(1) << "App handler removed for: " << app_id; |
| 171 } | 174 } |
| 172 | 175 |
| 173 GCMAppHandler* GCMDriver::GetAppHandler(const std::string& app_id) { | 176 GCMAppHandler* GCMDriver::GetAppHandler(const std::string& app_id) { |
| 174 // Look for exact match. | 177 // Look for exact match. |
| 175 GCMAppHandlerMap::const_iterator iter = app_handlers_.find(app_id); | 178 GCMAppHandlerMap::const_iterator iter = app_handlers_.find(app_id); |
| 176 if (iter != app_handlers_.end()) | 179 if (iter != app_handlers_.end()) |
| 177 return iter->second; | 180 return iter->second; |
| 178 | 181 |
| 179 // Ask the handlers whether they know how to handle it. | 182 // Ask the handlers whether they know how to handle it. |
| 180 for (iter = app_handlers_.begin(); iter != app_handlers_.end(); ++iter) { | 183 for (iter = app_handlers_.begin(); iter != app_handlers_.end(); ++iter) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 194 unregister_callbacks_.clear(); | 197 unregister_callbacks_.clear(); |
| 195 send_callbacks_.clear(); | 198 send_callbacks_.clear(); |
| 196 } | 199 } |
| 197 | 200 |
| 198 bool GCMDriver::IsAsyncOperationPending(const std::string& app_id) const { | 201 bool GCMDriver::IsAsyncOperationPending(const std::string& app_id) const { |
| 199 return register_callbacks_.find(app_id) != register_callbacks_.end() || | 202 return register_callbacks_.find(app_id) != register_callbacks_.end() || |
| 200 unregister_callbacks_.find(app_id) != unregister_callbacks_.end(); | 203 unregister_callbacks_.find(app_id) != unregister_callbacks_.end(); |
| 201 } | 204 } |
| 202 | 205 |
| 203 } // namespace gcm | 206 } // namespace gcm |
| OLD | NEW |