| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 5 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/incognito_helpers.h" | 7 #include "chrome/browser/profiles/incognito_helpers.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/services/gcm/gcm_client_factory.h" | 9 #include "chrome/browser/services/gcm/gcm_client_factory.h" |
| 10 #include "chrome/browser/services/gcm/gcm_profile_service.h" | 10 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
| 11 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" | 11 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.h" |
| 12 | 12 |
| 13 namespace gcm { | 13 namespace gcm { |
| 14 | 14 |
| 15 // static | 15 // static |
| 16 GCMProfileService* GCMProfileServiceFactory::GetForProfile(Profile* profile) { | 16 GCMProfileService* GCMProfileServiceFactory::GetForProfile(Profile* profile) { |
| 17 if (!gcm::GCMProfileService::IsGCMEnabled(profile)) | 17 // GCM is not supported in incognito mode. |
| 18 if (profile->IsOffTheRecord()) |
| 18 return NULL; | 19 return NULL; |
| 19 | 20 |
| 20 return static_cast<GCMProfileService*>( | 21 return static_cast<GCMProfileService*>( |
| 21 GetInstance()->GetServiceForBrowserContext(profile, true)); | 22 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 22 } | 23 } |
| 23 | 24 |
| 24 // static | 25 // static |
| 25 GCMProfileServiceFactory* GCMProfileServiceFactory::GetInstance() { | 26 GCMProfileServiceFactory* GCMProfileServiceFactory::GetInstance() { |
| 26 return Singleton<GCMProfileServiceFactory>::get(); | 27 return Singleton<GCMProfileServiceFactory>::get(); |
| 27 } | 28 } |
| 28 | 29 |
| 29 GCMProfileServiceFactory::GCMProfileServiceFactory() | 30 GCMProfileServiceFactory::GCMProfileServiceFactory() |
| 30 : BrowserContextKeyedServiceFactory( | 31 : BrowserContextKeyedServiceFactory( |
| 31 "GCMProfileService", | 32 "GCMProfileService", |
| 32 BrowserContextDependencyManager::GetInstance()) { | 33 BrowserContextDependencyManager::GetInstance()) { |
| 33 } | 34 } |
| 34 | 35 |
| 35 GCMProfileServiceFactory::~GCMProfileServiceFactory() { | 36 GCMProfileServiceFactory::~GCMProfileServiceFactory() { |
| 36 } | 37 } |
| 37 | 38 |
| 38 BrowserContextKeyedService* GCMProfileServiceFactory::BuildServiceInstanceFor( | 39 BrowserContextKeyedService* GCMProfileServiceFactory::BuildServiceInstanceFor( |
| 39 content::BrowserContext* context) const { | 40 content::BrowserContext* context) const { |
| 40 Profile* profile = static_cast<Profile*>(context); | 41 Profile* profile = static_cast<Profile*>(context); |
| 41 if (!gcm::GCMProfileService::IsGCMEnabled(profile)) | |
| 42 return NULL; | |
| 43 GCMProfileService* service = new GCMProfileService(profile); | 42 GCMProfileService* service = new GCMProfileService(profile); |
| 44 scoped_ptr<GCMClientFactory> gcm_client_factory(new GCMClientFactory); | 43 scoped_ptr<GCMClientFactory> gcm_client_factory(new GCMClientFactory); |
| 45 service->Initialize(gcm_client_factory.Pass()); | 44 service->Initialize(gcm_client_factory.Pass()); |
| 46 return service; | 45 return service; |
| 47 } | 46 } |
| 48 | 47 |
| 49 content::BrowserContext* GCMProfileServiceFactory::GetBrowserContextToUse( | 48 content::BrowserContext* GCMProfileServiceFactory::GetBrowserContextToUse( |
| 50 content::BrowserContext* context) const { | 49 content::BrowserContext* context) const { |
| 51 return chrome::GetBrowserContextOwnInstanceInIncognito(context); | 50 return chrome::GetBrowserContextOwnInstanceInIncognito(context); |
| 52 } | 51 } |
| 53 | 52 |
| 54 } // namespace gcm | 53 } // namespace gcm |
| OLD | NEW |