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

Side by Side Diff: components/gcm_driver/gcm_driver_desktop.cc

Issue 324913004: Skeleton GCMAppHandler for Push API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile Created 6 years, 6 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 "components/gcm_driver/gcm_driver_desktop.h" 5 #include "components/gcm_driver/gcm_driver_desktop.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 387
388 // Ensures that the GCM service is started when there is an interest. 388 // Ensures that the GCM service is started when there is an interest.
389 EnsureStarted(); 389 EnsureStarted();
390 } 390 }
391 391
392 void GCMDriverDesktop::RemoveAppHandler(const std::string& app_id) { 392 void GCMDriverDesktop::RemoveAppHandler(const std::string& app_id) {
393 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 393 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
394 GCMDriver::RemoveAppHandler(app_id); 394 GCMDriver::RemoveAppHandler(app_id);
395 395
396 // Stops the GCM service when no app intends to consume it. 396 // Stops the GCM service when no app intends to consume it.
397 if (app_handlers().empty()) 397 if (app_handlers().empty() && wildcard_app_handlers().empty())
398 Stop(); 398 Stop();
399 } 399 }
400 400
401 void GCMDriverDesktop::AddWildcardAppHandler(GCMWildcardAppHandler* handler) {
402 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
403 GCMDriver::AddWildcardAppHandler(handler);
404
405 // Ensures that the GCM service is started when there is an interest.
406 EnsureStarted();
407 }
408
409 void GCMDriverDesktop::RemoveWildcardAppHandler(
410 GCMWildcardAppHandler* handler) {
411 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
412 GCMDriver::RemoveWildcardAppHandler(handler);
413
414 // Stops the GCM service when no app intends to consume it.
415 if (app_handlers().empty() && wildcard_app_handlers().empty())
416 Stop();
417 }
418
401 void GCMDriverDesktop::Enable() { 419 void GCMDriverDesktop::Enable() {
402 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 420 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
403 421
404 if (gcm_enabled_) 422 if (gcm_enabled_)
405 return; 423 return;
406 gcm_enabled_ = true; 424 gcm_enabled_ = true;
407 425
408 EnsureStarted(); 426 EnsureStarted();
409 } 427 }
410 428
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 recording)); 578 recording));
561 } 579 }
562 580
563 GCMClient::Result GCMDriverDesktop::EnsureStarted() { 581 GCMClient::Result GCMDriverDesktop::EnsureStarted() {
564 DCHECK(ui_thread_->RunsTasksOnCurrentThread()); 582 DCHECK(ui_thread_->RunsTasksOnCurrentThread());
565 583
566 if (!gcm_enabled_) 584 if (!gcm_enabled_)
567 return GCMClient::GCM_DISABLED; 585 return GCMClient::GCM_DISABLED;
568 586
569 // Have any app requested the service? 587 // Have any app requested the service?
570 if (app_handlers().empty()) 588 if (app_handlers().empty() && wildcard_app_handlers().empty())
571 return GCMClient::UNKNOWN_ERROR; 589 return GCMClient::UNKNOWN_ERROR;
572 590
573 // Is the user signed in? 591 // Is the user signed in?
574 const std::string account_id = identity_provider_->GetActiveAccountId(); 592 const std::string account_id = identity_provider_->GetActiveAccountId();
575 if (account_id.empty()) 593 if (account_id.empty())
576 return GCMClient::NOT_SIGNED_IN; 594 return GCMClient::NOT_SIGNED_IN;
577 595
578 // CheckIn could be called more than once when: 596 // CheckIn could be called more than once when:
579 // 1) The password changes. 597 // 1) The password changes.
580 // 2) Register/send function calls it to ensure CheckIn is done. 598 // 2) Register/send function calls it to ensure CheckIn is done.
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; 696 LOG(WARNING) << "request_gcm_statistics_callback_ is NULL.";
679 } 697 }
680 698
681 std::string GCMDriverDesktop::SignedInUserName() const { 699 std::string GCMDriverDesktop::SignedInUserName() const {
682 if (IsStarted()) 700 if (IsStarted())
683 return identity_provider_->GetActiveUsername(); 701 return identity_provider_->GetActiveUsername();
684 return std::string(); 702 return std::string();
685 } 703 }
686 704
687 } // namespace gcm 705 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698