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" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 app_id, | 62 app_id, |
63 normalized_sender_ids, | 63 normalized_sender_ids, |
64 unregister_iter->second); | 64 unregister_iter->second); |
65 return; | 65 return; |
66 } | 66 } |
67 | 67 |
68 RegisterImpl(app_id, normalized_sender_ids); | 68 RegisterImpl(app_id, normalized_sender_ids); |
69 } | 69 } |
70 | 70 |
71 void GCMDriver::Unregister(const std::string& app_id, | 71 void GCMDriver::Unregister(const std::string& app_id, |
| 72 const std::vector<std::string>& sender_ids, |
72 const UnregisterCallback& callback) { | 73 const UnregisterCallback& callback) { |
73 DCHECK(!app_id.empty()); | 74 DCHECK(!app_id.empty()); |
| 75 #if defined(OS_ANDROID) |
| 76 DCHECK(!sender_ids.empty()); |
| 77 #endif |
74 DCHECK(!callback.is_null()); | 78 DCHECK(!callback.is_null()); |
75 | 79 |
76 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); | 80 GCMClient::Result result = EnsureStarted(GCMClient::IMMEDIATE_START); |
77 if (result != GCMClient::SUCCESS) { | 81 if (result != GCMClient::SUCCESS) { |
78 callback.Run(result); | 82 callback.Run(result); |
79 return; | 83 return; |
80 } | 84 } |
81 | 85 |
82 // If previous un/register operation is still in progress, bail out. | 86 // If previous un/register operation is still in progress, bail out. |
83 if (register_callbacks_.find(app_id) != register_callbacks_.end() || | 87 if (register_callbacks_.find(app_id) != register_callbacks_.end() || |
84 unregister_callbacks_.find(app_id) != unregister_callbacks_.end()) { | 88 unregister_callbacks_.find(app_id) != unregister_callbacks_.end()) { |
85 callback.Run(GCMClient::ASYNC_OPERATION_PENDING); | 89 callback.Run(GCMClient::ASYNC_OPERATION_PENDING); |
86 return; | 90 return; |
87 } | 91 } |
88 | 92 |
| 93 // Normalize the sender IDs by making them sorted. |
| 94 std::vector<std::string> normalized_sender_ids = sender_ids; |
| 95 std::sort(normalized_sender_ids.begin(), normalized_sender_ids.end()); |
| 96 |
89 unregister_callbacks_[app_id] = callback; | 97 unregister_callbacks_[app_id] = callback; |
90 | 98 |
91 UnregisterImpl(app_id); | 99 UnregisterImpl(app_id, normalized_sender_ids); |
92 } | 100 } |
93 | 101 |
94 void GCMDriver::Send(const std::string& app_id, | 102 void GCMDriver::Send(const std::string& app_id, |
95 const std::string& receiver_id, | 103 const std::string& receiver_id, |
96 const GCMClient::OutgoingMessage& message, | 104 const GCMClient::OutgoingMessage& message, |
97 const SendCallback& callback) { | 105 const SendCallback& callback) { |
98 DCHECK(!app_id.empty()); | 106 DCHECK(!app_id.empty()); |
99 DCHECK(!receiver_id.empty()); | 107 DCHECK(!receiver_id.empty()); |
100 DCHECK(!callback.is_null()); | 108 DCHECK(!callback.is_null()); |
101 | 109 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 GCMClient::Result result) { | 224 GCMClient::Result result) { |
217 // Invoke the original unregister callback. | 225 // Invoke the original unregister callback. |
218 unregister_callback.Run(result); | 226 unregister_callback.Run(result); |
219 | 227 |
220 // Trigger the pending registration. | 228 // Trigger the pending registration. |
221 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end()); | 229 DCHECK(register_callbacks_.find(app_id) != register_callbacks_.end()); |
222 RegisterImpl(app_id, normalized_sender_ids); | 230 RegisterImpl(app_id, normalized_sender_ids); |
223 } | 231 } |
224 | 232 |
225 } // namespace gcm | 233 } // namespace gcm |
OLD | NEW |