Commit a877a7d2 authored by jknotten@chromium.org's avatar jknotten@chromium.org

Make ChromeGeolocationPermissionContextFactory a ProfileKeyedServiceFactory

content::GeolocationPermissionContext derives RefCountedThreadSafe, so
we can't mix a RefcountedProfileKeyedService into
ChromeGeolocationPermissionContextFactory. Instead, create a separate
ProfileKeyedService to hold the
scoped_refptr<GeolocationPermissionContext>.

Ground work for https://codereview.chromium.org/11590002/

TEST=Existing
BUG=155029

Review URL: https://chromiumcodereview.appspot.com/11587003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175521 0039d316-1c4b-4281-b951-d872f2087c98
parent b6e7b2b9
......@@ -4,6 +4,7 @@
#include "chrome/browser/geolocation/chrome_geolocation_permission_context_factory.h"
#include "chrome/browser/profiles/profile_dependency_manager.h"
#include "chrome/common/pref_names.h"
#if defined(OS_ANDROID)
#include "chrome/browser/geolocation/chrome_geolocation_permission_context_android.h"
......@@ -11,13 +12,58 @@
#include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
#endif
ChromeGeolocationPermissionContext*
ChromeGeolocationPermissionContextFactory::Create(Profile* profile) {
namespace {
class Service : public ProfileKeyedService {
public:
explicit Service(Profile* profile) {
#if defined(OS_ANDROID)
return new ChromeGeolocationPermissionContextAndroid(profile);
context_ = new ChromeGeolocationPermissionContextAndroid(profile);
#else
return new ChromeGeolocationPermissionContext(profile);
context_ = new ChromeGeolocationPermissionContext(profile);
#endif
}
ChromeGeolocationPermissionContext* context() {
return context_.get();
}
private:
scoped_refptr<ChromeGeolocationPermissionContext> context_;
DISALLOW_COPY_AND_ASSIGN(Service);
};
} // namespace
// static
ChromeGeolocationPermissionContext*
ChromeGeolocationPermissionContextFactory::GetForProfile(Profile* profile) {
return static_cast<Service*>(
GetInstance()->GetServiceForProfile(profile, true))->context();
}
// static
ChromeGeolocationPermissionContextFactory*
ChromeGeolocationPermissionContextFactory::GetInstance() {
return Singleton<ChromeGeolocationPermissionContextFactory>::get();
}
ChromeGeolocationPermissionContextFactory::
ChromeGeolocationPermissionContextFactory()
: ProfileKeyedServiceFactory(
"ChromeGeolocationPermissionContext",
ProfileDependencyManager::GetInstance()) {
}
ChromeGeolocationPermissionContextFactory::
~ChromeGeolocationPermissionContextFactory() {
}
ProfileKeyedService*
ChromeGeolocationPermissionContextFactory::BuildServiceInstanceFor(
Profile* profile) const {
return new Service(profile);
}
void ChromeGeolocationPermissionContextFactory::RegisterUserPrefs(
......@@ -28,3 +74,8 @@ void ChromeGeolocationPermissionContextFactory::RegisterUserPrefs(
PrefServiceSyncable::UNSYNCABLE_PREF);
#endif
}
bool ChromeGeolocationPermissionContextFactory::
ServiceRedirectedInIncognito() const {
return true;
}
......@@ -5,20 +5,33 @@
#ifndef CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_FACTORY_H_
#define CHROME_BROWSER_GEOLOCATION_CHROME_GEOLOCATION_PERMISSION_CONTEXT_FACTORY_H_
#include "base/memory/singleton.h"
#include "base/values.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile_keyed_service_factory.h"
class ChromeGeolocationPermissionContext;
class Profile;
class ChromeGeolocationPermissionContextFactory {
class ChromeGeolocationPermissionContextFactory
: public ProfileKeyedServiceFactory {
public:
ChromeGeolocationPermissionContextFactory() {}
~ChromeGeolocationPermissionContextFactory() {}
static ChromeGeolocationPermissionContext* Create(Profile* profile);
static void RegisterUserPrefs(PrefServiceSyncable* user_prefs);
static ChromeGeolocationPermissionContext* GetForProfile(Profile* profile);
static ChromeGeolocationPermissionContextFactory* GetInstance();
private:
friend struct
DefaultSingletonTraits<ChromeGeolocationPermissionContextFactory>;
ChromeGeolocationPermissionContextFactory();
virtual ~ChromeGeolocationPermissionContextFactory();
// |ProfileKeyedBaseFactory| methods:
virtual ProfileKeyedService*
BuildServiceInstanceFor(Profile* profile) const OVERRIDE;
virtual void RegisterUserPrefs(PrefServiceSyncable* user_prefs) OVERRIDE;
virtual bool ServiceRedirectedInIncognito() const OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(ChromeGeolocationPermissionContextFactory);
};
......
......@@ -264,7 +264,7 @@ void GeolocationPermissionContextTests::SetUp() {
MockGoogleLocationSettingsHelper::SetLocationStatus(true, true);
#endif
geolocation_permission_context_ =
ChromeGeolocationPermissionContextFactory::Create(profile());
ChromeGeolocationPermissionContextFactory::GetForProfile(profile());
}
void GeolocationPermissionContextTests::TearDown() {
......
......@@ -13,8 +13,4 @@ void RegisterPrefs(PrefServiceSimple* prefs) {
ChromeAccessTokenStore::RegisterPrefs(prefs);
}
void RegisterUserPrefs(PrefServiceSyncable* user_prefs) {
ChromeGeolocationPermissionContextFactory::RegisterUserPrefs(user_prefs);
}
} // namespace geolocation
......@@ -10,7 +10,6 @@ class PrefServiceSyncable;
namespace geolocation {
void RegisterPrefs(PrefServiceSimple* prefs);
void RegisterUserPrefs(PrefServiceSyncable* user_prefs);
}
#endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PREFS_H_
......@@ -270,7 +270,6 @@ void RegisterUserPrefs(PrefServiceSyncable* user_prefs) {
#endif
#if defined(OS_ANDROID)
geolocation::RegisterUserPrefs(user_prefs);
PromoHandler::RegisterUserPrefs(user_prefs);
#endif
......
......@@ -37,6 +37,7 @@
#include "chrome/browser/extensions/app_restore_service_factory.h"
#include "chrome/browser/extensions/extension_system_factory.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/geolocation/chrome_geolocation_permission_context_factory.h"
#include "chrome/browser/google/google_url_tracker_factory.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/history/shortcuts_backend_factory.h"
......@@ -234,6 +235,7 @@ void ProfileDependencyManager::AssertFactoriesBuilt() {
#if defined(ENABLE_CAPTIVE_PORTAL_DETECTION)
captive_portal::CaptivePortalServiceFactory::GetInstance();
#endif
ChromeGeolocationPermissionContextFactory::GetInstance();
ChromeURLDataManagerFactory::GetInstance();
#if defined(ENABLE_PRINTING)
CloudPrintProxyServiceFactory::GetInstance();
......
......@@ -851,11 +851,7 @@ HostContentSettingsMap* ProfileImpl::GetHostContentSettingsMap() {
content::GeolocationPermissionContext*
ProfileImpl::GetGeolocationPermissionContext() {
if (!geolocation_permission_context_.get()) {
geolocation_permission_context_ =
ChromeGeolocationPermissionContextFactory::Create(this);
}
return geolocation_permission_context_.get();
return ChromeGeolocationPermissionContextFactory::GetForProfile(this);
}
content::SpeechRecognitionPreferences*
......
......@@ -227,8 +227,6 @@ class ProfileImpl : public Profile,
scoped_ptr<NetPrefObserver> net_pref_observer_;
scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_;
scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
scoped_refptr<content::GeolocationPermissionContext>
geolocation_permission_context_;
scoped_refptr<history::ShortcutsBackend> shortcuts_backend_;
// Exit type the last time the profile was opened. This is set only once from
......
......@@ -664,11 +664,7 @@ HostContentSettingsMap* TestingProfile::GetHostContentSettingsMap() {
content::GeolocationPermissionContext*
TestingProfile::GetGeolocationPermissionContext() {
if (!geolocation_permission_context_.get()) {
geolocation_permission_context_ =
ChromeGeolocationPermissionContextFactory::Create(this);
}
return geolocation_permission_context_.get();
return ChromeGeolocationPermissionContextFactory::GetForProfile(this);
}
content::SpeechRecognitionPreferences*
......
......@@ -330,8 +330,6 @@ class TestingProfile : public Profile {
bool last_session_exited_cleanly_;
scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
scoped_refptr<content::GeolocationPermissionContext>
geolocation_permission_context_;
FilePath last_selected_directory_;
scoped_refptr<history::TopSites> top_sites_; // For history and thumbnails.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment