Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(501)

Side by Side Diff: chrome/browser/geolocation/geolocation_permission_context_factory.cc

Issue 459953002: Migrate geolocation permissions to the new common permission class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/geolocation/geolocation_permission_context_factory.h" 5 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
6 6
7 #include "chrome/browser/profiles/incognito_helpers.h" 7 #include "chrome/browser/profiles/incognito_helpers.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/common/pref_names.h" 9 #include "chrome/common/pref_names.h"
10 #include "components/keyed_service/content/browser_context_dependency_manager.h" 10 #include "components/keyed_service/content/browser_context_dependency_manager.h"
11 #include "components/pref_registry/pref_registry_syncable.h" 11 #include "components/pref_registry/pref_registry_syncable.h"
12 #if defined(OS_ANDROID) 12 #if defined(OS_ANDROID)
13 #include "chrome/browser/geolocation/geolocation_permission_context_android.h" 13 #include "chrome/browser/geolocation/geolocation_permission_context_android.h"
14 #else 14 #else
15 #include "chrome/browser/geolocation/geolocation_permission_context.h" 15 #include "chrome/browser/geolocation/geolocation_permission_context.h"
16 #endif 16 #endif
17 17
18 namespace {
19
20 class Service : public KeyedService {
21 public:
22 explicit Service(Profile* profile) {
23 #if defined(OS_ANDROID)
24 context_ = new GeolocationPermissionContextAndroid(profile);
25 #else
26 context_ = new GeolocationPermissionContext(profile);
27 #endif
28 }
29
30 GeolocationPermissionContext* context() {
31 return context_.get();
32 }
33
34 virtual void Shutdown() OVERRIDE {
35 context()->ShutdownOnUIThread();
36 }
37
38 private:
39 scoped_refptr<GeolocationPermissionContext> context_;
40
41 DISALLOW_COPY_AND_ASSIGN(Service);
42 };
43
44 } // namespace
45 18
46 // static 19 // static
47 GeolocationPermissionContext* 20 GeolocationPermissionContext*
48 GeolocationPermissionContextFactory::GetForProfile(Profile* profile) { 21 GeolocationPermissionContextFactory::GetForProfile(Profile* profile) {
49 return static_cast<Service*>( 22 return static_cast<GeolocationPermissionContext*>(
50 GetInstance()->GetServiceForBrowserContext(profile, true))->context(); 23 GetInstance()->GetServiceForBrowserContext(profile, true));
51 } 24 }
52 25
53 // static 26 // static
54 GeolocationPermissionContextFactory* 27 GeolocationPermissionContextFactory*
55 GeolocationPermissionContextFactory::GetInstance() { 28 GeolocationPermissionContextFactory::GetInstance() {
56 return Singleton<GeolocationPermissionContextFactory>::get(); 29 return Singleton<GeolocationPermissionContextFactory>::get();
57 } 30 }
58 31
32 #if !defined(OS_ANDROID)
59 GeolocationPermissionContextFactory::GeolocationPermissionContextFactory() 33 GeolocationPermissionContextFactory::GeolocationPermissionContextFactory()
60 : BrowserContextKeyedServiceFactory( 34 : BrowserContextKeyedServiceFactory(
61 "GeolocationPermissionContext", 35 "GeolocationPermissionContext",
62 BrowserContextDependencyManager::GetInstance()) { 36 BrowserContextDependencyManager::GetInstance()) {
63 } 37 }
38 #else
39 GeolocationPermissionContextFactory::GeolocationPermissionContextFactory()
40 : BrowserContextKeyedServiceFactory(
41 "GeolocationPermissionContextAndroid",
42 BrowserContextDependencyManager::GetInstance()) {
43 }
44 #endif
45
64 46
65 GeolocationPermissionContextFactory::~GeolocationPermissionContextFactory() { 47 GeolocationPermissionContextFactory::~GeolocationPermissionContextFactory() {
66 } 48 }
67 49
68 KeyedService* 50 KeyedService*
69 GeolocationPermissionContextFactory::BuildServiceInstanceFor( 51 GeolocationPermissionContextFactory::BuildServiceInstanceFor(
70 content::BrowserContext* profile) const { 52 content::BrowserContext* profile) const {
71 return new Service(static_cast<Profile*>(profile)); 53 #if !defined(OS_ANDROID)
54 return new GeolocationPermissionContext(static_cast<Profile*>(profile));
55 #else
56 return new GeolocationPermissionContextAndroid(
57 static_cast<Profile*>(profile));
58 #endif
72 } 59 }
73 60
74 void GeolocationPermissionContextFactory::RegisterProfilePrefs( 61 void GeolocationPermissionContextFactory::RegisterProfilePrefs(
75 user_prefs::PrefRegistrySyncable* registry) { 62 user_prefs::PrefRegistrySyncable* registry) {
76 #if defined(OS_ANDROID) 63 #if defined(OS_ANDROID)
77 registry->RegisterBooleanPref( 64 registry->RegisterBooleanPref(
78 prefs::kGeolocationEnabled, 65 prefs::kGeolocationEnabled,
79 true, 66 true,
80 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 67 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
81 #endif 68 #endif
82 } 69 }
83 70
84 content::BrowserContext* 71 content::BrowserContext*
85 GeolocationPermissionContextFactory::GetBrowserContextToUse( 72 GeolocationPermissionContextFactory::GetBrowserContextToUse(
86 content::BrowserContext* context) const { 73 content::BrowserContext* context) const {
87 return chrome::GetBrowserContextOwnInstanceInIncognito(context); 74 return chrome::GetBrowserContextOwnInstanceInIncognito(context);
88 } 75 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698