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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 const scoped_refptr<net::URLRequestContextGetter>& | 79 const scoped_refptr<net::URLRequestContextGetter>& |
80 url_request_context_getter, | 80 url_request_context_getter, |
81 std::unique_ptr<Encryptor> encryptor, | 81 std::unique_ptr<Encryptor> encryptor, |
82 Delegate* delegate) { | 82 Delegate* delegate) { |
83 product_category_for_subtypes_ = | 83 product_category_for_subtypes_ = |
84 chrome_build_info.product_category_for_subtypes; | 84 chrome_build_info.product_category_for_subtypes; |
85 delegate_ = delegate; | 85 delegate_ = delegate; |
86 } | 86 } |
87 | 87 |
88 void FakeGCMClient::Start(StartMode start_mode) { | 88 void FakeGCMClient::Start(StartMode start_mode) { |
89 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 89 DCHECK(io_thread_->RunsTasksInCurrentSequence()); |
90 | 90 |
91 if (started_) | 91 if (started_) |
92 return; | 92 return; |
93 | 93 |
94 if (start_mode == IMMEDIATE_START) | 94 if (start_mode == IMMEDIATE_START) |
95 start_mode_ = IMMEDIATE_START; | 95 start_mode_ = IMMEDIATE_START; |
96 if (start_mode_ == DELAYED_START || | 96 if (start_mode_ == DELAYED_START || |
97 start_mode_overridding_ == FORCE_TO_ALWAYS_DELAY_START_GCM) { | 97 start_mode_overridding_ == FORCE_TO_ALWAYS_DELAY_START_GCM) { |
98 return; | 98 return; |
99 } | 99 } |
100 | 100 |
101 DoStart(); | 101 DoStart(); |
102 } | 102 } |
103 | 103 |
104 void FakeGCMClient::DoStart() { | 104 void FakeGCMClient::DoStart() { |
105 started_ = true; | 105 started_ = true; |
106 base::ThreadTaskRunnerHandle::Get()->PostTask( | 106 base::ThreadTaskRunnerHandle::Get()->PostTask( |
107 FROM_HERE, | 107 FROM_HERE, |
108 base::Bind(&FakeGCMClient::Started, weak_ptr_factory_.GetWeakPtr())); | 108 base::Bind(&FakeGCMClient::Started, weak_ptr_factory_.GetWeakPtr())); |
109 } | 109 } |
110 | 110 |
111 void FakeGCMClient::Stop() { | 111 void FakeGCMClient::Stop() { |
112 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 112 DCHECK(io_thread_->RunsTasksInCurrentSequence()); |
113 started_ = false; | 113 started_ = false; |
114 delegate_->OnDisconnected(); | 114 delegate_->OnDisconnected(); |
115 } | 115 } |
116 | 116 |
117 void FakeGCMClient::Register( | 117 void FakeGCMClient::Register( |
118 const linked_ptr<RegistrationInfo>& registration_info) { | 118 const linked_ptr<RegistrationInfo>& registration_info) { |
119 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 119 DCHECK(io_thread_->RunsTasksInCurrentSequence()); |
120 | 120 |
121 std::string registration_id; | 121 std::string registration_id; |
122 | 122 |
123 GCMRegistrationInfo* gcm_registration_info = | 123 GCMRegistrationInfo* gcm_registration_info = |
124 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get()); | 124 GCMRegistrationInfo::FromRegistrationInfo(registration_info.get()); |
125 if (gcm_registration_info) { | 125 if (gcm_registration_info) { |
126 registration_id = GenerateGCMRegistrationID( | 126 registration_id = GenerateGCMRegistrationID( |
127 gcm_registration_info->sender_ids); | 127 gcm_registration_info->sender_ids); |
128 } | 128 } |
129 | 129 |
(...skipping 12 matching lines...) Expand all Loading... |
142 } | 142 } |
143 | 143 |
144 bool FakeGCMClient::ValidateRegistration( | 144 bool FakeGCMClient::ValidateRegistration( |
145 const linked_ptr<RegistrationInfo>& registration_info, | 145 const linked_ptr<RegistrationInfo>& registration_info, |
146 const std::string& registration_id) { | 146 const std::string& registration_id) { |
147 return true; | 147 return true; |
148 } | 148 } |
149 | 149 |
150 void FakeGCMClient::Unregister( | 150 void FakeGCMClient::Unregister( |
151 const linked_ptr<RegistrationInfo>& registration_info) { | 151 const linked_ptr<RegistrationInfo>& registration_info) { |
152 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 152 DCHECK(io_thread_->RunsTasksInCurrentSequence()); |
153 | 153 |
154 base::ThreadTaskRunnerHandle::Get()->PostTask( | 154 base::ThreadTaskRunnerHandle::Get()->PostTask( |
155 FROM_HERE, base::Bind(&FakeGCMClient::UnregisterFinished, | 155 FROM_HERE, base::Bind(&FakeGCMClient::UnregisterFinished, |
156 weak_ptr_factory_.GetWeakPtr(), registration_info)); | 156 weak_ptr_factory_.GetWeakPtr(), registration_info)); |
157 } | 157 } |
158 | 158 |
159 void FakeGCMClient::Send(const std::string& app_id, | 159 void FakeGCMClient::Send(const std::string& app_id, |
160 const std::string& receiver_id, | 160 const std::string& receiver_id, |
161 const OutgoingMessage& message) { | 161 const OutgoingMessage& message) { |
162 DCHECK(io_thread_->RunsTasksOnCurrentThread()); | 162 DCHECK(io_thread_->RunsTasksInCurrentSequence()); |
163 | 163 |
164 base::ThreadTaskRunnerHandle::Get()->PostTask( | 164 base::ThreadTaskRunnerHandle::Get()->PostTask( |
165 FROM_HERE, base::Bind(&FakeGCMClient::SendFinished, | 165 FROM_HERE, base::Bind(&FakeGCMClient::SendFinished, |
166 weak_ptr_factory_.GetWeakPtr(), app_id, message)); | 166 weak_ptr_factory_.GetWeakPtr(), app_id, message)); |
167 } | 167 } |
168 | 168 |
169 void FakeGCMClient::RecordDecryptionFailure( | 169 void FakeGCMClient::RecordDecryptionFailure( |
170 const std::string& app_id, | 170 const std::string& app_id, |
171 GCMEncryptionProvider::DecryptionResult result) { | 171 GCMEncryptionProvider::DecryptionResult result) { |
172 recorder_.RecordDecryptionFailure(app_id, result); | 172 recorder_.RecordDecryptionFailure(app_id, result); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 229 } |
230 | 230 |
231 void FakeGCMClient::AddHeartbeatInterval(const std::string& scope, | 231 void FakeGCMClient::AddHeartbeatInterval(const std::string& scope, |
232 int interval_ms) { | 232 int interval_ms) { |
233 } | 233 } |
234 | 234 |
235 void FakeGCMClient::RemoveHeartbeatInterval(const std::string& scope) { | 235 void FakeGCMClient::RemoveHeartbeatInterval(const std::string& scope) { |
236 } | 236 } |
237 | 237 |
238 void FakeGCMClient::PerformDelayedStart() { | 238 void FakeGCMClient::PerformDelayedStart() { |
239 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 239 DCHECK(ui_thread_->RunsTasksInCurrentSequence()); |
240 | 240 |
241 io_thread_->PostTask( | 241 io_thread_->PostTask( |
242 FROM_HERE, | 242 FROM_HERE, |
243 base::Bind(&FakeGCMClient::DoStart, weak_ptr_factory_.GetWeakPtr())); | 243 base::Bind(&FakeGCMClient::DoStart, weak_ptr_factory_.GetWeakPtr())); |
244 } | 244 } |
245 | 245 |
246 void FakeGCMClient::ReceiveMessage(const std::string& app_id, | 246 void FakeGCMClient::ReceiveMessage(const std::string& app_id, |
247 const IncomingMessage& message) { | 247 const IncomingMessage& message) { |
248 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 248 DCHECK(ui_thread_->RunsTasksInCurrentSequence()); |
249 | 249 |
250 io_thread_->PostTask( | 250 io_thread_->PostTask( |
251 FROM_HERE, | 251 FROM_HERE, |
252 base::Bind(&FakeGCMClient::MessageReceived, | 252 base::Bind(&FakeGCMClient::MessageReceived, |
253 weak_ptr_factory_.GetWeakPtr(), | 253 weak_ptr_factory_.GetWeakPtr(), |
254 app_id, | 254 app_id, |
255 message)); | 255 message)); |
256 } | 256 } |
257 | 257 |
258 void FakeGCMClient::DeleteMessages(const std::string& app_id) { | 258 void FakeGCMClient::DeleteMessages(const std::string& app_id) { |
259 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); | 259 DCHECK(ui_thread_->RunsTasksInCurrentSequence()); |
260 | 260 |
261 io_thread_->PostTask( | 261 io_thread_->PostTask( |
262 FROM_HERE, | 262 FROM_HERE, |
263 base::Bind(&FakeGCMClient::MessagesDeleted, | 263 base::Bind(&FakeGCMClient::MessagesDeleted, |
264 weak_ptr_factory_.GetWeakPtr(), | 264 weak_ptr_factory_.GetWeakPtr(), |
265 app_id)); | 265 app_id)); |
266 } | 266 } |
267 | 267 |
268 void FakeGCMClient::Started() { | 268 void FakeGCMClient::Started() { |
269 delegate_->OnGCMReady(std::vector<AccountMapping>(), base::Time()); | 269 delegate_->OnGCMReady(std::vector<AccountMapping>(), base::Time()); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 delegate_->OnMessageSendError(app_id, send_error_details); | 326 delegate_->OnMessageSendError(app_id, send_error_details); |
327 } | 327 } |
328 | 328 |
329 void FakeGCMClient::SendAcknowledgement(const std::string& app_id, | 329 void FakeGCMClient::SendAcknowledgement(const std::string& app_id, |
330 const std::string& message_id) { | 330 const std::string& message_id) { |
331 if (delegate_) | 331 if (delegate_) |
332 delegate_->OnSendAcknowledged(app_id, message_id); | 332 delegate_->OnSendAcknowledged(app_id, message_id); |
333 } | 333 } |
334 | 334 |
335 } // namespace gcm | 335 } // namespace gcm |
OLD | NEW |