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/threading/sequenced_worker_pool.h" | 9 #include "base/threading/sequenced_worker_pool.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "chrome/browser/profiles/incognito_helpers.h" | 11 #include "chrome/browser/profiles/incognito_helpers.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
14 #include "chrome/browser/signin/signin_manager_factory.h" | 14 #include "chrome/browser/signin/signin_manager_factory.h" |
15 #include "components/gcm_driver/gcm_profile_service.h" | 15 #include "components/gcm_driver/gcm_profile_service.h" |
16 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 16 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
17 #include "components/signin/core/browser/profile_identity_provider.h" | 17 #include "components/signin/core/browser/profile_identity_provider.h" |
18 #include "components/signin/core/browser/signin_manager.h" | 18 #include "components/signin/core/browser/signin_manager.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 | 20 |
21 #if !defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
22 #include "components/offline_pages/content/prefetch_service_factory.h" | |
23 #include "components/offline_pages/core/prefetch/prefetch_service.h" | |
24 #else | |
22 #include "chrome/browser/gcm/gcm_product_util.h" | 25 #include "chrome/browser/gcm/gcm_product_util.h" |
23 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 26 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
24 #include "chrome/common/channel_info.h" | 27 #include "chrome/common/channel_info.h" |
25 #include "components/gcm_driver/gcm_client_factory.h" | 28 #include "components/gcm_driver/gcm_client_factory.h" |
26 #endif | 29 #endif |
27 | 30 |
28 namespace gcm { | 31 namespace gcm { |
29 | 32 |
30 // static | 33 // static |
31 GCMProfileService* GCMProfileServiceFactory::GetForProfile( | 34 GCMProfileService* GCMProfileServiceFactory::GetForProfile( |
(...skipping 12 matching lines...) Expand all Loading... | |
44 } | 47 } |
45 | 48 |
46 GCMProfileServiceFactory::GCMProfileServiceFactory() | 49 GCMProfileServiceFactory::GCMProfileServiceFactory() |
47 : BrowserContextKeyedServiceFactory( | 50 : BrowserContextKeyedServiceFactory( |
48 "GCMProfileService", | 51 "GCMProfileService", |
49 BrowserContextDependencyManager::GetInstance()) { | 52 BrowserContextDependencyManager::GetInstance()) { |
50 DependsOn(SigninManagerFactory::GetInstance()); | 53 DependsOn(SigninManagerFactory::GetInstance()); |
51 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); | 54 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); |
52 #if !defined(OS_ANDROID) | 55 #if !defined(OS_ANDROID) |
53 DependsOn(LoginUIServiceFactory::GetInstance()); | 56 DependsOn(LoginUIServiceFactory::GetInstance()); |
57 #else | |
58 DependsOn(offline_pages::PrefetchServiceFactory::GetInstance()); | |
54 #endif | 59 #endif |
55 } | 60 } |
56 | 61 |
57 GCMProfileServiceFactory::~GCMProfileServiceFactory() { | 62 GCMProfileServiceFactory::~GCMProfileServiceFactory() { |
58 } | 63 } |
59 | 64 |
60 KeyedService* GCMProfileServiceFactory::BuildServiceInstanceFor( | 65 KeyedService* GCMProfileServiceFactory::BuildServiceInstanceFor( |
61 content::BrowserContext* context) const { | 66 content::BrowserContext* context) const { |
62 Profile* profile = Profile::FromBrowserContext(context); | 67 Profile* profile = Profile::FromBrowserContext(context); |
63 DCHECK(!profile->IsOffTheRecord()); | 68 DCHECK(!profile->IsOffTheRecord()); |
64 | 69 |
65 base::SequencedWorkerPool* worker_pool = | 70 base::SequencedWorkerPool* worker_pool = |
66 content::BrowserThread::GetBlockingPool(); | 71 content::BrowserThread::GetBlockingPool(); |
67 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( | 72 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( |
68 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( | 73 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( |
69 worker_pool->GetSequenceToken(), | 74 worker_pool->GetSequenceToken(), |
70 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | 75 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); |
76 std::unique_ptr<GCMProfileService> service; | |
71 #if defined(OS_ANDROID) | 77 #if defined(OS_ANDROID) |
72 return new GCMProfileService(profile->GetPath(), blocking_task_runner); | 78 service = base::WrapUnique( |
Dmitry Titov
2017/05/11 03:35:20
Could be just base::MakeUnique<type>(params);
| |
79 new GCMProfileService(profile->GetPath(), blocking_task_runner)); | |
80 offline_pages::PrefetchService* prefetch_service = | |
81 offline_pages::PrefetchServiceFactory::GetForBrowserContext(context); | |
82 if (prefetch_service) | |
83 prefetch_service->RegisterWithGCMDriver(service->driver()); | |
73 #else | 84 #else |
74 return new GCMProfileService( | 85 service = base::WrapUnique(new GCMProfileService( |
75 profile->GetPrefs(), profile->GetPath(), profile->GetRequestContext(), | 86 profile->GetPrefs(), profile->GetPath(), profile->GetRequestContext(), |
76 chrome::GetChannel(), | 87 chrome::GetChannel(), |
77 gcm::GetProductCategoryForSubtypes(profile->GetPrefs()), | 88 gcm::GetProductCategoryForSubtypes(profile->GetPrefs()), |
78 std::unique_ptr<ProfileIdentityProvider>(new ProfileIdentityProvider( | 89 std::unique_ptr<ProfileIdentityProvider>(new ProfileIdentityProvider( |
79 SigninManagerFactory::GetForProfile(profile), | 90 SigninManagerFactory::GetForProfile(profile), |
80 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), | 91 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |
81 LoginUIServiceFactory::GetShowLoginPopupCallbackForProfile(profile))), | 92 LoginUIServiceFactory::GetShowLoginPopupCallbackForProfile(profile))), |
82 std::unique_ptr<GCMClientFactory>(new GCMClientFactory), | 93 std::unique_ptr<GCMClientFactory>(new GCMClientFactory), |
83 content::BrowserThread::GetTaskRunnerForThread( | 94 content::BrowserThread::GetTaskRunnerForThread( |
84 content::BrowserThread::UI), | 95 content::BrowserThread::UI), |
85 content::BrowserThread::GetTaskRunnerForThread( | 96 content::BrowserThread::GetTaskRunnerForThread( |
86 content::BrowserThread::IO), | 97 content::BrowserThread::IO), |
87 blocking_task_runner); | 98 blocking_task_runner)); |
88 #endif | 99 #endif |
100 return service.release(); | |
89 } | 101 } |
90 | 102 |
91 content::BrowserContext* GCMProfileServiceFactory::GetBrowserContextToUse( | 103 content::BrowserContext* GCMProfileServiceFactory::GetBrowserContextToUse( |
92 content::BrowserContext* context) const { | 104 content::BrowserContext* context) const { |
93 return chrome::GetBrowserContextOwnInstanceInIncognito(context); | 105 return chrome::GetBrowserContextOwnInstanceInIncognito(context); |
94 } | 106 } |
95 | 107 |
96 } // namespace gcm | 108 } // namespace gcm |
OLD | NEW |