Upstream version 5.34.104.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 "chrome/browser/profiles/incognito_helpers.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/services/gcm/gcm_client_factory.h"
10 #include "chrome/browser/services/gcm/gcm_profile_service.h"
11 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
12
13 namespace gcm {
14
15 // static
16 GCMProfileService* GCMProfileServiceFactory::GetForProfile(Profile* profile) {
17   if (!gcm::GCMProfileService::IsGCMEnabled(profile))
18     return NULL;
19
20   return static_cast<GCMProfileService*>(
21       GetInstance()->GetServiceForBrowserContext(profile, true));
22 }
23
24 // static
25 GCMProfileServiceFactory* GCMProfileServiceFactory::GetInstance() {
26   return Singleton<GCMProfileServiceFactory>::get();
27 }
28
29 GCMProfileServiceFactory::GCMProfileServiceFactory()
30     : BrowserContextKeyedServiceFactory(
31         "GCMProfileService",
32         BrowserContextDependencyManager::GetInstance()) {
33 }
34
35 GCMProfileServiceFactory::~GCMProfileServiceFactory() {
36 }
37
38 BrowserContextKeyedService* GCMProfileServiceFactory::BuildServiceInstanceFor(
39     content::BrowserContext* context) const {
40   Profile* profile = static_cast<Profile*>(context);
41   if (!gcm::GCMProfileService::IsGCMEnabled(profile))
42     return NULL;
43   GCMProfileService* service = new GCMProfileService(profile);
44   scoped_ptr<GCMClientFactory> gcm_client_factory(new GCMClientFactory);
45   service->Initialize(gcm_client_factory.Pass());
46   return service;
47 }
48
49 content::BrowserContext* GCMProfileServiceFactory::GetBrowserContextToUse(
50     content::BrowserContext* context) const {
51   return chrome::GetBrowserContextOwnInstanceInIncognito(context);
52 }
53
54 }  // namespace gcm