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 "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"
16 GCMProfileService* GCMProfileServiceFactory::GetForProfile(Profile* profile) {
17 if (!gcm::GCMProfileService::IsGCMEnabled(profile))
20 return static_cast<GCMProfileService*>(
21 GetInstance()->GetServiceForBrowserContext(profile, true));
25 GCMProfileServiceFactory* GCMProfileServiceFactory::GetInstance() {
26 return Singleton<GCMProfileServiceFactory>::get();
29 GCMProfileServiceFactory::GCMProfileServiceFactory()
30 : BrowserContextKeyedServiceFactory(
32 BrowserContextDependencyManager::GetInstance()) {
35 GCMProfileServiceFactory::~GCMProfileServiceFactory() {
38 BrowserContextKeyedService* GCMProfileServiceFactory::BuildServiceInstanceFor(
39 content::BrowserContext* context) const {
40 Profile* profile = static_cast<Profile*>(context);
41 if (!gcm::GCMProfileService::IsGCMEnabled(profile))
43 GCMProfileService* service = new GCMProfileService(profile);
44 scoped_ptr<GCMClientFactory> gcm_client_factory(new GCMClientFactory);
45 service->Initialize(gcm_client_factory.Pass());
49 content::BrowserContext* GCMProfileServiceFactory::GetBrowserContextToUse(
50 content::BrowserContext* context) const {
51 return chrome::GetBrowserContextOwnInstanceInIncognito(context);