OLD | NEW |
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/chrome_geolocation_permission_context_facto
ry.h" | 5 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_facto
ry.h" |
6 | 6 |
| 7 #include "chrome/browser/profiles/profile_dependency_manager.h" |
7 #include "chrome/common/pref_names.h" | 8 #include "chrome/common/pref_names.h" |
8 #if defined(OS_ANDROID) | 9 #if defined(OS_ANDROID) |
9 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_andro
id.h" | 10 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_andro
id.h" |
10 #else | 11 #else |
11 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" | 12 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" |
12 #endif | 13 #endif |
13 | 14 |
| 15 namespace { |
| 16 |
| 17 class Service : public ProfileKeyedService { |
| 18 public: |
| 19 explicit Service(Profile* profile) { |
| 20 #if defined(OS_ANDROID) |
| 21 context_ = new ChromeGeolocationPermissionContextAndroid(profile); |
| 22 #else |
| 23 context_ = new ChromeGeolocationPermissionContext(profile); |
| 24 #endif |
| 25 } |
| 26 |
| 27 ChromeGeolocationPermissionContext* context() { |
| 28 return context_.get(); |
| 29 } |
| 30 |
| 31 private: |
| 32 scoped_refptr<ChromeGeolocationPermissionContext> context_; |
| 33 |
| 34 DISALLOW_COPY_AND_ASSIGN(Service); |
| 35 }; |
| 36 |
| 37 } // namespace |
| 38 |
| 39 // static |
14 ChromeGeolocationPermissionContext* | 40 ChromeGeolocationPermissionContext* |
15 ChromeGeolocationPermissionContextFactory::Create(Profile* profile) { | 41 ChromeGeolocationPermissionContextFactory::GetForProfile(Profile* profile) { |
16 #if defined(OS_ANDROID) | 42 return static_cast<Service*>( |
17 return new ChromeGeolocationPermissionContextAndroid(profile); | 43 GetInstance()->GetServiceForProfile(profile, true))->context(); |
18 #else | 44 } |
19 return new ChromeGeolocationPermissionContext(profile); | 45 |
20 #endif | 46 // static |
| 47 ChromeGeolocationPermissionContextFactory* |
| 48 ChromeGeolocationPermissionContextFactory::GetInstance() { |
| 49 return Singleton<ChromeGeolocationPermissionContextFactory>::get(); |
| 50 } |
| 51 |
| 52 ChromeGeolocationPermissionContextFactory:: |
| 53 ChromeGeolocationPermissionContextFactory() |
| 54 : ProfileKeyedServiceFactory( |
| 55 "ChromeGeolocationPermissionContext", |
| 56 ProfileDependencyManager::GetInstance()) { |
| 57 } |
| 58 |
| 59 ChromeGeolocationPermissionContextFactory:: |
| 60 ~ChromeGeolocationPermissionContextFactory() { |
| 61 } |
| 62 |
| 63 ProfileKeyedService* |
| 64 ChromeGeolocationPermissionContextFactory::BuildServiceInstanceFor( |
| 65 Profile* profile) const { |
| 66 return new Service(profile); |
21 } | 67 } |
22 | 68 |
23 void ChromeGeolocationPermissionContextFactory::RegisterUserPrefs( | 69 void ChromeGeolocationPermissionContextFactory::RegisterUserPrefs( |
24 PrefServiceSyncable* user_prefs) { | 70 PrefServiceSyncable* user_prefs) { |
25 #if defined(OS_ANDROID) | 71 #if defined(OS_ANDROID) |
26 user_prefs->RegisterBooleanPref(prefs::kGeolocationEnabled, | 72 user_prefs->RegisterBooleanPref(prefs::kGeolocationEnabled, |
27 true, | 73 true, |
28 PrefServiceSyncable::UNSYNCABLE_PREF); | 74 PrefServiceSyncable::UNSYNCABLE_PREF); |
29 #endif | 75 #endif |
30 } | 76 } |
| 77 |
| 78 bool ChromeGeolocationPermissionContextFactory:: |
| 79 ServiceRedirectedInIncognito() const { |
| 80 return true; |
| 81 } |
OLD | NEW |