| 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/gcm/gcm_profile_service_factory.h" | 5 #include "chrome/browser/gcm/gcm_profile_service_factory.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/sequenced_task_runner.h" | 9 #include "base/sequenced_task_runner.h" |
| 10 #include "base/task_scheduler/post_task.h" | 10 #include "base/task_scheduler/post_task.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "chrome/browser/profiles/incognito_helpers.h" | 12 #include "chrome/browser/profiles/incognito_helpers.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 15 #include "chrome/browser/signin/signin_manager_factory.h" | 15 #include "chrome/browser/signin/signin_manager_factory.h" |
| 16 #include "components/gcm_driver/gcm_profile_service.h" | 16 #include "components/gcm_driver/gcm_profile_service.h" |
| 17 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 17 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 18 #include "components/offline_pages/features/features.h" |
| 18 #include "components/signin/core/browser/profile_identity_provider.h" | 19 #include "components/signin/core/browser/profile_identity_provider.h" |
| 19 #include "components/signin/core/browser/signin_manager.h" | 20 #include "components/signin/core/browser/signin_manager.h" |
| 20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 21 | 22 |
| 22 #if !defined(OS_ANDROID) | 23 #if !defined(OS_ANDROID) |
| 23 #include "chrome/browser/gcm/gcm_product_util.h" | 24 #include "chrome/browser/gcm/gcm_product_util.h" |
| 24 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 25 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 25 #include "chrome/common/channel_info.h" | 26 #include "chrome/common/channel_info.h" |
| 26 #include "components/gcm_driver/gcm_client_factory.h" | 27 #include "components/gcm_driver/gcm_client_factory.h" |
| 27 #endif | 28 #endif |
| 28 | 29 |
| 30 #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 31 #include "chrome/browser/offline_pages/prefetch/prefetch_service_factory.h" |
| 32 #include "components/offline_pages/core/prefetch/prefetch_gcm_app_handler.h" |
| 33 #endif |
| 34 |
| 29 namespace gcm { | 35 namespace gcm { |
| 30 | 36 |
| 31 // static | 37 // static |
| 32 GCMProfileService* GCMProfileServiceFactory::GetForProfile( | 38 GCMProfileService* GCMProfileServiceFactory::GetForProfile( |
| 33 content::BrowserContext* profile) { | 39 content::BrowserContext* profile) { |
| 34 // GCM is not supported in incognito mode. | 40 // GCM is not supported in incognito mode. |
| 35 if (profile->IsOffTheRecord()) | 41 if (profile->IsOffTheRecord()) |
| 36 return NULL; | 42 return NULL; |
| 37 | 43 |
| 38 return static_cast<GCMProfileService*>( | 44 return static_cast<GCMProfileService*>( |
| 39 GetInstance()->GetServiceForBrowserContext(profile, true)); | 45 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 40 } | 46 } |
| 41 | 47 |
| 42 // static | 48 // static |
| 43 GCMProfileServiceFactory* GCMProfileServiceFactory::GetInstance() { | 49 GCMProfileServiceFactory* GCMProfileServiceFactory::GetInstance() { |
| 44 return base::Singleton<GCMProfileServiceFactory>::get(); | 50 return base::Singleton<GCMProfileServiceFactory>::get(); |
| 45 } | 51 } |
| 46 | 52 |
| 47 GCMProfileServiceFactory::GCMProfileServiceFactory() | 53 GCMProfileServiceFactory::GCMProfileServiceFactory() |
| 48 : BrowserContextKeyedServiceFactory( | 54 : BrowserContextKeyedServiceFactory( |
| 49 "GCMProfileService", | 55 "GCMProfileService", |
| 50 BrowserContextDependencyManager::GetInstance()) { | 56 BrowserContextDependencyManager::GetInstance()) { |
| 51 DependsOn(SigninManagerFactory::GetInstance()); | 57 DependsOn(SigninManagerFactory::GetInstance()); |
| 52 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); | 58 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); |
| 53 #if !defined(OS_ANDROID) | 59 #if !defined(OS_ANDROID) |
| 54 DependsOn(LoginUIServiceFactory::GetInstance()); | 60 DependsOn(LoginUIServiceFactory::GetInstance()); |
| 55 #endif | 61 #endif |
| 62 #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 63 DependsOn(offline_pages::PrefetchServiceFactory::GetInstance()); |
| 64 #endif // BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 56 } | 65 } |
| 57 | 66 |
| 58 GCMProfileServiceFactory::~GCMProfileServiceFactory() { | 67 GCMProfileServiceFactory::~GCMProfileServiceFactory() { |
| 59 } | 68 } |
| 60 | 69 |
| 61 KeyedService* GCMProfileServiceFactory::BuildServiceInstanceFor( | 70 KeyedService* GCMProfileServiceFactory::BuildServiceInstanceFor( |
| 62 content::BrowserContext* context) const { | 71 content::BrowserContext* context) const { |
| 63 Profile* profile = Profile::FromBrowserContext(context); | 72 Profile* profile = Profile::FromBrowserContext(context); |
| 64 DCHECK(!profile->IsOffTheRecord()); | 73 DCHECK(!profile->IsOffTheRecord()); |
| 65 | 74 |
| 66 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( | 75 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( |
| 67 base::CreateSequencedTaskRunnerWithTraits( | 76 base::CreateSequencedTaskRunnerWithTraits( |
| 68 {base::MayBlock(), base::TaskPriority::BACKGROUND, | 77 {base::MayBlock(), base::TaskPriority::BACKGROUND, |
| 69 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})); | 78 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN})); |
| 79 std::unique_ptr<GCMProfileService> service = nullptr; |
| 70 #if defined(OS_ANDROID) | 80 #if defined(OS_ANDROID) |
| 71 return new GCMProfileService(profile->GetPath(), blocking_task_runner); | 81 service = base::WrapUnique( |
| 82 new GCMProfileService(profile->GetPath(), blocking_task_runner)); |
| 72 #else | 83 #else |
| 73 return new GCMProfileService( | 84 service = base::WrapUnique(new GCMProfileService( |
| 74 profile->GetPrefs(), profile->GetPath(), profile->GetRequestContext(), | 85 profile->GetPrefs(), profile->GetPath(), profile->GetRequestContext(), |
| 75 chrome::GetChannel(), | 86 chrome::GetChannel(), |
| 76 gcm::GetProductCategoryForSubtypes(profile->GetPrefs()), | 87 gcm::GetProductCategoryForSubtypes(profile->GetPrefs()), |
| 77 std::unique_ptr<ProfileIdentityProvider>(new ProfileIdentityProvider( | 88 std::unique_ptr<ProfileIdentityProvider>(new ProfileIdentityProvider( |
| 78 SigninManagerFactory::GetForProfile(profile), | 89 SigninManagerFactory::GetForProfile(profile), |
| 79 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), | 90 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |
| 80 LoginUIServiceFactory::GetShowLoginPopupCallbackForProfile(profile))), | 91 LoginUIServiceFactory::GetShowLoginPopupCallbackForProfile(profile))), |
| 81 std::unique_ptr<GCMClientFactory>(new GCMClientFactory), | 92 std::unique_ptr<GCMClientFactory>(new GCMClientFactory), |
| 82 content::BrowserThread::GetTaskRunnerForThread( | 93 content::BrowserThread::GetTaskRunnerForThread( |
| 83 content::BrowserThread::UI), | 94 content::BrowserThread::UI), |
| 84 content::BrowserThread::GetTaskRunnerForThread( | 95 content::BrowserThread::GetTaskRunnerForThread( |
| 85 content::BrowserThread::IO), | 96 content::BrowserThread::IO), |
| 86 blocking_task_runner); | 97 blocking_task_runner)); |
| 87 #endif | 98 #endif |
| 99 #if BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 100 offline_pages::PrefetchGCMAppHandler::AddAppHandlerToPrefetchService( |
| 101 offline_pages::PrefetchServiceFactory::GetForBrowserContext(context), |
| 102 service.get()); |
| 103 #endif // BUILDFLAG(ENABLE_OFFLINE_PAGES) |
| 104 |
| 105 return service.release(); |
| 88 } | 106 } |
| 89 | 107 |
| 90 content::BrowserContext* GCMProfileServiceFactory::GetBrowserContextToUse( | 108 content::BrowserContext* GCMProfileServiceFactory::GetBrowserContextToUse( |
| 91 content::BrowserContext* context) const { | 109 content::BrowserContext* context) const { |
| 92 return chrome::GetBrowserContextOwnInstanceInIncognito(context); | 110 return chrome::GetBrowserContextOwnInstanceInIncognito(context); |
| 93 } | 111 } |
| 94 | 112 |
| 95 } // namespace gcm | 113 } // namespace gcm |
| OLD | NEW |