1 // Copyright (c) 2012 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/geolocation/geolocation_permission_context_factory.h"
7 #include "chrome/browser/profiles/incognito_helpers.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/common/pref_names.h"
10 #include "components/keyed_service/content/browser_context_dependency_manager.h"
11 #include "components/pref_registry/pref_registry_syncable.h"
12 #if defined(OS_ANDROID)
13 #include "chrome/browser/geolocation/geolocation_permission_context_android.h"
15 #include "chrome/browser/geolocation/geolocation_permission_context.h"
20 GeolocationPermissionContext
*
21 GeolocationPermissionContextFactory::GetForProfile(Profile
* profile
) {
22 return static_cast<GeolocationPermissionContext
*>(
23 GetInstance()->GetServiceForBrowserContext(profile
, true));
27 GeolocationPermissionContextFactory
*
28 GeolocationPermissionContextFactory::GetInstance() {
29 return Singleton
<GeolocationPermissionContextFactory
>::get();
32 #if !defined(OS_ANDROID)
33 GeolocationPermissionContextFactory::GeolocationPermissionContextFactory()
34 : BrowserContextKeyedServiceFactory(
35 "GeolocationPermissionContext",
36 BrowserContextDependencyManager::GetInstance()) {
39 GeolocationPermissionContextFactory::GeolocationPermissionContextFactory()
40 : BrowserContextKeyedServiceFactory(
41 "GeolocationPermissionContextAndroid",
42 BrowserContextDependencyManager::GetInstance()) {
47 GeolocationPermissionContextFactory::~GeolocationPermissionContextFactory() {
51 GeolocationPermissionContextFactory::BuildServiceInstanceFor(
52 content::BrowserContext
* profile
) const {
53 #if !defined(OS_ANDROID)
54 return new GeolocationPermissionContext(static_cast<Profile
*>(profile
));
56 return new GeolocationPermissionContextAndroid(
57 static_cast<Profile
*>(profile
));
61 void GeolocationPermissionContextFactory::RegisterProfilePrefs(
62 user_prefs::PrefRegistrySyncable
* registry
) {
63 #if defined(OS_ANDROID)
64 registry
->RegisterBooleanPref(prefs::kGeolocationEnabled
, true);
68 content::BrowserContext
*
69 GeolocationPermissionContextFactory::GetBrowserContextToUse(
70 content::BrowserContext
* context
) const {
71 return chrome::GetBrowserContextOwnInstanceInIncognito(context
);