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.
5 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/profiles/incognito_helpers.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/services/gcm/gcm_profile_service.h"
11 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
12 #include "chrome/browser/signin/signin_manager_factory.h"
13 #include "components/keyed_service/content/browser_context_dependency_manager.h"
15 #if !defined(OS_ANDROID)
16 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
17 #include "components/gcm_driver/gcm_client_factory.h"
23 GCMProfileService
* GCMProfileServiceFactory::GetForProfile(
24 content::BrowserContext
* profile
) {
25 // GCM is not supported in incognito mode.
26 if (profile
->IsOffTheRecord())
29 return static_cast<GCMProfileService
*>(
30 GetInstance()->GetServiceForBrowserContext(profile
, true));
34 GCMProfileServiceFactory
* GCMProfileServiceFactory::GetInstance() {
35 return Singleton
<GCMProfileServiceFactory
>::get();
38 GCMProfileServiceFactory::GCMProfileServiceFactory()
39 : BrowserContextKeyedServiceFactory(
41 BrowserContextDependencyManager::GetInstance()) {
42 DependsOn(SigninManagerFactory::GetInstance());
43 DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
44 #if !defined(OS_ANDROID)
45 DependsOn(LoginUIServiceFactory::GetInstance());
49 GCMProfileServiceFactory::~GCMProfileServiceFactory() {
52 KeyedService
* GCMProfileServiceFactory::BuildServiceInstanceFor(
53 content::BrowserContext
* context
) const {
54 #if defined(OS_ANDROID)
55 return new GCMProfileService(Profile::FromBrowserContext(context
));
57 return new GCMProfileService(
58 Profile::FromBrowserContext(context
),
59 scoped_ptr
<GCMClientFactory
>(new GCMClientFactory
));
63 content::BrowserContext
* GCMProfileServiceFactory::GetBrowserContextToUse(
64 content::BrowserContext
* context
) const {
65 return chrome::GetBrowserContextOwnInstanceInIncognito(context
);