summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-05 17:24:57 +0000
committerbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-05 17:24:57 +0000
commit078bb91539d0ed72f6c40dcabd00eaeac4d239ff (patch)
tree139f80769ab83a7a7c39ccf6d012405782d720bf
parent49d198eaf7bd7b118fb46b97cc790fdc7b380eee (diff)
downloadchromium_src-078bb91539d0ed72f6c40dcabd00eaeac4d239ff.zip
chromium_src-078bb91539d0ed72f6c40dcabd00eaeac4d239ff.tar.gz
chromium_src-078bb91539d0ed72f6c40dcabd00eaeac4d239ff.tar.bz2
Get rid of PrefService::GetMutableDictionary/GetMutableList
BUG=77914 TEST=none, trybots remain green Review URL: http://codereview.chromium.org/6735032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80475 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/debugger/devtools_window.cc6
-rw-r--r--chrome/browser/ui/cocoa/browser_window_controller_private.mm5
-rw-r--r--chrome/browser/ui/cocoa/window_size_autosaver.mm18
-rw-r--r--chrome/browser/ui/cocoa/window_size_autosaver_unittest.mm8
-rw-r--r--chrome/browser/ui/gtk/browser_window_gtk.cc7
-rw-r--r--chrome/browser/ui/gtk/task_manager_gtk.cc7
-rw-r--r--chrome/browser/ui/views/chrome_views_delegate.cc5
-rw-r--r--chrome/browser/ui/views/task_manager_view.cc7
8 files changed, 38 insertions, 25 deletions
diff --git a/chrome/browser/debugger/devtools_window.cc b/chrome/browser/debugger/devtools_window.cc
index 5bb68db..7d3f1b9 100644
--- a/chrome/browser/debugger/devtools_window.cc
+++ b/chrome/browser/debugger/devtools_window.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/load_notification_details.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/tabs/tab_strip_model.h"
#include "chrome/browser/themes/theme_service.h"
@@ -230,8 +231,9 @@ void DevToolsWindow::CreateDevToolsBrowser() {
}
const DictionaryValue* wp_pref = prefs->GetDictionary(wp_key.c_str());
- if (!wp_pref) {
- DictionaryValue* defaults = prefs->GetMutableDictionary(wp_key.c_str());
+ if (!wp_pref || wp_pref->empty()) {
+ DictionaryPrefUpdate update(prefs, wp_key.c_str());
+ DictionaryValue* defaults = update.Get();
defaults->SetInteger("left", 100);
defaults->SetInteger("top", 100);
defaults->SetInteger("right", 740);
diff --git a/chrome/browser/ui/cocoa/browser_window_controller_private.mm b/chrome/browser/ui/cocoa/browser_window_controller_private.mm
index e26a64d..2eac331 100644
--- a/chrome/browser/ui/cocoa/browser_window_controller_private.mm
+++ b/chrome/browser/ui/cocoa/browser_window_controller_private.mm
@@ -8,6 +8,7 @@
#import "base/memory/scoped_nsobject.h"
#include "chrome/browser/browser_process.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_list.h"
#import "chrome/browser/ui/cocoa/fast_resize_view.h"
@@ -116,8 +117,8 @@ enum {
if (browser_->ShouldSaveWindowPlacement())
browser_->SaveWindowPlacement(bounds, /*maximized=*/ false);
- DictionaryValue* windowPreferences = prefs->GetMutableDictionary(
- browser_->GetWindowPlacementKey().c_str());
+ DictionaryPrefUpdate update(prefs, browser_->GetWindowPlacementKey().c_str());
+ DictionaryValue* windowPreferences = update.Get();
windowPreferences->SetInteger("left", bounds.x());
windowPreferences->SetInteger("top", bounds.y());
windowPreferences->SetInteger("right", bounds.right());
diff --git a/chrome/browser/ui/cocoa/window_size_autosaver.mm b/chrome/browser/ui/cocoa/window_size_autosaver.mm
index 5ca9878..267a830 100644
--- a/chrome/browser/ui/cocoa/window_size_autosaver.mm
+++ b/chrome/browser/ui/cocoa/window_size_autosaver.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,6 +7,7 @@
#import "chrome/browser/ui/cocoa/window_size_autosaver.h"
#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/prefs/scoped_user_pref_update.h"
// If the window width stored in the prefs is smaller than this, the size is
// not restored but instead cleared from the profile -- to protect users from
@@ -52,7 +53,8 @@ const int kMinWindowHeight = 17;
}
- (void)save:(NSNotification*)notification {
- DictionaryValue* windowPrefs = prefService_->GetMutableDictionary(path_);
+ DictionaryPrefUpdate update(prefService_, path_);
+ DictionaryValue* windowPrefs = update.Get();
NSRect frame = [window_ frame];
if ([window_ styleMask] & NSResizableWindowMask) {
// Save the origin of the window.
@@ -72,7 +74,7 @@ const int kMinWindowHeight = 17;
- (void)restore {
// Get the positioning information.
- DictionaryValue* windowPrefs = prefService_->GetMutableDictionary(path_);
+ const DictionaryValue* windowPrefs = prefService_->GetDictionary(path_);
if ([window_ styleMask] & NSResizableWindowMask) {
int x1, x2, y1, y2;
if (!windowPrefs->GetInteger("left", &x1) ||
@@ -83,10 +85,12 @@ const int kMinWindowHeight = 17;
}
if (x2 - x1 < kMinWindowWidth || y2 - y1 < kMinWindowHeight) {
// Windows should never be very small.
- windowPrefs->Remove("left", NULL);
- windowPrefs->Remove("right", NULL);
- windowPrefs->Remove("top", NULL);
- windowPrefs->Remove("bottom", NULL);
+ DictionaryPrefUpdate update(prefService_, path_);
+ DictionaryValue* mutableWindowPrefs = update.Get();
+ mutableWindowPrefs->Remove("left", NULL);
+ mutableWindowPrefs->Remove("right", NULL);
+ mutableWindowPrefs->Remove("top", NULL);
+ mutableWindowPrefs->Remove("bottom", NULL);
} else {
[window_ setFrame:NSMakeRect(x1, y1, x2 - x1, y2 - y1) display:YES];
diff --git a/chrome/browser/ui/cocoa/window_size_autosaver_unittest.mm b/chrome/browser/ui/cocoa/window_size_autosaver_unittest.mm
index 09b13f5..7b93717 100644
--- a/chrome/browser/ui/cocoa/window_size_autosaver_unittest.mm
+++ b/chrome/browser/ui/cocoa/window_size_autosaver_unittest.mm
@@ -8,6 +8,7 @@
#include "base/memory/scoped_nsobject.h"
#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/ui/cocoa/browser_test_helper.h"
#import "chrome/browser/ui/cocoa/cocoa_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -95,7 +96,7 @@ TEST_F(WindowSizeAutosaverTest, RestoresAndSavesPos) {
// ...and it should be in the profile, too.
EXPECT_TRUE(pref->GetDictionary(path_) != NULL);
int x, y;
- DictionaryValue* windowPref = pref->GetMutableDictionary(path_);
+ const DictionaryValue* windowPref = pref->GetDictionary(path_);
EXPECT_FALSE(windowPref->GetInteger("left", &x));
EXPECT_FALSE(windowPref->GetInteger("right", &x));
EXPECT_FALSE(windowPref->GetInteger("top", &x));
@@ -154,7 +155,7 @@ TEST_F(WindowSizeAutosaverTest, RestoresAndSavesRect) {
// ...and it should be in the profile, too.
EXPECT_TRUE(pref->GetDictionary(path_) != NULL);
int x1, y1, x2, y2;
- DictionaryValue* windowPref = pref->GetMutableDictionary(path_);
+ const DictionaryValue* windowPref = pref->GetDictionary(path_);
EXPECT_FALSE(windowPref->GetInteger("x", &x1));
EXPECT_FALSE(windowPref->GetInteger("y", &x1));
ASSERT_TRUE(windowPref->GetInteger("left", &x1));
@@ -172,7 +173,8 @@ TEST_F(WindowSizeAutosaverTest, DoesNotRestoreButClearsEmptyRect) {
PrefService* pref = browser_helper_.profile()->GetPrefs();
ASSERT_TRUE(pref != NULL);
- DictionaryValue* windowPref = pref->GetMutableDictionary(path_);
+ DictionaryPrefUpdate update(pref, path_);
+ DictionaryValue* windowPref = update.Get();
windowPref->SetInteger("left", 50);
windowPref->SetInteger("right", 50);
windowPref->SetInteger("top", 60);
diff --git a/chrome/browser/ui/gtk/browser_window_gtk.cc b/chrome/browser/ui/gtk/browser_window_gtk.cc
index a3b8943..0bb8c8c 100644
--- a/chrome/browser/ui/gtk/browser_window_gtk.cc
+++ b/chrome/browser/ui/gtk/browser_window_gtk.cc
@@ -29,6 +29,7 @@
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/page_info_window.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/tabs/tab_strip_model.h"
#include "chrome/browser/themes/theme_service.h"
@@ -1786,9 +1787,9 @@ void BrowserWindowGtk::SaveWindowPosition() {
return;
std::string window_name = browser_->GetWindowPlacementKey();
- DictionaryValue* window_preferences =
- browser_->profile()->GetPrefs()->
- GetMutableDictionary(window_name.c_str());
+ DictionaryPrefUpdate update(browser_->profile()->GetPrefs(),
+ window_name.c_str());
+ DictionaryValue* window_preferences = update.Get();
// Note that we store left/top for consistency with Windows, but that we
// *don't* obey them; we only use them for computing width/height. See
// comments in SetGeometryHints().
diff --git a/chrome/browser/ui/gtk/task_manager_gtk.cc b/chrome/browser/ui/gtk/task_manager_gtk.cc
index d137122..b5d4ecf 100644
--- a/chrome/browser/ui/gtk/task_manager_gtk.cc
+++ b/chrome/browser/ui/gtk/task_manager_gtk.cc
@@ -19,6 +19,7 @@
#include "chrome/browser/defaults.h"
#include "chrome/browser/memory_purger.h"
#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/ui/gtk/gtk_chrome_link_button.h"
#include "chrome/browser/ui/gtk/gtk_theme_service.h"
#include "chrome/browser/ui/gtk/gtk_tree.h"
@@ -863,9 +864,9 @@ void TaskManagerGtk::OnResponse(GtkWidget* dialog, int response_id) {
if (g_browser_process->local_state()) {
gfx::Rect dialog_bounds = gtk_util::GetDialogBounds(GTK_WIDGET(dialog));
- DictionaryValue* placement_pref =
- g_browser_process->local_state()->GetMutableDictionary(
- prefs::kTaskManagerWindowPlacement);
+ DictionaryPrefUpdate update(g_browser_process->local_state(),
+ prefs::kTaskManagerWindowPlacement);
+ DictionaryValue* placement_pref = update.Get();
// Note that we store left/top for consistency with Windows, but that we
// *don't* restore them.
placement_pref->SetInteger("left", dialog_bounds.x());
diff --git a/chrome/browser/ui/views/chrome_views_delegate.cc b/chrome/browser/ui/views/chrome_views_delegate.cc
index 35b5bc3..cd63fab 100644
--- a/chrome/browser/ui/views/chrome_views_delegate.cc
+++ b/chrome/browser/ui/views/chrome_views_delegate.cc
@@ -9,6 +9,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/views/accessibility_event_router_views.h"
#include "chrome/browser/ui/window_sizer.h"
@@ -60,8 +61,8 @@ void ChromeViewsDelegate::SaveWindowPlacement(views::Window* window,
return;
DCHECK(prefs->FindPreference(WideToUTF8(window_name).c_str()));
- DictionaryValue* window_preferences =
- prefs->GetMutableDictionary(WideToUTF8(window_name).c_str());
+ DictionaryPrefUpdate update(prefs, WideToUTF8(window_name).c_str());
+ DictionaryValue* window_preferences = update.Get();
window_preferences->SetInteger("left", bounds.x());
window_preferences->SetInteger("top", bounds.y());
window_preferences->SetInteger("right", bounds.right());
diff --git a/chrome/browser/ui/views/task_manager_view.cc b/chrome/browser/ui/views/task_manager_view.cc
index d74cc2d..7f60b45 100644
--- a/chrome/browser/ui/views/task_manager_view.cc
+++ b/chrome/browser/ui/views/task_manager_view.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/browser_window.h"
#include "chrome/browser/memory_purger.h"
#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/prefs/scoped_user_pref_update.h"
#include "chrome/browser/ui/views/browser_dialogs.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
@@ -622,9 +623,9 @@ bool TaskManagerView::ExecuteWindowsCommand(int command_id) {
// Save the state.
if (g_browser_process->local_state()) {
- DictionaryValue* window_preferences =
- g_browser_process->local_state()->GetMutableDictionary(
- WideToUTF8(GetWindowName()).c_str());
+ DictionaryPrefUpdate update(g_browser_process->local_state(),
+ WideToUTF8(GetWindowName()).c_str());
+ DictionaryValue* window_preferences = update.Get();
window_preferences->SetBoolean("always_on_top", is_always_on_top_);
}
return true;