Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / services / gcm / gcm_profile_service_factory.cc
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 "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_client_factory.h"
11 #include "chrome/browser/services/gcm/gcm_profile_service.h"
12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
13 #include "chrome/browser/signin/signin_manager_factory.h"
14 #include "components/keyed_service/content/browser_context_dependency_manager.h"
15
16 #if !defined(OS_ANDROID)
17 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h"
18 #endif
19
20 namespace gcm {
21
22 // static
23 GCMProfileService* GCMProfileServiceFactory::GetForProfile(Profile* profile) {
24   // GCM is not supported in incognito mode.
25   if (profile->IsOffTheRecord())
26     return NULL;
27
28   return static_cast<GCMProfileService*>(
29       GetInstance()->GetServiceForBrowserContext(profile, true));
30 }
31
32 // static
33 GCMProfileServiceFactory* GCMProfileServiceFactory::GetInstance() {
34   return Singleton<GCMProfileServiceFactory>::get();
35 }
36
37 GCMProfileServiceFactory::GCMProfileServiceFactory()
38     : BrowserContextKeyedServiceFactory(
39         "GCMProfileService",
40         BrowserContextDependencyManager::GetInstance()) {
41   DependsOn(SigninManagerFactory::GetInstance());
42   DependsOn(ProfileOAuth2TokenServiceFactory::GetInstance());
43 #if !defined(OS_ANDROID)
44   DependsOn(LoginUIServiceFactory::GetInstance());
45 #endif
46 }
47
48 GCMProfileServiceFactory::~GCMProfileServiceFactory() {
49 }
50
51 KeyedService* GCMProfileServiceFactory::BuildServiceInstanceFor(
52     content::BrowserContext* context) const {
53   Profile* profile = static_cast<Profile*>(context);
54   GCMProfileService* service = new GCMProfileService(profile);
55   scoped_ptr<GCMClientFactory> gcm_client_factory(new GCMClientFactory);
56   service->Initialize(gcm_client_factory.Pass());
57   return service;
58 }
59
60 content::BrowserContext* GCMProfileServiceFactory::GetBrowserContextToUse(
61     content::BrowserContext* context) const {
62   return chrome::GetBrowserContextOwnInstanceInIncognito(context);
63 }
64
65 }  // namespace gcm