| 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/fake_gcm_client.h" | 5 #include "components/gcm_driver/fake_gcm_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/sequenced_task_runner.h" | 10 #include "base/sequenced_task_runner.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 base::Bind(&FakeGCMClient::Started, | 67 base::Bind(&FakeGCMClient::Started, |
| 68 weak_ptr_factory_.GetWeakPtr())); | 68 weak_ptr_factory_.GetWeakPtr())); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void FakeGCMClient::Stop() { | 71 void FakeGCMClient::Stop() { |
| 72 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 72 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 73 started_ = false; | 73 started_ = false; |
| 74 delegate_->OnDisconnected(); | 74 delegate_->OnDisconnected(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void FakeGCMClient::Register(const std::string& app_id, | 77 void FakeGCMClient::Register( |
| 78 const std::vector<std::string>& sender_ids) { | 78 const linked_ptr<RegistrationInfo>& registration_info) { |
| 79 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 79 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 80 | 80 |
| 81 std::string registration_id = GetRegistrationIdFromSenderIds(sender_ids); | 81 GCMRegistrationInfo* gcm_registration_info = |
| 82 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get()); |
| 83 DCHECK(gcm_registration_info); |
| 84 |
| 85 std::string registration_id = GetRegistrationIdFromSenderIds( |
| 86 gcm_registration_info->sender_ids); |
| 82 base::MessageLoop::current()->PostTask( | 87 base::MessageLoop::current()->PostTask( |
| 83 FROM_HERE, | 88 FROM_HERE, |
| 84 base::Bind(&FakeGCMClient::RegisterFinished, | 89 base::Bind(&FakeGCMClient::RegisterFinished, |
| 85 weak_ptr_factory_.GetWeakPtr(), | 90 weak_ptr_factory_.GetWeakPtr(), |
| 86 app_id, | 91 registration_info, |
| 87 registration_id)); | 92 registration_id)); |
| 88 } | 93 } |
| 89 | 94 |
| 90 void FakeGCMClient::Unregister(const std::string& app_id) { | 95 void FakeGCMClient::Unregister( |
| 96 const linked_ptr<RegistrationInfo>& registration_info) { |
| 91 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 97 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 92 | 98 |
| 93 base::MessageLoop::current()->PostTask( | 99 base::MessageLoop::current()->PostTask( |
| 94 FROM_HERE, | 100 FROM_HERE, |
| 95 base::Bind(&FakeGCMClient::UnregisterFinished, | 101 base::Bind(&FakeGCMClient::UnregisterFinished, |
| 96 weak_ptr_factory_.GetWeakPtr(), | 102 weak_ptr_factory_.GetWeakPtr(), |
| 97 app_id)); | 103 registration_info)); |
| 98 } | 104 } |
| 99 | 105 |
| 100 void FakeGCMClient::Send(const std::string& app_id, | 106 void FakeGCMClient::Send(const std::string& app_id, |
| 101 const std::string& receiver_id, | 107 const std::string& receiver_id, |
| 102 const OutgoingMessage& message) { | 108 const OutgoingMessage& message) { |
| 103 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 109 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 104 | 110 |
| 105 base::MessageLoop::current()->PostTask( | 111 base::MessageLoop::current()->PostTask( |
| 106 FROM_HERE, | 112 FROM_HERE, |
| 107 base::Bind(&FakeGCMClient::SendFinished, | 113 base::Bind(&FakeGCMClient::SendFinished, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 131 void FakeGCMClient::RemoveAccountMapping(const std::string& account_id) { | 137 void FakeGCMClient::RemoveAccountMapping(const std::string& account_id) { |
| 132 } | 138 } |
| 133 | 139 |
| 134 void FakeGCMClient::SetLastTokenFetchTime(const base::Time& time) { | 140 void FakeGCMClient::SetLastTokenFetchTime(const base::Time& time) { |
| 135 } | 141 } |
| 136 | 142 |
| 137 void FakeGCMClient::UpdateHeartbeatTimer(scoped_ptr<base::Timer> timer) { | 143 void FakeGCMClient::UpdateHeartbeatTimer(scoped_ptr<base::Timer> timer) { |
| 138 } | 144 } |
| 139 | 145 |
| 140 void FakeGCMClient::AddInstanceIDData(const std::string& app_id, | 146 void FakeGCMClient::AddInstanceIDData(const std::string& app_id, |
| 141 const std::string& instance_id_data) { | 147 const std::string& instance_id, |
| 148 const std::string& extra_data) { |
| 142 } | 149 } |
| 143 | 150 |
| 144 void FakeGCMClient::RemoveInstanceIDData(const std::string& app_id) { | 151 void FakeGCMClient::RemoveInstanceIDData(const std::string& app_id) { |
| 145 } | 152 } |
| 146 | 153 |
| 147 std::string FakeGCMClient::GetInstanceIDData(const std::string& app_id) { | 154 void FakeGCMClient::GetInstanceIDData(const std::string& app_id, |
| 148 return std::string(); | 155 std::string* instance_id, |
| 156 std::string* extra_data) { |
| 149 } | 157 } |
| 150 | 158 |
| 151 void FakeGCMClient::PerformDelayedStart() { | 159 void FakeGCMClient::PerformDelayedStart() { |
| 152 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 160 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); |
| 153 | 161 |
| 154 io_thread_->PostTask( | 162 io_thread_->PostTask( |
| 155 FROM_HERE, | 163 FROM_HERE, |
| 156 base::Bind(&FakeGCMClient::DoStart, weak_ptr_factory_.GetWeakPtr())); | 164 base::Bind(&FakeGCMClient::DoStart, weak_ptr_factory_.GetWeakPtr())); |
| 157 } | 165 } |
| 158 | 166 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 } | 205 } |
| 198 } | 206 } |
| 199 return registration_id; | 207 return registration_id; |
| 200 } | 208 } |
| 201 | 209 |
| 202 void FakeGCMClient::Started() { | 210 void FakeGCMClient::Started() { |
| 203 delegate_->OnGCMReady(std::vector<AccountMapping>(), base::Time()); | 211 delegate_->OnGCMReady(std::vector<AccountMapping>(), base::Time()); |
| 204 delegate_->OnConnected(net::IPEndPoint()); | 212 delegate_->OnConnected(net::IPEndPoint()); |
| 205 } | 213 } |
| 206 | 214 |
| 207 void FakeGCMClient::RegisterFinished(const std::string& app_id, | 215 void FakeGCMClient::RegisterFinished( |
| 208 const std::string& registrion_id) { | 216 const linked_ptr<RegistrationInfo>& registration_info, |
| 217 const std::string& registrion_id) { |
| 209 delegate_->OnRegisterFinished( | 218 delegate_->OnRegisterFinished( |
| 210 app_id, registrion_id, registrion_id.empty() ? SERVER_ERROR : SUCCESS); | 219 registration_info, |
| 220 registrion_id, |
| 221 registrion_id.empty() ? SERVER_ERROR : SUCCESS); |
| 211 } | 222 } |
| 212 | 223 |
| 213 void FakeGCMClient::UnregisterFinished(const std::string& app_id) { | 224 void FakeGCMClient::UnregisterFinished( |
| 214 delegate_->OnUnregisterFinished(app_id, GCMClient::SUCCESS); | 225 const linked_ptr<RegistrationInfo>& registration_info) { |
| 226 delegate_->OnUnregisterFinished(registration_info, GCMClient::SUCCESS); |
| 215 } | 227 } |
| 216 | 228 |
| 217 void FakeGCMClient::SendFinished(const std::string& app_id, | 229 void FakeGCMClient::SendFinished(const std::string& app_id, |
| 218 const OutgoingMessage& message) { | 230 const OutgoingMessage& message) { |
| 219 delegate_->OnSendFinished(app_id, message.id, SUCCESS); | 231 delegate_->OnSendFinished(app_id, message.id, SUCCESS); |
| 220 | 232 |
| 221 // Simulate send error if message id contains a hint. | 233 // Simulate send error if message id contains a hint. |
| 222 if (message.id.find("error") != std::string::npos) { | 234 if (message.id.find("error") != std::string::npos) { |
| 223 SendErrorDetails send_error_details; | 235 SendErrorDetails send_error_details; |
| 224 send_error_details.message_id = message.id; | 236 send_error_details.message_id = message.id; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 delegate_->OnMessageSendError(app_id, send_error_details); | 273 delegate_->OnMessageSendError(app_id, send_error_details); |
| 262 } | 274 } |
| 263 | 275 |
| 264 void FakeGCMClient::SendAcknowledgement(const std::string& app_id, | 276 void FakeGCMClient::SendAcknowledgement(const std::string& app_id, |
| 265 const std::string& message_id) { | 277 const std::string& message_id) { |
| 266 if (delegate_) | 278 if (delegate_) |
| 267 delegate_->OnSendAcknowledged(app_id, message_id); | 279 delegate_->OnSendAcknowledged(app_id, message_id); |
| 268 } | 280 } |
| 269 | 281 |
| 270 } // namespace gcm | 282 } // namespace gcm |
| OLD | NEW |