Chromium Code Reviews| 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/push_messaging_service_impl.h" | 12 #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/gcm_profile_service_factory.h" | 13 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 14 #include "chrome/browser/services/gcm/instance_id/instance_id_profile_service.h" | |
| 15 #include "chrome/browser/services/gcm/instance_id/instance_id_profile_service_fa ctory.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* context) { |
| 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 (context->IsOffTheRecord()) |
| 23 return NULL; | 24 return nullptr; |
| 25 | |
| 26 if (!instance_id::InstanceIDProfileService::IsInstanceIDEnabled( | |
| 27 Profile::FromBrowserContext(context))) { | |
| 28 DLOG(WARNING) << "PushMessagingService could not be built, because " | |
|
Peter Beverloo
2016/04/21 13:26:18
LOG(WARNING).
When, for whatever reason, the kill
johnme
2016/05/25 14:11:50
Done.
| |
| 29 "InstanceIDProfileService is unexpectedly disabled"; | |
|
Peter Beverloo
2016/04/21 13:26:18
micro nits:
(1) no comma
(2) InstanceIDProfileSe
johnme
2016/05/25 14:11:50
Done.
| |
| 30 return nullptr; | |
| 31 } | |
| 24 | 32 |
| 25 return static_cast<PushMessagingServiceImpl*>( | 33 return static_cast<PushMessagingServiceImpl*>( |
| 26 GetInstance()->GetServiceForBrowserContext(profile, true)); | 34 GetInstance()->GetServiceForBrowserContext(context, true)); |
| 27 } | 35 } |
| 28 | 36 |
| 29 // static | 37 // static |
| 30 PushMessagingServiceFactory* PushMessagingServiceFactory::GetInstance() { | 38 PushMessagingServiceFactory* PushMessagingServiceFactory::GetInstance() { |
| 31 return base::Singleton<PushMessagingServiceFactory>::get(); | 39 return base::Singleton<PushMessagingServiceFactory>::get(); |
| 32 } | 40 } |
| 33 | 41 |
| 34 PushMessagingServiceFactory::PushMessagingServiceFactory() | 42 PushMessagingServiceFactory::PushMessagingServiceFactory() |
| 35 : BrowserContextKeyedServiceFactory( | 43 : BrowserContextKeyedServiceFactory( |
| 36 "PushMessagingProfileService", | 44 "PushMessagingProfileService", |
| 37 BrowserContextDependencyManager::GetInstance()) { | 45 BrowserContextDependencyManager::GetInstance()) { |
| 38 DependsOn(gcm::GCMProfileServiceFactory::GetInstance()); | 46 DependsOn(gcm::GCMProfileServiceFactory::GetInstance()); |
| 47 DependsOn(instance_id::InstanceIDProfileServiceFactory::GetInstance()); | |
| 39 DependsOn(HostContentSettingsMapFactory::GetInstance()); | 48 DependsOn(HostContentSettingsMapFactory::GetInstance()); |
| 40 DependsOn(PermissionManagerFactory::GetInstance()); | 49 DependsOn(PermissionManagerFactory::GetInstance()); |
| 41 } | 50 } |
| 42 | 51 |
| 43 PushMessagingServiceFactory::~PushMessagingServiceFactory() {} | 52 PushMessagingServiceFactory::~PushMessagingServiceFactory() {} |
| 44 | 53 |
| 45 void PushMessagingServiceFactory::RestoreFactoryForTests( | 54 void PushMessagingServiceFactory::RestoreFactoryForTests( |
| 46 content::BrowserContext* context) { | 55 content::BrowserContext* context) { |
| 47 SetTestingFactory(context, [](content::BrowserContext* context) { | 56 SetTestingFactory(context, [](content::BrowserContext* context) { |
| 48 return scoped_ptr<KeyedService>( | 57 return scoped_ptr<KeyedService>( |
| 49 GetInstance()->BuildServiceInstanceFor(context)); | 58 GetInstance()->BuildServiceInstanceFor(context)); |
| 50 }); | 59 }); |
| 51 } | 60 } |
| 52 | 61 |
| 53 KeyedService* PushMessagingServiceFactory::BuildServiceInstanceFor( | 62 KeyedService* PushMessagingServiceFactory::BuildServiceInstanceFor( |
| 54 content::BrowserContext* context) const { | 63 content::BrowserContext* context) const { |
| 55 Profile* profile = Profile::FromBrowserContext(context); | 64 Profile* profile = Profile::FromBrowserContext(context); |
| 56 CHECK(!profile->IsOffTheRecord()); | 65 CHECK(!profile->IsOffTheRecord()); |
| 57 return new PushMessagingServiceImpl(profile); | 66 return new PushMessagingServiceImpl(profile); |
| 58 } | 67 } |
| 59 | 68 |
| 60 content::BrowserContext* PushMessagingServiceFactory::GetBrowserContextToUse( | 69 content::BrowserContext* PushMessagingServiceFactory::GetBrowserContextToUse( |
| 61 content::BrowserContext* context) const { | 70 content::BrowserContext* context) const { |
| 62 return chrome::GetBrowserContextOwnInstanceInIncognito(context); | 71 return chrome::GetBrowserContextOwnInstanceInIncognito(context); |
| 63 } | 72 } |
| OLD | NEW |