summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-31 09:18:43 +0000
committerbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-31 09:18:43 +0000
commitf33bee52a41f7f4576ad43ff057fe0f99a2ad4b2 (patch)
tree9a2d878102e25905da980ac50277d850421ab0ef
parent8a59ccc18ce9c39965e2c04429d314d7156d033b (diff)
downloadchromium_src-f33bee52a41f7f4576ad43ff057fe0f99a2ad4b2.zip
chromium_src-f33bee52a41f7f4576ad43ff057fe0f99a2ad4b2.tar.gz
chromium_src-f33bee52a41f7f4576ad43ff057fe0f99a2ad4b2.tar.bz2
Get rid of PrefService::GetMutableDictionary/GetMutableList
BUG=77914 TEST=none, trybots remain green Review URL: http://codereview.chromium.org/6779001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79976 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/background_contents_service.cc10
-rw-r--r--chrome/browser/background_contents_service_unittest.cc19
-rw-r--r--chrome/browser/background_page_tracker.cc23
3 files changed, 28 insertions, 24 deletions
diff --git a/chrome/browser/background_contents_service.cc b/chrome/browser/background_contents_service.cc
index fd88660..4c63bdc 100644
--- a/chrome/browser/background_contents_service.cc
+++ b/chrome/browser/background_contents_service.cc
@@ -11,6 +11,7 @@
#include "base/values.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
@@ -236,8 +237,8 @@ void BackgroundContentsService::RegisterBackgroundContents(
// already an entry for this application, no need to do anything.
// TODO(atwilson): Verify that this is the desired behavior based on developer
// feedback (http://crbug.com/47118).
- DictionaryValue* pref = prefs_->GetMutableDictionary(
- prefs::kRegisteredBackgroundContents);
+ DictionaryPrefUpdate update(prefs_, prefs::kRegisteredBackgroundContents);
+ DictionaryValue* pref = update.Get();
const string16& appid = GetParentApplicationId(background_contents);
DictionaryValue* current;
if (pref->GetDictionaryWithoutPathExpansion(UTF16ToUTF8(appid), &current))
@@ -257,9 +258,8 @@ void BackgroundContentsService::UnregisterBackgroundContents(
return;
DCHECK(IsTracked(background_contents));
const string16 appid = GetParentApplicationId(background_contents);
- DictionaryValue* pref = prefs_->GetMutableDictionary(
- prefs::kRegisteredBackgroundContents);
- pref->RemoveWithoutPathExpansion(UTF16ToUTF8(appid), NULL);
+ DictionaryPrefUpdate update(prefs_, prefs::kRegisteredBackgroundContents);
+ update.Get()->RemoveWithoutPathExpansion(UTF16ToUTF8(appid), NULL);
prefs_->ScheduleSavePersistentPrefs();
}
diff --git a/chrome/browser/background_contents_service_unittest.cc b/chrome/browser/background_contents_service_unittest.cc
index 0cb1080..a4aca14 100644
--- a/chrome/browser/background_contents_service_unittest.cc
+++ b/chrome/browser/background_contents_service_unittest.cc
@@ -11,6 +11,7 @@
#include "chrome/browser/background_contents_service.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/tab_contents/background_contents.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/testing_browser_process.h"
@@ -28,14 +29,18 @@ class BackgroundContentsServiceTest : public TestingBrowserProcessTest {
command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM));
}
- DictionaryValue* GetPrefs(Profile* profile) {
- return profile->GetPrefs()->GetMutableDictionary(
+ const DictionaryValue* GetPrefs(Profile* profile) {
+ return profile->GetPrefs()->GetDictionary(
prefs::kRegisteredBackgroundContents);
}
+ void ClearPrefs(Profile* profile) {
+ profile->GetPrefs()->ClearPref(prefs::kRegisteredBackgroundContents);
+ }
+
// Returns the stored pref URL for the passed app id.
std::string GetPrefURLForApp(Profile* profile, const string16& appid) {
- DictionaryValue* pref = GetPrefs(profile);
+ const DictionaryValue* pref = GetPrefs(profile);
EXPECT_TRUE(pref->HasKey(UTF16ToUTF8(appid)));
DictionaryValue* value;
pref->GetDictionaryWithoutPathExpansion(UTF16ToUTF8(appid), &value);
@@ -120,7 +125,7 @@ TEST_F(BackgroundContentsServiceTest, BackgroundContentsCreateDestroy) {
TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAdded) {
TestingProfile profile;
- GetPrefs(&profile)->Clear();
+ ClearPrefs(&profile);
BackgroundContentsService service(&profile, command_line_.get());
GURL orig_url;
GURL url("http://a/");
@@ -146,7 +151,7 @@ TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAdded) {
TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAddedAndClosed) {
TestingProfile profile;
- GetPrefs(&profile)->Clear();
+ ClearPrefs(&profile);
BackgroundContentsService service(&profile, command_line_.get());
GURL url("http://a/");
MockBackgroundContents* contents = new MockBackgroundContents(&profile);
@@ -165,7 +170,7 @@ TEST_F(BackgroundContentsServiceTest, BackgroundContentsUrlAddedAndClosed) {
// crash) then is restarted. Should not persist URL twice.
TEST_F(BackgroundContentsServiceTest, RestartBackgroundContents) {
TestingProfile profile;
- GetPrefs(&profile)->Clear();
+ ClearPrefs(&profile);
BackgroundContentsService service(&profile, command_line_.get());
GURL url("http://a/");
{
@@ -196,7 +201,7 @@ TEST_F(BackgroundContentsServiceTest, RestartBackgroundContents) {
TEST_F(BackgroundContentsServiceTest, TestApplicationIDLinkage) {
TestingProfile profile;
BackgroundContentsService service(&profile, command_line_.get());
- GetPrefs(&profile)->Clear();
+ ClearPrefs(&profile);
EXPECT_EQ(NULL, service.GetAppBackgroundContents(ASCIIToUTF16("appid")));
MockBackgroundContents* contents = new MockBackgroundContents(&profile,
diff --git a/chrome/browser/background_page_tracker.cc b/chrome/browser/background_page_tracker.cc
index 5534bbe..5c52ea0 100644
--- a/chrome/browser/background_page_tracker.cc
+++ b/chrome/browser/background_page_tracker.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/extensions/extension.h"
@@ -84,10 +85,8 @@ void BackgroundPageTracker::AcknowledgeBackgroundPages() {
if (!IsEnabled())
return;
PrefService* prefs = GetPrefService();
- DictionaryValue* contents =
- prefs->GetMutableDictionary(prefs::kKnownBackgroundPages);
- if (!contents)
- return;
+ DictionaryPrefUpdate update(prefs, prefs::kKnownBackgroundPages);
+ DictionaryValue* contents = update.Get();
bool prefs_modified = false;
for (DictionaryValue::key_iterator it = contents->begin_keys();
it != contents->end_keys(); ++it) {
@@ -194,8 +193,8 @@ bool BackgroundPageTracker::UpdateExtensionList() {
// want to automatically mark all existing extensions as acknowledged.
bool first_launch =
prefs->GetDictionary(prefs::kKnownBackgroundPages) == NULL;
- DictionaryValue* contents =
- prefs->GetMutableDictionary(prefs::kKnownBackgroundPages);
+ DictionaryPrefUpdate update(prefs, prefs::kKnownBackgroundPages);
+ DictionaryValue* contents = update.Get();
for (DictionaryValue::key_iterator it = contents->begin_keys();
it != contents->end_keys(); ++it) {
// Check to make sure that the parent extension is still enabled.
@@ -266,10 +265,10 @@ bool BackgroundPageTracker::UpdateExtensionList() {
void BackgroundPageTracker::OnBackgroundPageLoaded(const std::string& id) {
DCHECK(IsEnabled());
PrefService* prefs = GetPrefService();
- DictionaryValue* contents =
- prefs->GetMutableDictionary(prefs::kKnownBackgroundPages);
+ DictionaryPrefUpdate update(prefs, prefs::kKnownBackgroundPages);
+ DictionaryValue* contents = update.Get();
// No need to update our list if this extension was already known.
- if (!contents || contents->HasKey(id))
+ if (contents->HasKey(id))
return;
// Update our list with this new as-yet-unacknowledged page.
@@ -281,10 +280,10 @@ void BackgroundPageTracker::OnBackgroundPageLoaded(const std::string& id) {
void BackgroundPageTracker::OnExtensionUnloaded(const std::string& id) {
DCHECK(IsEnabled());
PrefService* prefs = GetPrefService();
- DictionaryValue* contents =
- prefs->GetMutableDictionary(prefs::kKnownBackgroundPages);
+ DictionaryPrefUpdate update(prefs, prefs::kKnownBackgroundPages);
+ DictionaryValue* contents = update.Get();
- if (!contents || !contents->HasKey(id))
+ if (!contents->HasKey(id))
return;
contents->RemoveWithoutPathExpansion(id, NULL);