| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/push_messaging/push_messaging_service_factory.h" | 5 #include "chrome/browser/push_messaging/push_messaging_service_factory.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 9 #include "chrome/browser/permissions/permission_manager_factory.h" | 9 #include "chrome/browser/permissions/permission_manager_factory.h" |
| 10 #include "chrome/browser/profiles/incognito_helpers.h" | 10 #include "chrome/browser/profiles/incognito_helpers.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/push_messaging/background_budget_service_factory.h" |
| 12 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" | 13 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
| 13 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" | 14 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" |
| 14 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 15 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 15 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 16 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 16 | 17 |
| 17 // static | 18 // static |
| 18 PushMessagingServiceImpl* PushMessagingServiceFactory::GetForProfile( | 19 PushMessagingServiceImpl* PushMessagingServiceFactory::GetForProfile( |
| 19 content::BrowserContext* profile) { | 20 content::BrowserContext* profile) { |
| 20 // The Push API is not currently supported in incognito mode. | 21 // The Push API is not currently supported in incognito mode. |
| 21 // See https://crbug.com/401439. | 22 // See https://crbug.com/401439. |
| 22 if (profile->IsOffTheRecord()) | 23 if (profile->IsOffTheRecord()) |
| 23 return NULL; | 24 return NULL; |
| 24 | 25 |
| 25 return static_cast<PushMessagingServiceImpl*>( | 26 return static_cast<PushMessagingServiceImpl*>( |
| 26 GetInstance()->GetServiceForBrowserContext(profile, true)); | 27 GetInstance()->GetServiceForBrowserContext(profile, true)); |
| 27 } | 28 } |
| 28 | 29 |
| 29 // static | 30 // static |
| 30 PushMessagingServiceFactory* PushMessagingServiceFactory::GetInstance() { | 31 PushMessagingServiceFactory* PushMessagingServiceFactory::GetInstance() { |
| 31 return base::Singleton<PushMessagingServiceFactory>::get(); | 32 return base::Singleton<PushMessagingServiceFactory>::get(); |
| 32 } | 33 } |
| 33 | 34 |
| 34 PushMessagingServiceFactory::PushMessagingServiceFactory() | 35 PushMessagingServiceFactory::PushMessagingServiceFactory() |
| 35 : BrowserContextKeyedServiceFactory( | 36 : BrowserContextKeyedServiceFactory( |
| 36 "PushMessagingProfileService", | 37 "PushMessagingProfileService", |
| 37 BrowserContextDependencyManager::GetInstance()) { | 38 BrowserContextDependencyManager::GetInstance()) { |
| 39 DependsOn(BackgroundBudgetServiceFactory::GetInstance()); |
| 38 DependsOn(gcm::GCMProfileServiceFactory::GetInstance()); | 40 DependsOn(gcm::GCMProfileServiceFactory::GetInstance()); |
| 39 DependsOn(HostContentSettingsMapFactory::GetInstance()); | 41 DependsOn(HostContentSettingsMapFactory::GetInstance()); |
| 40 DependsOn(PermissionManagerFactory::GetInstance()); | 42 DependsOn(PermissionManagerFactory::GetInstance()); |
| 41 } | 43 } |
| 42 | 44 |
| 43 PushMessagingServiceFactory::~PushMessagingServiceFactory() {} | 45 PushMessagingServiceFactory::~PushMessagingServiceFactory() {} |
| 44 | 46 |
| 45 void PushMessagingServiceFactory::RestoreFactoryForTests( | 47 void PushMessagingServiceFactory::RestoreFactoryForTests( |
| 46 content::BrowserContext* context) { | 48 content::BrowserContext* context) { |
| 47 SetTestingFactory(context, [](content::BrowserContext* context) { | 49 SetTestingFactory(context, [](content::BrowserContext* context) { |
| 48 return scoped_ptr<KeyedService>( | 50 return scoped_ptr<KeyedService>( |
| 49 GetInstance()->BuildServiceInstanceFor(context)); | 51 GetInstance()->BuildServiceInstanceFor(context)); |
| 50 }); | 52 }); |
| 51 } | 53 } |
| 52 | 54 |
| 53 KeyedService* PushMessagingServiceFactory::BuildServiceInstanceFor( | 55 KeyedService* PushMessagingServiceFactory::BuildServiceInstanceFor( |
| 54 content::BrowserContext* context) const { | 56 content::BrowserContext* context) const { |
| 55 Profile* profile = Profile::FromBrowserContext(context); | 57 Profile* profile = Profile::FromBrowserContext(context); |
| 56 CHECK(!profile->IsOffTheRecord()); | 58 CHECK(!profile->IsOffTheRecord()); |
| 57 return new PushMessagingServiceImpl(profile); | 59 return new PushMessagingServiceImpl(profile); |
| 58 } | 60 } |
| 59 | 61 |
| 60 content::BrowserContext* PushMessagingServiceFactory::GetBrowserContextToUse( | 62 content::BrowserContext* PushMessagingServiceFactory::GetBrowserContextToUse( |
| 61 content::BrowserContext* context) const { | 63 content::BrowserContext* context) const { |
| 62 return chrome::GetBrowserContextOwnInstanceInIncognito(context); | 64 return chrome::GetBrowserContextOwnInstanceInIncognito(context); |
| 63 } | 65 } |
| OLD | NEW |