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
3 // found in the LICENSE file.
5 #include "chrome/browser/push_messaging/push_messaging_service_factory.h"
7 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
8 #include "chrome/browser/profiles/incognito_helpers.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/push_messaging/push_messaging_service_impl.h"
11 #include "chrome/browser/services/gcm/fake_gcm_profile_service.h"
12 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h"
13 #include "components/keyed_service/content/browser_context_dependency_manager.h"
16 PushMessagingServiceImpl
* PushMessagingServiceFactory::GetForProfile(
17 content::BrowserContext
* profile
) {
18 // The Push API is not currently supported in incognito mode.
19 // See https://crbug.com/401439.
20 if (profile
->IsOffTheRecord())
23 return static_cast<PushMessagingServiceImpl
*>(
24 GetInstance()->GetServiceForBrowserContext(profile
, true));
28 PushMessagingServiceFactory
* PushMessagingServiceFactory::GetInstance() {
29 return base::Singleton
<PushMessagingServiceFactory
>::get();
32 PushMessagingServiceFactory::PushMessagingServiceFactory()
33 : BrowserContextKeyedServiceFactory(
34 "PushMessagingProfileService",
35 BrowserContextDependencyManager::GetInstance()) {
36 DependsOn(gcm::GCMProfileServiceFactory::GetInstance());
37 DependsOn(HostContentSettingsMapFactory::GetInstance());
40 PushMessagingServiceFactory::~PushMessagingServiceFactory() {
43 KeyedService
* PushMessagingServiceFactory::BuildServiceInstanceFor(
44 content::BrowserContext
* context
) const {
45 Profile
* profile
= Profile::FromBrowserContext(context
);
46 CHECK(!profile
->IsOffTheRecord());
47 return new PushMessagingServiceImpl(profile
);
50 content::BrowserContext
* PushMessagingServiceFactory::GetBrowserContextToUse(
51 content::BrowserContext
* context
) const {
52 return chrome::GetBrowserContextOwnInstanceInIncognito(context
);