| 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/files/file_path.h" | |
| 8 #include "base/logging.h" | 7 #include "base/logging.h" |
| 9 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 10 #include "base/values.h" | 9 #include "base/values.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/common/pref_names.h" |
| 12 #include "components/pref_registry/pref_registry_syncable.h" |
| 13 |
| 14 #if defined(OS_ANDROID) |
| 15 #include "components/gcm_driver/gcm_driver_android.h" |
| 16 #else |
| 17 #include "base/files/file_path.h" |
| 12 #include "chrome/browser/services/gcm/gcm_utils.h" | 18 #include "chrome/browser/services/gcm/gcm_utils.h" |
| 13 #include "chrome/browser/signin/profile_identity_provider.h" | 19 #include "chrome/browser/signin/profile_identity_provider.h" |
| 14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 15 #include "chrome/browser/signin/signin_manager_factory.h" | 21 #include "chrome/browser/signin/signin_manager_factory.h" |
| 22 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 16 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
| 17 #include "chrome/common/pref_names.h" | |
| 18 #include "components/gcm_driver/gcm_client_factory.h" | 24 #include "components/gcm_driver/gcm_client_factory.h" |
| 19 #include "components/gcm_driver/gcm_driver.h" | 25 #include "components/gcm_driver/gcm_driver_desktop.h" |
| 20 #include "components/pref_registry/pref_registry_syncable.h" | |
| 21 #include "components/signin/core/browser/signin_manager.h" | 26 #include "components/signin/core/browser/signin_manager.h" |
| 22 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 23 #include "google_apis/gaia/identity_provider.h" | 28 #include "google_apis/gaia/identity_provider.h" |
| 24 #include "net/url_request/url_request_context_getter.h" | 29 #include "net/url_request/url_request_context_getter.h" |
| 25 | |
| 26 #if !defined(OS_ANDROID) | |
| 27 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | |
| 28 #endif | 30 #endif |
| 29 | 31 |
| 30 namespace gcm { | 32 namespace gcm { |
| 31 | 33 |
| 32 // static | 34 // static |
| 33 GCMProfileService::GCMEnabledState GCMProfileService::GetGCMEnabledState( | 35 GCMProfileService::GCMEnabledState GCMProfileService::GetGCMEnabledState( |
| 34 Profile* profile) { | 36 Profile* profile) { |
| 35 const base::Value* gcm_enabled_value = | 37 const base::Value* gcm_enabled_value = |
| 36 profile->GetPrefs()->GetUserPrefValue(prefs::kGCMChannelEnabled); | 38 profile->GetPrefs()->GetUserPrefValue(prefs::kGCMChannelEnabled); |
| 37 if (!gcm_enabled_value) | 39 if (!gcm_enabled_value) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 67 true, | 69 true, |
| 68 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 70 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 69 } | 71 } |
| 70 | 72 |
| 71 GCMProfileService::GCMProfileService( | 73 GCMProfileService::GCMProfileService( |
| 72 Profile* profile, | 74 Profile* profile, |
| 73 scoped_ptr<GCMClientFactory> gcm_client_factory) | 75 scoped_ptr<GCMClientFactory> gcm_client_factory) |
| 74 : profile_(profile) { | 76 : profile_(profile) { |
| 75 DCHECK(!profile->IsOffTheRecord()); | 77 DCHECK(!profile->IsOffTheRecord()); |
| 76 | 78 |
| 79 #if defined(OS_ANDROID) |
| 80 driver_.reset(new GCMDriverAndroid()); |
| 81 #else |
| 82 LoginUIService* login_ui_service = |
| 83 LoginUIServiceFactory::GetForProfile(profile_); |
| 77 scoped_refptr<base::SequencedWorkerPool> worker_pool( | 84 scoped_refptr<base::SequencedWorkerPool> worker_pool( |
| 78 content::BrowserThread::GetBlockingPool()); | 85 content::BrowserThread::GetBlockingPool()); |
| 79 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( | 86 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( |
| 80 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( | 87 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| 81 worker_pool->GetSequenceToken(), | 88 worker_pool->GetSequenceToken(), |
| 82 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | 89 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
| 83 | 90 driver_.reset(new GCMDriverDesktop( |
| 84 #if defined(OS_ANDROID) | |
| 85 LoginUIService* login_ui_service = NULL; | |
| 86 #else | |
| 87 LoginUIService* login_ui_service = | |
| 88 LoginUIServiceFactory::GetForProfile(profile_); | |
| 89 #endif | |
| 90 driver_.reset(new GCMDriver( | |
| 91 gcm_client_factory.Pass(), | 91 gcm_client_factory.Pass(), |
| 92 scoped_ptr<IdentityProvider>(new ProfileIdentityProvider( | 92 scoped_ptr<IdentityProvider>(new ProfileIdentityProvider( |
| 93 SigninManagerFactory::GetForProfile(profile_), | 93 SigninManagerFactory::GetForProfile(profile_), |
| 94 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), | 94 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_), |
| 95 login_ui_service)), | 95 login_ui_service)), |
| 96 GetChromeBuildInfo(), | 96 GetChromeBuildInfo(), |
| 97 profile_->GetPath().Append(chrome::kGCMStoreDirname), | 97 profile_->GetPath().Append(chrome::kGCMStoreDirname), |
| 98 profile_->GetRequestContext(), | 98 profile_->GetRequestContext(), |
| 99 content::BrowserThread::GetMessageLoopProxyForThread( | 99 content::BrowserThread::GetMessageLoopProxyForThread( |
| 100 content::BrowserThread::UI), | 100 content::BrowserThread::UI), |
| 101 content::BrowserThread::GetMessageLoopProxyForThread( | 101 content::BrowserThread::GetMessageLoopProxyForThread( |
| 102 content::BrowserThread::IO), | 102 content::BrowserThread::IO), |
| 103 blocking_task_runner)); | 103 blocking_task_runner)); |
| 104 #endif |
| 104 } | 105 } |
| 105 | 106 |
| 106 GCMProfileService::GCMProfileService() : profile_(NULL) { | 107 GCMProfileService::GCMProfileService() : profile_(NULL) { |
| 107 } | 108 } |
| 108 | 109 |
| 109 GCMProfileService::~GCMProfileService() { | 110 GCMProfileService::~GCMProfileService() { |
| 110 } | 111 } |
| 111 | 112 |
| 112 void GCMProfileService::AddAppHandler(const std::string& app_id, | 113 void GCMProfileService::AddAppHandler(const std::string& app_id, |
| 113 GCMAppHandler* handler) { | 114 GCMAppHandler* handler) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 132 driver_->Shutdown(); | 133 driver_->Shutdown(); |
| 133 driver_.reset(); | 134 driver_.reset(); |
| 134 } | 135 } |
| 135 } | 136 } |
| 136 | 137 |
| 137 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { | 138 void GCMProfileService::SetDriverForTesting(GCMDriver* driver) { |
| 138 driver_.reset(driver); | 139 driver_.reset(driver); |
| 139 } | 140 } |
| 140 | 141 |
| 141 } // namespace gcm | 142 } // namespace gcm |
| OLD | NEW |