summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-04 15:17:40 +0000
committerbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-04 15:17:40 +0000
commitca75998f5f7c387dd2ff6a5d9155beb403bcce8a (patch)
tree9486e6564f23d93be605c53d3f052076a014a8ca
parente1457d5825f3609777651359ae424be65b75b0e4 (diff)
downloadchromium_src-ca75998f5f7c387dd2ff6a5d9155beb403bcce8a.zip
chromium_src-ca75998f5f7c387dd2ff6a5d9155beb403bcce8a.tar.gz
chromium_src-ca75998f5f7c387dd2ff6a5d9155beb403bcce8a.tar.bz2
Implemented GetOffTheRecordPrefs() for Profile
BUG=71679 TEST=none Review URL: http://codereview.chromium.org/6250107 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73805 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/profiles/profile.cc18
-rw-r--r--chrome/browser/profiles/profile.h7
-rw-r--r--chrome/browser/profiles/profile_impl.cc10
-rw-r--r--chrome/browser/profiles/profile_impl.h7
-rw-r--r--chrome/test/testing_profile.h5
5 files changed, 28 insertions, 19 deletions
diff --git a/chrome/browser/profiles/profile.cc b/chrome/browser/profiles/profile.cc
index eaa2e94..ac869eb 100644
--- a/chrome/browser/profiles/profile.cc
+++ b/chrome/browser/profiles/profile.cc
@@ -142,10 +142,8 @@ class OffTheRecordProfileImpl : public Profile,
public:
explicit OffTheRecordProfileImpl(Profile* real_profile)
: profile_(real_profile),
+ prefs_(real_profile->GetOffTheRecordPrefs()),
start_time_(Time::Now()) {
- prefs_.reset(profile_->GetPrefs()->CreateIncognitoPrefService(
- new ExtensionPrefStore(profile_->GetExtensionPrefValueMap(), true)));
-
request_context_ = ChromeURLRequestContextGetter::CreateOffTheRecord(this);
extension_process_manager_.reset(ExtensionProcessManager::Create(this));
@@ -330,7 +328,11 @@ class OffTheRecordProfileImpl : public Profile,
}
virtual PrefService* GetPrefs() {
- return prefs_.get();
+ return prefs_;
+ }
+
+ virtual PrefService* GetOffTheRecordPrefs() {
+ return prefs_;
}
virtual TemplateURLModel* GetTemplateURLModel() {
@@ -640,18 +642,14 @@ class OffTheRecordProfileImpl : public Profile,
return NULL;
}
- protected:
- virtual ExtensionPrefValueMap* GetExtensionPrefValueMap() {
- return profile_->GetExtensionPrefValueMap();
- }
-
private:
NotificationRegistrar registrar_;
// The real underlying profile.
Profile* profile_;
- scoped_ptr<PrefService> prefs_;
+ // Weak pointer owned by |profile_|.
+ PrefService* prefs_;
scoped_ptr<ExtensionProcessManager> extension_process_manager_;
diff --git a/chrome/browser/profiles/profile.h b/chrome/browser/profiles/profile.h
index 81c895e..3391c6b 100644
--- a/chrome/browser/profiles/profile.h
+++ b/chrome/browser/profiles/profile.h
@@ -290,6 +290,11 @@ class Profile {
// time that this method is called.
virtual PrefService* GetPrefs() = 0;
+ // Retrieves a pointer to the PrefService that manages the preferences
+ // for OffTheRecord Profiles. This PrefService is lazily created the first
+ // time that this method is called.
+ virtual PrefService* GetOffTheRecordPrefs() = 0;
+
// Returns the TemplateURLModel for this profile. This is owned by the
// the Profile.
virtual TemplateURLModel* GetTemplateURLModel() = 0;
@@ -568,8 +573,6 @@ class Profile {
static URLRequestContextGetter* default_request_context_;
- virtual ExtensionPrefValueMap* GetExtensionPrefValueMap() = 0;
-
private:
bool restored_last_session_;
diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc
index 6f6abfb..ad861b0 100644
--- a/chrome/browser/profiles/profile_impl.cc
+++ b/chrome/browser/profiles/profile_impl.cc
@@ -757,6 +757,16 @@ PrefService* ProfileImpl::GetPrefs() {
return prefs_.get();
}
+PrefService* ProfileImpl::GetOffTheRecordPrefs() {
+ if (!otr_prefs_.get()) {
+ // The new ExtensionPrefStore is ref_counted and the new PrefService
+ // stores a reference so that we do not leak memory here.
+ otr_prefs_.reset(GetPrefs()->CreateIncognitoPrefService(
+ new ExtensionPrefStore(GetExtensionPrefValueMap(), true)));
+ }
+ return otr_prefs_.get();
+}
+
FilePath ProfileImpl::GetPrefFilePath() {
FilePath pref_file_path = path_;
pref_file_path = pref_file_path.Append(chrome::kPreferencesFilename);
diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h
index ee36db5..acc0d5b 100644
--- a/chrome/browser/profiles/profile_impl.h
+++ b/chrome/browser/profiles/profile_impl.h
@@ -71,6 +71,7 @@ class ProfileImpl : public Profile,
virtual WebDataService* GetWebDataServiceWithoutCreating();
virtual PasswordStore* GetPasswordStore(ServiceAccessType sat);
virtual PrefService* GetPrefs();
+ virtual PrefService* GetOffTheRecordPrefs();
virtual TemplateURLModel* GetTemplateURLModel();
virtual TemplateURLFetcher* GetTemplateURLFetcher();
virtual DownloadManager* GetDownloadManager();
@@ -148,9 +149,6 @@ class ProfileImpl : public Profile,
// SpellCheckHostObserver implementation.
virtual void SpellCheckHostInitialized();
- protected:
- virtual ExtensionPrefValueMap* GetExtensionPrefValueMap();
-
private:
friend class Profile;
@@ -174,6 +172,8 @@ class ProfileImpl : public Profile,
void RegisterComponentExtensions();
void InstallDefaultApps();
+ ExtensionPrefValueMap* GetExtensionPrefValueMap();
+
NotificationRegistrar registrar_;
PrefChangeRegistrar pref_change_registrar_;
@@ -184,6 +184,7 @@ class ProfileImpl : public Profile,
// net_pref_observer_, web_resource_service_ and background_contents_service_
// store pointers to prefs_ and shall be destructed first.
scoped_ptr<PrefService> prefs_;
+ scoped_ptr<PrefService> otr_prefs_;
scoped_ptr<VisitedLinkEventListener> visited_link_event_listener_;
scoped_ptr<VisitedLinkMaster> visited_link_master_;
// Keep extension_prefs_ on top of extensions_service_ because the latter
diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h
index a9244b7..fc561d4 100644
--- a/chrome/test/testing_profile.h
+++ b/chrome/test/testing_profile.h
@@ -321,12 +321,9 @@ class TestingProfile : public Profile {
virtual PromoCounter* GetInstantPromoCounter() { return NULL; }
virtual policy::ProfilePolicyContext* GetPolicyContext() { return NULL; }
virtual PrerenderManager* GetPrerenderManager() { return NULL; }
+ virtual PrefService* GetOffTheRecordPrefs() { return NULL; }
protected:
- virtual ExtensionPrefValueMap* GetExtensionPrefValueMap() {
- return extension_pref_value_map_.get();
- }
-
base::Time start_time_;
scoped_ptr<PrefService> prefs_;
// ref only for right type, lifecycle is managed by prefs_