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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 10 #include "chrome/browser/permissions/permission_manager_factory.h" | 10 #include "chrome/browser/permissions/permission_manager_factory.h" |
| 11 #include "chrome/browser/profiles/incognito_helpers.h" | 11 #include "chrome/browser/profiles/incognito_helpers.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/push_messaging/background_budget_service_factory.h" | 13 #include "chrome/browser/push_messaging/background_budget_service_factory.h" |
| 14 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" | 14 #include "chrome/browser/push_messaging/push_messaging_service_impl.h" |
| 15 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h" | |
| 16 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 15 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 16 #include "chrome/browser/services/gcm/instance_id/instance_id_profile_service.h" | |
| 17 #include "chrome/browser/services/gcm/instance_id/instance_id_profile_service_fa ctory.h" | |
| 17 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 18 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 18 | 19 |
| 19 // static | 20 // static |
| 20 PushMessagingServiceImpl* PushMessagingServiceFactory::GetForProfile( | 21 PushMessagingServiceImpl* PushMessagingServiceFactory::GetForProfile( |
| 21 content::BrowserContext* profile) { | 22 content::BrowserContext* context) { |
| 22 // The Push API is not currently supported in incognito mode. | 23 // The Push API is not currently supported in incognito mode. |
| 23 // See https://crbug.com/401439. | 24 // See https://crbug.com/401439. |
| 24 if (profile->IsOffTheRecord()) | 25 if (context->IsOffTheRecord()) |
| 25 return NULL; | 26 return nullptr; |
| 27 | |
| 28 if (!instance_id::InstanceIDProfileService::IsInstanceIDEnabled( | |
| 29 Profile::FromBrowserContext(context))) { | |
| 30 LOG(WARNING) << "PushMessagingService could not be built because " | |
| 31 "InstanceID is unexpectedly disabled"; | |
|
Peter Beverloo
2016/06/02 15:53:17
s/unexpectedly//, these things don't happen by acc
Peter Beverloo
2016/06/02 15:53:17
Is there a watchlist or something we can subscribe
johnme
2016/06/07 14:16:43
Done.
johnme
2016/06/07 14:16:43
Yes: https://goto.google.com/actkg
| |
| 32 return nullptr; | |
| 33 } | |
| 26 | 34 |
| 27 return static_cast<PushMessagingServiceImpl*>( | 35 return static_cast<PushMessagingServiceImpl*>( |
| 28 GetInstance()->GetServiceForBrowserContext(profile, true)); | 36 GetInstance()->GetServiceForBrowserContext(context, true)); |
| 29 } | 37 } |
| 30 | 38 |
| 31 // static | 39 // static |
| 32 PushMessagingServiceFactory* PushMessagingServiceFactory::GetInstance() { | 40 PushMessagingServiceFactory* PushMessagingServiceFactory::GetInstance() { |
| 33 return base::Singleton<PushMessagingServiceFactory>::get(); | 41 return base::Singleton<PushMessagingServiceFactory>::get(); |
| 34 } | 42 } |
| 35 | 43 |
| 36 PushMessagingServiceFactory::PushMessagingServiceFactory() | 44 PushMessagingServiceFactory::PushMessagingServiceFactory() |
| 37 : BrowserContextKeyedServiceFactory( | 45 : BrowserContextKeyedServiceFactory( |
| 38 "PushMessagingProfileService", | 46 "PushMessagingProfileService", |
| 39 BrowserContextDependencyManager::GetInstance()) { | 47 BrowserContextDependencyManager::GetInstance()) { |
| 40 DependsOn(BackgroundBudgetServiceFactory::GetInstance()); | 48 DependsOn(BackgroundBudgetServiceFactory::GetInstance()); |
| 41 DependsOn(gcm::GCMProfileServiceFactory::GetInstance()); | 49 DependsOn(gcm::GCMProfileServiceFactory::GetInstance()); |
| 50 DependsOn(instance_id::InstanceIDProfileServiceFactory::GetInstance()); | |
| 42 DependsOn(HostContentSettingsMapFactory::GetInstance()); | 51 DependsOn(HostContentSettingsMapFactory::GetInstance()); |
| 43 DependsOn(PermissionManagerFactory::GetInstance()); | 52 DependsOn(PermissionManagerFactory::GetInstance()); |
| 44 } | 53 } |
| 45 | 54 |
| 46 PushMessagingServiceFactory::~PushMessagingServiceFactory() {} | 55 PushMessagingServiceFactory::~PushMessagingServiceFactory() {} |
| 47 | 56 |
| 48 void PushMessagingServiceFactory::RestoreFactoryForTests( | 57 void PushMessagingServiceFactory::RestoreFactoryForTests( |
| 49 content::BrowserContext* context) { | 58 content::BrowserContext* context) { |
| 50 SetTestingFactory(context, [](content::BrowserContext* context) { | 59 SetTestingFactory(context, [](content::BrowserContext* context) { |
| 51 return std::unique_ptr<KeyedService>( | 60 return std::unique_ptr<KeyedService>( |
| 52 GetInstance()->BuildServiceInstanceFor(context)); | 61 GetInstance()->BuildServiceInstanceFor(context)); |
| 53 }); | 62 }); |
| 54 } | 63 } |
| 55 | 64 |
| 56 KeyedService* PushMessagingServiceFactory::BuildServiceInstanceFor( | 65 KeyedService* PushMessagingServiceFactory::BuildServiceInstanceFor( |
| 57 content::BrowserContext* context) const { | 66 content::BrowserContext* context) const { |
| 58 Profile* profile = Profile::FromBrowserContext(context); | 67 Profile* profile = Profile::FromBrowserContext(context); |
| 59 CHECK(!profile->IsOffTheRecord()); | 68 CHECK(!profile->IsOffTheRecord()); |
| 60 return new PushMessagingServiceImpl(profile); | 69 return new PushMessagingServiceImpl(profile); |
| 61 } | 70 } |
| 62 | 71 |
| 63 content::BrowserContext* PushMessagingServiceFactory::GetBrowserContextToUse( | 72 content::BrowserContext* PushMessagingServiceFactory::GetBrowserContextToUse( |
| 64 content::BrowserContext* context) const { | 73 content::BrowserContext* context) const { |
| 65 return chrome::GetBrowserContextOwnInstanceInIncognito(context); | 74 return chrome::GetBrowserContextOwnInstanceInIncognito(context); |
| 66 } | 75 } |
| OLD | NEW |