| 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 "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #if !defined(OS_ANDROID) |
| 13 #include "chrome/browser/extensions/api/gcm/gcm_api.h" |
| 14 #endif |
| 12 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_system.h" | 16 #include "chrome/browser/extensions/extension_system.h" |
| 14 #include "chrome/browser/extensions/state_store.h" | 17 #include "chrome/browser/extensions/state_store.h" |
| 15 #include "chrome/browser/services/gcm/gcm_client_factory.h" | 18 #include "chrome/browser/services/gcm/gcm_client_factory.h" |
| 16 #include "chrome/browser/services/gcm/gcm_event_router.h" | 19 #include "chrome/browser/services/gcm/gcm_event_router.h" |
| 17 #include "chrome/browser/signin/signin_manager.h" | 20 #include "chrome/browser/signin/signin_manager.h" |
| 18 #include "chrome/browser/signin/signin_manager_factory.h" | 21 #include "chrome/browser/signin/signin_manager_factory.h" |
| 19 #include "chrome/common/chrome_version_info.h" | 22 #include "chrome/common/chrome_version_info.h" |
| 20 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 21 #include "components/user_prefs/pref_registry_syncable.h" | 24 #include "components/user_prefs/pref_registry_syncable.h" |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 base::Bind(&GCMProfileService::IOWorker::RemoveUser, | 482 base::Bind(&GCMProfileService::IOWorker::RemoveUser, |
| 480 io_worker_)); | 483 io_worker_)); |
| 481 } | 484 } |
| 482 | 485 |
| 483 void GCMProfileService::Initialize() { | 486 void GCMProfileService::Initialize() { |
| 484 delayed_task_controller_.reset(new DelayedTaskController); | 487 delayed_task_controller_.reset(new DelayedTaskController); |
| 485 | 488 |
| 486 // This has to be done first since CheckIn depends on it. | 489 // This has to be done first since CheckIn depends on it. |
| 487 io_worker_ = new IOWorker(weak_ptr_factory_.GetWeakPtr()); | 490 io_worker_ = new IOWorker(weak_ptr_factory_.GetWeakPtr()); |
| 488 | 491 |
| 492 #if !defined(OS_ANDROID) |
| 493 js_event_router_.reset(new extensions::GcmJsEventRouter(profile_)); |
| 494 #endif |
| 495 |
| 489 // This initializes GCMClient and also does the check to find out if GCMClient | 496 // This initializes GCMClient and also does the check to find out if GCMClient |
| 490 // has finished the loading. | 497 // has finished the loading. |
| 491 content::BrowserThread::PostTask( | 498 content::BrowserThread::PostTask( |
| 492 content::BrowserThread::IO, | 499 content::BrowserThread::IO, |
| 493 FROM_HERE, | 500 FROM_HERE, |
| 494 base::Bind(&GCMProfileService::IOWorker::Initialize, io_worker_)); | 501 base::Bind(&GCMProfileService::IOWorker::Initialize, io_worker_)); |
| 495 | 502 |
| 496 // In case that the profile has been signed in before GCMProfileService is | 503 // In case that the profile has been signed in before GCMProfileService is |
| 497 // created. | 504 // created. |
| 498 SigninManagerBase* manager = SigninManagerFactory::GetForProfile(profile_); | 505 SigninManagerBase* manager = SigninManagerFactory::GetForProfile(profile_); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 void GCMProfileService::GCMClientLoadingFinished() { | 922 void GCMProfileService::GCMClientLoadingFinished() { |
| 916 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 923 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 917 | 924 |
| 918 if (gcm_client_ready_) | 925 if (gcm_client_ready_) |
| 919 return; | 926 return; |
| 920 gcm_client_ready_ = true; | 927 gcm_client_ready_ = true; |
| 921 | 928 |
| 922 DoCheckIn(); | 929 DoCheckIn(); |
| 923 } | 930 } |
| 924 | 931 |
| 925 GCMEventRouter* GCMProfileService::GetEventRouter(const std::string& app_id) { | 932 GCMEventRouter* GCMProfileService::GetEventRouter(const std::string& app_id) |
| 933 const { |
| 926 if (testing_delegate_ && testing_delegate_->GetEventRouter()) | 934 if (testing_delegate_ && testing_delegate_->GetEventRouter()) |
| 927 return testing_delegate_->GetEventRouter(); | 935 return testing_delegate_->GetEventRouter(); |
| 928 // TODO(fgorski): check and create the event router for JS routing. | 936 #if defined(OS_ANDROID) |
| 937 return NULL; |
| 938 #else |
| 929 return js_event_router_.get(); | 939 return js_event_router_.get(); |
| 940 #endif |
| 930 } | 941 } |
| 931 | 942 |
| 932 void GCMProfileService::DeleteRegistrationInfo(const std::string& app_id) { | 943 void GCMProfileService::DeleteRegistrationInfo(const std::string& app_id) { |
| 933 extensions::StateStore* storage = | 944 extensions::StateStore* storage = |
| 934 extensions::ExtensionSystem::Get(profile_)->state_store(); | 945 extensions::ExtensionSystem::Get(profile_)->state_store(); |
| 935 DCHECK(storage); | 946 DCHECK(storage); |
| 936 | 947 |
| 937 storage->RemoveExtensionValue(app_id, kRegistrationKey); | 948 storage->RemoveExtensionValue(app_id, kRegistrationKey); |
| 938 } | 949 } |
| 939 | 950 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 | 1030 |
| 1020 return true; | 1031 return true; |
| 1021 } | 1032 } |
| 1022 | 1033 |
| 1023 // static | 1034 // static |
| 1024 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() { | 1035 const char* GCMProfileService::GetPersistentRegisterKeyForTesting() { |
| 1025 return kRegistrationKey; | 1036 return kRegistrationKey; |
| 1026 } | 1037 } |
| 1027 | 1038 |
| 1028 } // namespace gcm | 1039 } // namespace gcm |
| OLD | NEW |