Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: chrome/browser/services/gcm/gcm_service.cc

Issue 270873002: Extract GCMClient data types into separate gcm_types.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reupload Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/services/gcm/gcm_service.h" 5 #include "chrome/browser/services/gcm/gcm_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 class GCMService::IOWorker : public GCMClient::Delegate { 125 class GCMService::IOWorker : public GCMClient::Delegate {
126 public: 126 public:
127 // Called on UI thread. 127 // Called on UI thread.
128 IOWorker(); 128 IOWorker();
129 virtual ~IOWorker(); 129 virtual ~IOWorker();
130 130
131 // Overridden from GCMClient::Delegate: 131 // Overridden from GCMClient::Delegate:
132 // Called on IO thread. 132 // Called on IO thread.
133 virtual void OnRegisterFinished(const std::string& app_id, 133 virtual void OnRegisterFinished(const std::string& app_id,
134 const std::string& registration_id, 134 const std::string& registration_id,
135 GCMClient::Result result) OVERRIDE; 135 Result result) OVERRIDE;
136 virtual void OnUnregisterFinished(const std::string& app_id, 136 virtual void OnUnregisterFinished(const std::string& app_id,
137 GCMClient::Result result) OVERRIDE; 137 Result result) OVERRIDE;
138 virtual void OnSendFinished(const std::string& app_id, 138 virtual void OnSendFinished(const std::string& app_id,
139 const std::string& message_id, 139 const std::string& message_id,
140 GCMClient::Result result) OVERRIDE; 140 Result result) OVERRIDE;
141 virtual void OnMessageReceived( 141 virtual void OnMessageReceived(
142 const std::string& app_id, 142 const std::string& app_id,
143 const GCMClient::IncomingMessage& message) OVERRIDE; 143 const IncomingMessage& message) OVERRIDE;
144 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; 144 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE;
145 virtual void OnMessageSendError( 145 virtual void OnMessageSendError(
146 const std::string& app_id, 146 const std::string& app_id,
147 const GCMClient::SendErrorDetails& send_error_details) OVERRIDE; 147 const SendErrorDetails& send_error_details) OVERRIDE;
148 virtual void OnGCMReady() OVERRIDE; 148 virtual void OnGCMReady() OVERRIDE;
149 149
150 // Called on IO thread. 150 // Called on IO thread.
151 void Initialize(scoped_ptr<GCMClientFactory> gcm_client_factory, 151 void Initialize(scoped_ptr<GCMClientFactory> gcm_client_factory,
152 const base::FilePath& store_path, 152 const base::FilePath& store_path,
153 const std::vector<std::string>& account_ids, 153 const std::vector<std::string>& account_ids,
154 const scoped_refptr<net::URLRequestContextGetter>& 154 const scoped_refptr<net::URLRequestContextGetter>&
155 url_request_context_getter); 155 url_request_context_getter);
156 void Load(const base::WeakPtr<GCMService>& service); 156 void Load(const base::WeakPtr<GCMService>& service);
157 void Stop(); 157 void Stop();
158 void CheckOut(); 158 void CheckOut();
159 void Register(const std::string& app_id, 159 void Register(const std::string& app_id,
160 const std::vector<std::string>& sender_ids); 160 const std::vector<std::string>& sender_ids);
161 void Unregister(const std::string& app_id); 161 void Unregister(const std::string& app_id);
162 void Send(const std::string& app_id, 162 void Send(const std::string& app_id,
163 const std::string& receiver_id, 163 const std::string& receiver_id,
164 const GCMClient::OutgoingMessage& message); 164 const OutgoingMessage& message);
165 void GetGCMStatistics(bool clear_logs); 165 void GetGCMStatistics(bool clear_logs);
166 void SetGCMRecording(bool recording); 166 void SetGCMRecording(bool recording);
167 167
168 // For testing purpose. Can be called from UI thread. Use with care. 168 // For testing purpose. Can be called from UI thread. Use with care.
169 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); } 169 GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); }
170 170
171 private: 171 private:
172 base::WeakPtr<GCMService> service_; 172 base::WeakPtr<GCMService> service_;
173 173
174 scoped_ptr<GCMClient> gcm_client_; 174 scoped_ptr<GCMClient> gcm_client_;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 store_path, 210 store_path,
211 account_ids, 211 account_ids,
212 blocking_task_runner, 212 blocking_task_runner,
213 url_request_context_getter, 213 url_request_context_getter,
214 this); 214 this);
215 } 215 }
216 216
217 void GCMService::IOWorker::OnRegisterFinished( 217 void GCMService::IOWorker::OnRegisterFinished(
218 const std::string& app_id, 218 const std::string& app_id,
219 const std::string& registration_id, 219 const std::string& registration_id,
220 GCMClient::Result result) { 220 Result result) {
221 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 221 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
222 222
223 content::BrowserThread::PostTask(content::BrowserThread::UI, 223 content::BrowserThread::PostTask(content::BrowserThread::UI,
224 FROM_HERE, 224 FROM_HERE,
225 base::Bind(&GCMService::RegisterFinished, 225 base::Bind(&GCMService::RegisterFinished,
226 service_, 226 service_,
227 app_id, 227 app_id,
228 registration_id, 228 registration_id,
229 result)); 229 result));
230 } 230 }
231 231
232 void GCMService::IOWorker::OnUnregisterFinished(const std::string& app_id, 232 void GCMService::IOWorker::OnUnregisterFinished(const std::string& app_id,
233 GCMClient::Result result) { 233 Result result) {
234 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 234 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
235 235
236 content::BrowserThread::PostTask( 236 content::BrowserThread::PostTask(
237 content::BrowserThread::UI, 237 content::BrowserThread::UI,
238 FROM_HERE, 238 FROM_HERE,
239 base::Bind(&GCMService::UnregisterFinished, service_, app_id, result)); 239 base::Bind(&GCMService::UnregisterFinished, service_, app_id, result));
240 } 240 }
241 241
242 void GCMService::IOWorker::OnSendFinished(const std::string& app_id, 242 void GCMService::IOWorker::OnSendFinished(const std::string& app_id,
243 const std::string& message_id, 243 const std::string& message_id,
244 GCMClient::Result result) { 244 Result result) {
245 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 245 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
246 246
247 content::BrowserThread::PostTask(content::BrowserThread::UI, 247 content::BrowserThread::PostTask(content::BrowserThread::UI,
248 FROM_HERE, 248 FROM_HERE,
249 base::Bind(&GCMService::SendFinished, 249 base::Bind(&GCMService::SendFinished,
250 service_, 250 service_,
251 app_id, 251 app_id,
252 message_id, 252 message_id,
253 result)); 253 result));
254 } 254 }
255 255
256 void GCMService::IOWorker::OnMessageReceived( 256 void GCMService::IOWorker::OnMessageReceived(
257 const std::string& app_id, 257 const std::string& app_id,
258 const GCMClient::IncomingMessage& message) { 258 const IncomingMessage& message) {
259 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 259 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
260 260
261 content::BrowserThread::PostTask(content::BrowserThread::UI, 261 content::BrowserThread::PostTask(content::BrowserThread::UI,
262 FROM_HERE, 262 FROM_HERE,
263 base::Bind(&GCMService::MessageReceived, 263 base::Bind(&GCMService::MessageReceived,
264 service_, 264 service_,
265 app_id, 265 app_id,
266 message)); 266 message));
267 } 267 }
268 268
269 void GCMService::IOWorker::OnMessagesDeleted(const std::string& app_id) { 269 void GCMService::IOWorker::OnMessagesDeleted(const std::string& app_id) {
270 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 270 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
271 271
272 content::BrowserThread::PostTask(content::BrowserThread::UI, 272 content::BrowserThread::PostTask(content::BrowserThread::UI,
273 FROM_HERE, 273 FROM_HERE,
274 base::Bind(&GCMService::MessagesDeleted, 274 base::Bind(&GCMService::MessagesDeleted,
275 service_, 275 service_,
276 app_id)); 276 app_id));
277 } 277 }
278 278
279 void GCMService::IOWorker::OnMessageSendError( 279 void GCMService::IOWorker::OnMessageSendError(
280 const std::string& app_id, 280 const std::string& app_id,
281 const GCMClient::SendErrorDetails& send_error_details) { 281 const SendErrorDetails& send_error_details) {
282 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 282 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
283 283
284 content::BrowserThread::PostTask(content::BrowserThread::UI, 284 content::BrowserThread::PostTask(content::BrowserThread::UI,
285 FROM_HERE, 285 FROM_HERE,
286 base::Bind(&GCMService::MessageSendError, 286 base::Bind(&GCMService::MessageSendError,
287 service_, 287 service_,
288 app_id, 288 app_id,
289 send_error_details)); 289 send_error_details));
290 } 290 }
291 291
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 } 327 }
328 328
329 void GCMService::IOWorker::Unregister(const std::string& app_id) { 329 void GCMService::IOWorker::Unregister(const std::string& app_id) {
330 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 330 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
331 331
332 gcm_client_->Unregister(app_id); 332 gcm_client_->Unregister(app_id);
333 } 333 }
334 334
335 void GCMService::IOWorker::Send(const std::string& app_id, 335 void GCMService::IOWorker::Send(const std::string& app_id,
336 const std::string& receiver_id, 336 const std::string& receiver_id,
337 const GCMClient::OutgoingMessage& message) { 337 const OutgoingMessage& message) {
338 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 338 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
339 339
340 gcm_client_->Send(app_id, receiver_id, message); 340 gcm_client_->Send(app_id, receiver_id, message);
341 } 341 }
342 342
343 void GCMService::IOWorker::GetGCMStatistics(bool clear_logs) { 343 void GCMService::IOWorker::GetGCMStatistics(bool clear_logs) {
344 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 344 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
345 gcm::GCMClient::GCMStatistics stats; 345 GCMClient::GCMStatistics stats;
346 346
347 if (gcm_client_.get()) { 347 if (gcm_client_.get()) {
348 if (clear_logs) 348 if (clear_logs)
349 gcm_client_->ClearActivityLogs(); 349 gcm_client_->ClearActivityLogs();
350 stats = gcm_client_->GetStatistics(); 350 stats = gcm_client_->GetStatistics();
351 } 351 }
352 352
353 content::BrowserThread::PostTask( 353 content::BrowserThread::PostTask(
354 content::BrowserThread::UI, 354 content::BrowserThread::UI,
355 FROM_HERE, 355 FROM_HERE,
356 base::Bind(&GCMService::GetGCMStatisticsFinished, service_, stats)); 356 base::Bind(&GCMService::GetGCMStatisticsFinished, service_, stats));
357 } 357 }
358 358
359 void GCMService::IOWorker::SetGCMRecording(bool recording) { 359 void GCMService::IOWorker::SetGCMRecording(bool recording) {
360 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 360 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
361 gcm::GCMClient::GCMStatistics stats; 361 GCMClient::GCMStatistics stats;
362 362
363 if (gcm_client_.get()) { 363 if (gcm_client_.get()) {
364 gcm_client_->SetRecording(recording); 364 gcm_client_->SetRecording(recording);
365 stats = gcm_client_->GetStatistics(); 365 stats = gcm_client_->GetStatistics();
366 stats.gcm_client_created = true; 366 stats.gcm_client_created = true;
367 } 367 }
368 368
369 content::BrowserThread::PostTask( 369 content::BrowserThread::PostTask(
370 content::BrowserThread::UI, 370 content::BrowserThread::UI,
371 FROM_HERE, 371 FROM_HERE,
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 } 463 }
464 464
465 void GCMService::Register(const std::string& app_id, 465 void GCMService::Register(const std::string& app_id,
466 const std::vector<std::string>& sender_ids, 466 const std::vector<std::string>& sender_ids,
467 RegisterCallback callback) { 467 RegisterCallback callback) {
468 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 468 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
469 DCHECK(!app_id.empty()); 469 DCHECK(!app_id.empty());
470 DCHECK(!sender_ids.empty()); 470 DCHECK(!sender_ids.empty());
471 DCHECK(!callback.is_null()); 471 DCHECK(!callback.is_null());
472 472
473 GCMClient::Result result = EnsureAppReady(app_id); 473 Result result = EnsureAppReady(app_id);
474 if (result != GCMClient::SUCCESS) { 474 if (result != RESULT_SUCCESS) {
475 callback.Run(std::string(), result); 475 callback.Run(std::string(), result);
476 return; 476 return;
477 } 477 }
478 478
479 // If previous un/register operation is still in progress, bail out. 479 // If previous un/register operation is still in progress, bail out.
480 if (IsAsyncOperationPending(app_id)) { 480 if (IsAsyncOperationPending(app_id)) {
481 callback.Run(std::string(), GCMClient::ASYNC_OPERATION_PENDING); 481 callback.Run(std::string(), RESULT_ASYNC_OPERATION_PENDING);
482 return; 482 return;
483 } 483 }
484 484
485 register_callbacks_[app_id] = callback; 485 register_callbacks_[app_id] = callback;
486 486
487 // Delay the register operation until GCMClient is ready. 487 // Delay the register operation until GCMClient is ready.
488 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { 488 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
489 delayed_task_controller_->AddTask(base::Bind(&GCMService::DoRegister, 489 delayed_task_controller_->AddTask(base::Bind(&GCMService::DoRegister,
490 weak_ptr_factory_.GetWeakPtr(), 490 weak_ptr_factory_.GetWeakPtr(),
491 app_id, 491 app_id,
(...skipping 26 matching lines...) Expand all
518 app_id, 518 app_id,
519 normalized_sender_ids)); 519 normalized_sender_ids));
520 } 520 }
521 521
522 void GCMService::Unregister(const std::string& app_id, 522 void GCMService::Unregister(const std::string& app_id,
523 UnregisterCallback callback) { 523 UnregisterCallback callback) {
524 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 524 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
525 DCHECK(!app_id.empty()); 525 DCHECK(!app_id.empty());
526 DCHECK(!callback.is_null()); 526 DCHECK(!callback.is_null());
527 527
528 GCMClient::Result result = EnsureAppReady(app_id); 528 Result result = EnsureAppReady(app_id);
529 if (result != GCMClient::SUCCESS) { 529 if (result != RESULT_SUCCESS) {
530 callback.Run(result); 530 callback.Run(result);
531 return; 531 return;
532 } 532 }
533 533
534 // If previous un/register operation is still in progress, bail out. 534 // If previous un/register operation is still in progress, bail out.
535 if (IsAsyncOperationPending(app_id)) { 535 if (IsAsyncOperationPending(app_id)) {
536 callback.Run(GCMClient::ASYNC_OPERATION_PENDING); 536 callback.Run(RESULT_ASYNC_OPERATION_PENDING);
537 return; 537 return;
538 } 538 }
539 539
540 unregister_callbacks_[app_id] = callback; 540 unregister_callbacks_[app_id] = callback;
541 541
542 // Delay the unregister operation until GCMClient is ready. 542 // Delay the unregister operation until GCMClient is ready.
543 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { 543 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
544 delayed_task_controller_->AddTask(base::Bind(&GCMService::DoUnregister, 544 delayed_task_controller_->AddTask(base::Bind(&GCMService::DoUnregister,
545 weak_ptr_factory_.GetWeakPtr(), 545 weak_ptr_factory_.GetWeakPtr(),
546 app_id)); 546 app_id));
(...skipping 12 matching lines...) Expand all
559 content::BrowserThread::PostTask( 559 content::BrowserThread::PostTask(
560 content::BrowserThread::IO, 560 content::BrowserThread::IO,
561 FROM_HERE, 561 FROM_HERE,
562 base::Bind(&GCMService::IOWorker::Unregister, 562 base::Bind(&GCMService::IOWorker::Unregister,
563 base::Unretained(io_worker_.get()), 563 base::Unretained(io_worker_.get()),
564 app_id)); 564 app_id));
565 } 565 }
566 566
567 void GCMService::Send(const std::string& app_id, 567 void GCMService::Send(const std::string& app_id,
568 const std::string& receiver_id, 568 const std::string& receiver_id,
569 const GCMClient::OutgoingMessage& message, 569 const OutgoingMessage& message,
570 SendCallback callback) { 570 SendCallback callback) {
571 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 571 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
572 DCHECK(!app_id.empty()); 572 DCHECK(!app_id.empty());
573 DCHECK(!receiver_id.empty()); 573 DCHECK(!receiver_id.empty());
574 DCHECK(!callback.is_null()); 574 DCHECK(!callback.is_null());
575 575
576 GCMClient::Result result = EnsureAppReady(app_id); 576 Result result = EnsureAppReady(app_id);
577 if (result != GCMClient::SUCCESS) { 577 if (result != RESULT_SUCCESS) {
578 callback.Run(std::string(), result); 578 callback.Run(std::string(), result);
579 return; 579 return;
580 } 580 }
581 581
582 // If the message with send ID is still in progress, bail out. 582 // If the message with send ID is still in progress, bail out.
583 std::pair<std::string, std::string> key(app_id, message.id); 583 std::pair<std::string, std::string> key(app_id, message.id);
584 if (send_callbacks_.find(key) != send_callbacks_.end()) { 584 if (send_callbacks_.find(key) != send_callbacks_.end()) {
585 callback.Run(message.id, GCMClient::INVALID_PARAMETER); 585 callback.Run(message.id, RESULT_INVALID_PARAMETER);
586 return; 586 return;
587 } 587 }
588 588
589 send_callbacks_[key] = callback; 589 send_callbacks_[key] = callback;
590 590
591 // Delay the send operation until all GCMClient is ready. 591 // Delay the send operation until all GCMClient is ready.
592 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) { 592 if (!delayed_task_controller_->CanRunTaskWithoutDelay()) {
593 delayed_task_controller_->AddTask(base::Bind(&GCMService::DoSend, 593 delayed_task_controller_->AddTask(base::Bind(&GCMService::DoSend,
594 weak_ptr_factory_.GetWeakPtr(), 594 weak_ptr_factory_.GetWeakPtr(),
595 app_id, 595 app_id,
596 receiver_id, 596 receiver_id,
597 message)); 597 message));
598 return; 598 return;
599 } 599 }
600 600
601 DoSend(app_id, receiver_id, message); 601 DoSend(app_id, receiver_id, message);
602 } 602 }
603 603
604 void GCMService::DoSend(const std::string& app_id, 604 void GCMService::DoSend(const std::string& app_id,
605 const std::string& receiver_id, 605 const std::string& receiver_id,
606 const GCMClient::OutgoingMessage& message) { 606 const OutgoingMessage& message) {
607 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 607 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
608 content::BrowserThread::PostTask( 608 content::BrowserThread::PostTask(
609 content::BrowserThread::IO, 609 content::BrowserThread::IO,
610 FROM_HERE, 610 FROM_HERE,
611 base::Bind(&GCMService::IOWorker::Send, 611 base::Bind(&GCMService::IOWorker::Send,
612 base::Unretained(io_worker_.get()), 612 base::Unretained(io_worker_.get()),
613 app_id, 613 app_id,
614 receiver_id, 614 receiver_id,
615 message)); 615 message));
616 } 616 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 716
717 RemoveCachedData(); 717 RemoveCachedData();
718 718
719 content::BrowserThread::PostTask( 719 content::BrowserThread::PostTask(
720 content::BrowserThread::IO, 720 content::BrowserThread::IO,
721 FROM_HERE, 721 FROM_HERE,
722 base::Bind(&GCMService::IOWorker::CheckOut, 722 base::Bind(&GCMService::IOWorker::CheckOut,
723 base::Unretained(io_worker_.get()))); 723 base::Unretained(io_worker_.get())));
724 } 724 }
725 725
726 GCMClient::Result GCMService::EnsureAppReady(const std::string& app_id) { 726 Result GCMService::EnsureAppReady(const std::string& app_id) {
727 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 727 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
728 // Ensure that check-in has been done. 728 // Ensure that check-in has been done.
729 EnsureLoaded(); 729 EnsureLoaded();
730 730
731 // If the service was not started, bail out. 731 // If the service was not started, bail out.
732 if (account_id_.empty()) 732 if (account_id_.empty())
733 return GCMClient::NOT_SIGNED_IN; 733 return RESULT_NOT_SIGNED_IN;
734 734
735 return GCMClient::SUCCESS; 735 return RESULT_SUCCESS;
736 } 736 }
737 737
738 bool GCMService::IsAsyncOperationPending(const std::string& app_id) const { 738 bool GCMService::IsAsyncOperationPending(const std::string& app_id) const {
739 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 739 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
740 return register_callbacks_.find(app_id) != register_callbacks_.end() || 740 return register_callbacks_.find(app_id) != register_callbacks_.end() ||
741 unregister_callbacks_.find(app_id) != unregister_callbacks_.end(); 741 unregister_callbacks_.find(app_id) != unregister_callbacks_.end();
742 } 742 }
743 743
744 void GCMService::RegisterFinished(const std::string& app_id, 744 void GCMService::RegisterFinished(const std::string& app_id,
745 const std::string& registration_id, 745 const std::string& registration_id,
746 GCMClient::Result result) { 746 Result result) {
747 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 747 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
748 748
749 std::map<std::string, RegisterCallback>::iterator callback_iter = 749 std::map<std::string, RegisterCallback>::iterator callback_iter =
750 register_callbacks_.find(app_id); 750 register_callbacks_.find(app_id);
751 if (callback_iter == register_callbacks_.end()) { 751 if (callback_iter == register_callbacks_.end()) {
752 // The callback could have been removed when the app is uninstalled. 752 // The callback could have been removed when the app is uninstalled.
753 return; 753 return;
754 } 754 }
755 755
756 RegisterCallback callback = callback_iter->second; 756 RegisterCallback callback = callback_iter->second;
757 register_callbacks_.erase(callback_iter); 757 register_callbacks_.erase(callback_iter);
758 callback.Run(registration_id, result); 758 callback.Run(registration_id, result);
759 } 759 }
760 760
761 void GCMService::UnregisterFinished(const std::string& app_id, 761 void GCMService::UnregisterFinished(const std::string& app_id,
762 GCMClient::Result result) { 762 Result result) {
763 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 763 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
764 764
765 std::map<std::string, UnregisterCallback>::iterator callback_iter = 765 std::map<std::string, UnregisterCallback>::iterator callback_iter =
766 unregister_callbacks_.find(app_id); 766 unregister_callbacks_.find(app_id);
767 if (callback_iter == unregister_callbacks_.end()) 767 if (callback_iter == unregister_callbacks_.end())
768 return; 768 return;
769 769
770 UnregisterCallback callback = callback_iter->second; 770 UnregisterCallback callback = callback_iter->second;
771 unregister_callbacks_.erase(callback_iter); 771 unregister_callbacks_.erase(callback_iter);
772 callback.Run(result); 772 callback.Run(result);
773 } 773 }
774 774
775 void GCMService::SendFinished(const std::string& app_id, 775 void GCMService::SendFinished(const std::string& app_id,
776 const std::string& message_id, 776 const std::string& message_id,
777 GCMClient::Result result) { 777 Result result) {
778 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 778 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
779 779
780 std::map<std::pair<std::string, std::string>, SendCallback>::iterator 780 std::map<std::pair<std::string, std::string>, SendCallback>::iterator
781 callback_iter = send_callbacks_.find( 781 callback_iter = send_callbacks_.find(
782 std::pair<std::string, std::string>(app_id, message_id)); 782 std::pair<std::string, std::string>(app_id, message_id));
783 if (callback_iter == send_callbacks_.end()) { 783 if (callback_iter == send_callbacks_.end()) {
784 // The callback could have been removed when the app is uninstalled. 784 // The callback could have been removed when the app is uninstalled.
785 return; 785 return;
786 } 786 }
787 787
788 SendCallback callback = callback_iter->second; 788 SendCallback callback = callback_iter->second;
789 send_callbacks_.erase(callback_iter); 789 send_callbacks_.erase(callback_iter);
790 callback.Run(message_id, result); 790 callback.Run(message_id, result);
791 } 791 }
792 792
793 void GCMService::MessageReceived(const std::string& app_id, 793 void GCMService::MessageReceived(const std::string& app_id,
794 GCMClient::IncomingMessage message) { 794 IncomingMessage message) {
795 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 795 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
796 796
797 // Drop the event if signed out. 797 // Drop the event if signed out.
798 if (account_id_.empty()) 798 if (account_id_.empty())
799 return; 799 return;
800 800
801 GetAppHandler(app_id)->OnMessage(app_id, message); 801 GetAppHandler(app_id)->OnMessage(app_id, message);
802 } 802 }
803 803
804 void GCMService::MessagesDeleted(const std::string& app_id) { 804 void GCMService::MessagesDeleted(const std::string& app_id) {
805 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 805 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
806 806
807 // Drop the event if signed out. 807 // Drop the event if signed out.
808 if (account_id_.empty()) 808 if (account_id_.empty())
809 return; 809 return;
810 810
811 GetAppHandler(app_id)->OnMessagesDeleted(app_id); 811 GetAppHandler(app_id)->OnMessagesDeleted(app_id);
812 } 812 }
813 813
814 void GCMService::MessageSendError( 814 void GCMService::MessageSendError(
815 const std::string& app_id, 815 const std::string& app_id,
816 const GCMClient::SendErrorDetails& send_error_details) { 816 const SendErrorDetails& send_error_details) {
817 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 817 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
818 818
819 // Drop the event if signed out. 819 // Drop the event if signed out.
820 if (account_id_.empty()) 820 if (account_id_.empty())
821 return; 821 return;
822 822
823 GetAppHandler(app_id)->OnSendError(app_id, send_error_details); 823 GetAppHandler(app_id)->OnSendError(app_id, send_error_details);
824 } 824 }
825 825
826 void GCMService::GCMClientReady() { 826 void GCMService::GCMClientReady() {
(...skipping 14 matching lines...) Expand all
841 return iter == app_handlers_.end() ? &default_app_handler_ : iter->second; 841 return iter == app_handlers_.end() ? &default_app_handler_ : iter->second;
842 } 842 }
843 843
844 void GCMService::GetGCMStatisticsFinished( 844 void GCMService::GetGCMStatisticsFinished(
845 GCMClient::GCMStatistics stats) { 845 GCMClient::GCMStatistics stats) {
846 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 846 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
847 request_gcm_statistics_callback_.Run(stats); 847 request_gcm_statistics_callback_.Run(stats);
848 } 848 }
849 849
850 } // namespace gcm 850 } // namespace gcm
OLDNEW
« no previous file with comments | « chrome/browser/services/gcm/gcm_service.h ('k') | chrome/browser/services/gcm/gcm_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698