| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_profile_service.h" | 5 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base64.h" | 10 #include "base/base64.h" |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, | 529 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, |
| 530 content::Source<Profile>(profile_)); | 530 content::Source<Profile>(profile_)); |
| 531 registrar_.Add(this, | 531 registrar_.Add(this, |
| 532 chrome::NOTIFICATION_PROFILE_DESTROYED, | 532 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 533 content::Source<Profile>(profile_)); | 533 content::Source<Profile>(profile_)); |
| 534 // TODO(jianli): move extension specific logic out of GCMProfileService. | 534 // TODO(jianli): move extension specific logic out of GCMProfileService. |
| 535 registrar_.Add(this, | 535 registrar_.Add(this, |
| 536 chrome:: NOTIFICATION_EXTENSION_UNINSTALLED, | 536 chrome:: NOTIFICATION_EXTENSION_UNINSTALLED, |
| 537 content::Source<Profile>(profile_)); | 537 content::Source<Profile>(profile_)); |
| 538 | 538 |
| 539 #if !defined(OS_ANDROID) |
| 540 js_event_router_.reset(new extensions::GcmJsEventRouter(profile_)); |
| 541 #endif |
| 542 |
| 539 // Get the list of available accounts. | 543 // Get the list of available accounts. |
| 540 std::vector<std::string> account_ids; | 544 std::vector<std::string> account_ids; |
| 541 #if !defined(OS_ANDROID) | 545 #if !defined(OS_ANDROID) |
| 542 account_ids = | 546 account_ids = |
| 543 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->GetAccounts(); | 547 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->GetAccounts(); |
| 544 #endif | 548 #endif |
| 545 | 549 |
| 546 // Create and initialize the GCMClient. Note that this does not initiate the | 550 // Create and initialize the GCMClient. Note that this does not initiate the |
| 547 // GCM check-in. | 551 // GCM check-in. |
| 548 io_worker_ = new IOWorker(); | 552 io_worker_ = new IOWorker(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 578 return; | 582 return; |
| 579 | 583 |
| 580 RemoveCachedData(); | 584 RemoveCachedData(); |
| 581 | 585 |
| 582 content::BrowserThread::PostTask( | 586 content::BrowserThread::PostTask( |
| 583 content::BrowserThread::IO, | 587 content::BrowserThread::IO, |
| 584 FROM_HERE, | 588 FROM_HERE, |
| 585 base::Bind(&GCMProfileService::IOWorker::Stop, io_worker_)); | 589 base::Bind(&GCMProfileService::IOWorker::Stop, io_worker_)); |
| 586 } | 590 } |
| 587 | 591 |
| 592 void GCMProfileService::Shutdown() { |
| 593 #if !defined(OS_ANDROID) |
| 594 js_event_router_.reset(); |
| 595 #endif |
| 596 } |
| 597 |
| 588 void GCMProfileService::Register(const std::string& app_id, | 598 void GCMProfileService::Register(const std::string& app_id, |
| 589 const std::vector<std::string>& sender_ids, | 599 const std::vector<std::string>& sender_ids, |
| 590 RegisterCallback callback) { | 600 RegisterCallback callback) { |
| 591 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 601 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 592 DCHECK(!app_id.empty() && !sender_ids.empty() && !callback.is_null()); | 602 DCHECK(!app_id.empty() && !sender_ids.empty() && !callback.is_null()); |
| 593 | 603 |
| 594 // Ensure that check-in has been done. | 604 // Ensure that check-in has been done. |
| 595 EnsureLoaded(); | 605 EnsureLoaded(); |
| 596 | 606 |
| 597 // If the profile was not signed in, bail out. | 607 // If the profile was not signed in, bail out. |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 764 if (username.empty()) | 774 if (username.empty()) |
| 765 return; | 775 return; |
| 766 | 776 |
| 767 // CheckIn could be called more than once when: | 777 // CheckIn could be called more than once when: |
| 768 // 1) The password changes. | 778 // 1) The password changes. |
| 769 // 2) Register/send function calls it to ensure CheckIn is done. | 779 // 2) Register/send function calls it to ensure CheckIn is done. |
| 770 if (username_ == username) | 780 if (username_ == username) |
| 771 return; | 781 return; |
| 772 username_ = username; | 782 username_ = username; |
| 773 | 783 |
| 774 #if !defined(OS_ANDROID) | |
| 775 if (!js_event_router_) | |
| 776 js_event_router_.reset(new extensions::GcmJsEventRouter(profile_)); | |
| 777 #endif | |
| 778 | |
| 779 DCHECK(!delayed_task_controller_); | 784 DCHECK(!delayed_task_controller_); |
| 780 delayed_task_controller_.reset(new DelayedTaskController); | 785 delayed_task_controller_.reset(new DelayedTaskController); |
| 781 | 786 |
| 782 // Load all the registered apps. | 787 // Load all the registered apps. |
| 783 ReadRegisteredAppIDs(); | 788 ReadRegisteredAppIDs(); |
| 784 | 789 |
| 785 // This will load the data from the gcm store and trigger the check-in if | 790 // This will load the data from the gcm store and trigger the check-in if |
| 786 // the persisted check-in info is not found. | 791 // the persisted check-in info is not found. |
| 787 // Note that we need to pass weak pointer again since the existing weak | 792 // Note that we need to pass weak pointer again since the existing weak |
| 788 // pointer in IOWorker might have been invalidated when check-out occurs. | 793 // pointer in IOWorker might have been invalidated when check-out occurs. |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 | 1106 |
| 1102 return true; | 1107 return true; |
| 1103 } | 1108 } |
| 1104 | 1109 |
| 1105 // static | 1110 // static |
| 1106 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() { | 1111 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() { |
| 1107 return kRegistrationKey; | 1112 return kRegistrationKey; |
| 1108 } | 1113 } |
| 1109 | 1114 |
| 1110 } // namespace gcm | 1115 } // namespace gcm |
| OLD | NEW |