| 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" |
| 11 #include "base/sys_byteorder.h" | 11 #include "base/sys_byteorder.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "google_apis/gcm/base/encryptor.h" | 13 #include "google_apis/gcm/base/encryptor.h" |
| 14 #include "net/base/ip_endpoint.h" |
| 14 | 15 |
| 15 namespace gcm { | 16 namespace gcm { |
| 16 | 17 |
| 17 FakeGCMClient::FakeGCMClient( | 18 FakeGCMClient::FakeGCMClient( |
| 18 StartMode start_mode, | 19 StartMode start_mode, |
| 19 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, | 20 const scoped_refptr<base::SequencedTaskRunner>& ui_thread, |
| 20 const scoped_refptr<base::SequencedTaskRunner>& io_thread) | 21 const scoped_refptr<base::SequencedTaskRunner>& io_thread) |
| 21 : delegate_(NULL), | 22 : delegate_(NULL), |
| 22 status_(UNINITIALIZED), | 23 status_(UNINITIALIZED), |
| 23 start_mode_(start_mode), | 24 start_mode_(start_mode), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 54 status_ = STARTED; | 55 status_ = STARTED; |
| 55 base::MessageLoop::current()->PostTask( | 56 base::MessageLoop::current()->PostTask( |
| 56 FROM_HERE, | 57 FROM_HERE, |
| 57 base::Bind(&FakeGCMClient::CheckinFinished, | 58 base::Bind(&FakeGCMClient::CheckinFinished, |
| 58 weak_ptr_factory_.GetWeakPtr())); | 59 weak_ptr_factory_.GetWeakPtr())); |
| 59 } | 60 } |
| 60 | 61 |
| 61 void FakeGCMClient::Stop() { | 62 void FakeGCMClient::Stop() { |
| 62 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 63 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 63 status_ = STOPPED; | 64 status_ = STOPPED; |
| 65 delegate_->OnDisconnected(); |
| 64 } | 66 } |
| 65 | 67 |
| 66 void FakeGCMClient::CheckOut() { | 68 void FakeGCMClient::CheckOut() { |
| 67 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 69 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| 68 status_ = CHECKED_OUT; | 70 status_ = CHECKED_OUT; |
| 69 } | 71 } |
| 70 | 72 |
| 71 void FakeGCMClient::Register(const std::string& app_id, | 73 void FakeGCMClient::Register(const std::string& app_id, |
| 72 const std::vector<std::string>& sender_ids) { | 74 const std::vector<std::string>& sender_ids) { |
| 73 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 75 DCHECK(io_thread_->RunsTasksOnCurrentThread()); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 if (i > 0) | 163 if (i > 0) |
| 162 registration_id += ","; | 164 registration_id += ","; |
| 163 registration_id += normalized_sender_ids[i]; | 165 registration_id += normalized_sender_ids[i]; |
| 164 } | 166 } |
| 165 } | 167 } |
| 166 return registration_id; | 168 return registration_id; |
| 167 } | 169 } |
| 168 | 170 |
| 169 void FakeGCMClient::CheckinFinished() { | 171 void FakeGCMClient::CheckinFinished() { |
| 170 delegate_->OnGCMReady(); | 172 delegate_->OnGCMReady(); |
| 173 delegate_->OnConnected(net::IPEndPoint()); |
| 171 } | 174 } |
| 172 | 175 |
| 173 void FakeGCMClient::RegisterFinished(const std::string& app_id, | 176 void FakeGCMClient::RegisterFinished(const std::string& app_id, |
| 174 const std::string& registrion_id) { | 177 const std::string& registrion_id) { |
| 175 delegate_->OnRegisterFinished( | 178 delegate_->OnRegisterFinished( |
| 176 app_id, registrion_id, registrion_id.empty() ? SERVER_ERROR : SUCCESS); | 179 app_id, registrion_id, registrion_id.empty() ? SERVER_ERROR : SUCCESS); |
| 177 } | 180 } |
| 178 | 181 |
| 179 void FakeGCMClient::UnregisterFinished(const std::string& app_id) { | 182 void FakeGCMClient::UnregisterFinished(const std::string& app_id) { |
| 180 delegate_->OnUnregisterFinished(app_id, GCMClient::SUCCESS); | 183 delegate_->OnUnregisterFinished(app_id, GCMClient::SUCCESS); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 } | 215 } |
| 213 | 216 |
| 214 void FakeGCMClient::MessageSendError( | 217 void FakeGCMClient::MessageSendError( |
| 215 const std::string& app_id, | 218 const std::string& app_id, |
| 216 const GCMClient::SendErrorDetails& send_error_details) { | 219 const GCMClient::SendErrorDetails& send_error_details) { |
| 217 if (delegate_) | 220 if (delegate_) |
| 218 delegate_->OnMessageSendError(app_id, send_error_details); | 221 delegate_->OnMessageSendError(app_id, send_error_details); |
| 219 } | 222 } |
| 220 | 223 |
| 221 } // namespace gcm | 224 } // namespace gcm |
| OLD | NEW |