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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "components/gcm_driver/gcm_app_handler.h" | 11 #include "components/gcm_driver/gcm_app_handler.h" |
12 | 12 |
13 namespace gcm { | 13 namespace gcm { |
14 | 14 |
15 InstanceIDStore::InstanceIDStore() { | 15 namespace { |
| 16 const size_t kMaxSenders = 100; |
| 17 } // namespace |
| 18 |
| 19 InstanceIDHandler::InstanceIDHandler() { |
16 } | 20 } |
17 | 21 |
18 InstanceIDStore::~InstanceIDStore() { | 22 InstanceIDHandler::~InstanceIDHandler() { |
19 } | 23 } |
20 | 24 |
21 GCMDriver::GCMDriver() : weak_ptr_factory_(this) { | 25 GCMDriver::GCMDriver() : weak_ptr_factory_(this) { |
22 } | 26 } |
23 | 27 |
24 GCMDriver::~GCMDriver() { | 28 GCMDriver::~GCMDriver() { |
25 } | 29 } |
26 | 30 |
27 void GCMDriver::Register(const std::string& app_id, | 31 void GCMDriver::Register(const std::string& app_id, |
28 const std::vector<std::string>& sender_ids, | 32 const std::vector<std::string>& sender_ids, |
29 const RegisterCallback& callback) { | 33 const RegisterCallback& callback) { |
30 DCHECK(!app_id.empty()); | 34 DCHECK(!app_id.empty()); |
31 DCHECK(!sender_ids.empty()); | 35 DCHECK(!sender_ids.empty() && sender_ids.size() <= kMaxSenders); |
32 DCHECK(!callback.is_null()); | 36 DCHECK(!callback.is_null()); |
33 | 37 |
34 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); | 38 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); |
35 if (result != GCMClient::SUCCESS) { | 39 if (result != GCMClient::SUCCESS) { |
36 callback.Run(std::string(), result); | 40 callback.Run(std::string(), result); |
37 return; | 41 return; |
38 } | 42 } |
39 | 43 |
40 // If previous register operation is still in progress, bail out. | 44 // If previous register operation is still in progress, bail out. |
41 if (register_callbacks_.find(app_id) != register_callbacks_.end()) { | 45 if (register_callbacks_.find(app_id) != register_callbacks_.end()) { |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 GCMClient::Result result) { | 248 GCMClient::Result result) { |
245 // Invoke the original unregister callback. | 249 // Invoke the original unregister callback. |
246 unregister_callback.Run(result); | 250 unregister_callback.Run(result); |
247 | 251 |
248 // Trigger the pending registration. | 252 // Trigger the pending registration. |
249 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end()); | 253 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end()); |
250 RegisterImpl(app_id, normalized_sender_ids); | 254 RegisterImpl(app_id, normalized_sender_ids); |
251 } | 255 } |
252 | 256 |
253 } // namespace gcm | 257 } // namespace gcm |
OLD | NEW |