| 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 static_cast<ChromeGeolocationPermissionContext*>(context_.get()); |
| 29 } |
| 30 |
| 31 private: |
| 32 scoped_refptr<content::GeolocationPermissionContext> context_; |
| 33 }; |
| 34 |
| 35 } // namespace |
| 36 |
| 37 // static |
| 14 ChromeGeolocationPermissionContext* | 38 ChromeGeolocationPermissionContext* |
| 15 ChromeGeolocationPermissionContextFactory::Create(Profile* profile) { | 39 ChromeGeolocationPermissionContextFactory::GetForProfile(Profile* profile) { |
| 16 #if defined(OS_ANDROID) | 40 return static_cast<Service*>( |
| 17 return new ChromeGeolocationPermissionContextAndroid(profile); | 41 GetInstance()->GetServiceForProfile(profile, true))->context(); |
| 18 #else | 42 } |
| 19 return new ChromeGeolocationPermissionContext(profile); | 43 |
| 20 #endif | 44 // static |
| 45 ChromeGeolocationPermissionContextFactory* |
| 46 ChromeGeolocationPermissionContextFactory::GetInstance() { |
| 47 return Singleton<ChromeGeolocationPermissionContextFactory>::get(); |
| 48 } |
| 49 |
| 50 ChromeGeolocationPermissionContextFactory:: |
| 51 ChromeGeolocationPermissionContextFactory() |
| 52 : ProfileKeyedServiceFactory( |
| 53 "ChromeGeolocationPermissionContext", |
| 54 ProfileDependencyManager::GetInstance()) { |
| 55 } |
| 56 |
| 57 ChromeGeolocationPermissionContextFactory:: |
| 58 ~ChromeGeolocationPermissionContextFactory() { |
| 59 } |
| 60 |
| 61 ProfileKeyedService* |
| 62 ChromeGeolocationPermissionContextFactory::BuildServiceInstanceFor( |
| 63 Profile* profile) const { |
| 64 return new Service(profile); |
| 21 } | 65 } |
| 22 | 66 |
| 23 void ChromeGeolocationPermissionContextFactory::RegisterUserPrefs( | 67 void ChromeGeolocationPermissionContextFactory::RegisterUserPrefs( |
| 24 PrefService* user_prefs) { | 68 PrefService* user_prefs) { |
| 25 #if defined(OS_ANDROID) | 69 #if defined(OS_ANDROID) |
| 26 user_prefs->RegisterBooleanPref(prefs::kGeolocationEnabled, | 70 user_prefs->RegisterBooleanPref(prefs::kGeolocationEnabled, |
| 27 true, | 71 true, |
| 28 PrefService::UNSYNCABLE_PREF); | 72 PrefService::UNSYNCABLE_PREF); |
| 29 #endif | 73 #endif |
| 30 } | 74 } |
| OLD | NEW |