OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | |
6 | |
7 #include <memory> | |
8 | |
9 #include "build/build_config.h" | |
10 #include "chrome/browser/profiles/incognito_helpers.h" | |
11 #include "chrome/browser/profiles/profile.h" | |
12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | |
13 #include "chrome/browser/signin/signin_manager_factory.h" | |
14 #include "components/gcm_driver/gcm_profile_service.h" | |
15 #include "components/keyed_service/content/browser_context_dependency_manager.h" | |
16 #include "components/signin/core/browser/profile_identity_provider.h" | |
17 #include "components/signin/core/browser/signin_manager.h" | |
18 #include "content/public/browser/browser_thread.h" | |
19 | |
20 #if !defined(OS_ANDROID) | |
21 #include "chrome/browser/services/gcm/gcm_product_util.h" | |
22 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | |
23 #include "chrome/common/channel_info.h" | |
24 #include "components/gcm_driver/gcm_client_factory.h" | |
25 #endif | |
26 | |
27 namespace gcm { | |
28 | |
29 // static | |
30 GCMProfileService* GCMProfileServiceFactory::GetForProfile( | |
31 content::BrowserContext* profile) { | |
32 // GCM is not supported in incognito mode. | |
33 if (profile->IsOffTheRecord()) | |
34 return NULL; | |
35 | |
36 return static_cast<GCMProfileService*>( | |
37 GetInstance()->GetServiceForBrowserContext(profile, true)); | |
38 } | |
39 | |
40 // static | |
41 GCMProfileServiceFactory* GCMProfileServiceFactory::GetInstance() { | |
42 return base::Singleton<GCMProfileServiceFactory>::get(); | |
43 } | |
44 | |
45 GCMProfileServiceFactory::GCMProfileServiceFactory() | |
46 : BrowserContextKeyedServiceFactory( | |
47 "GCMProfileService", | |
48 BrowserContextDependencyManager::GetInstance()) { | |
49 DependsOn(SigninManagerFactory::GetInstance()); | |
50 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance()); | |
51 #if !defined(OS_ANDROID) | |
52 DependsOn(LoginUIServiceFactory::GetInstance()); | |
53 #endif | |
54 } | |
55 | |
56 GCMProfileServiceFactory::~GCMProfileServiceFactory() { | |
57 } | |
58 | |
59 KeyedService* GCMProfileServiceFactory::BuildServiceInstanceFor( | |
60 content::BrowserContext* context) const { | |
61 Profile* profile = Profile::FromBrowserContext(context); | |
62 DCHECK(!profile->IsOffTheRecord()); | |
63 | |
64 base::SequencedWorkerPool* worker_pool = | |
65 content::BrowserThread::GetBlockingPool(); | |
66 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner( | |
67 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior( | |
68 worker_pool->GetSequenceToken(), | |
69 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)); | |
70 #if defined(OS_ANDROID) | |
71 return new GCMProfileService(profile->GetPath(), blocking_task_runner); | |
72 #else | |
73 return new GCMProfileService( | |
74 profile->GetPrefs(), profile->GetPath(), profile->GetRequestContext(), | |
75 chrome::GetChannel(), | |
76 gcm::GetProductCategoryForSubtypes(profile->GetPrefs()), | |
77 std::unique_ptr<ProfileIdentityProvider>(new ProfileIdentityProvider( | |
78 SigninManagerFactory::GetForProfile(profile), | |
79 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), | |
80 LoginUIServiceFactory::GetShowLoginPopupCallbackForProfile(profile))), | |
81 std::unique_ptr<GCMClientFactory>(new GCMClientFactory), | |
82 content::BrowserThread::GetTaskRunnerForThread( | |
83 content::BrowserThread::UI), | |
84 content::BrowserThread::GetTaskRunnerForThread( | |
85 content::BrowserThread::IO), | |
86 blocking_task_runner); | |
87 #endif | |
88 } | |
89 | |
90 content::BrowserContext* GCMProfileServiceFactory::GetBrowserContextToUse( | |
91 content::BrowserContext* context) const { | |
92 return chrome::GetBrowserContextOwnInstanceInIncognito(context); | |
93 } | |
94 | |
95 } // namespace gcm | |
OLD | NEW |