diff options
author | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-21 18:18:45 +0000 |
---|---|---|
committer | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-21 18:18:45 +0000 |
commit | 0ffba0eb5bcda99b2802aef9fd3180b13ff75961 (patch) | |
tree | 7a5bbfa5df719a4720761facaf86f1b37f0e732c /chrome/browser/ui | |
parent | 0649c7b3862bf1a800809b846ddde17b3e036ca7 (diff) | |
download | chromium_src-0ffba0eb5bcda99b2802aef9fd3180b13ff75961.zip chromium_src-0ffba0eb5bcda99b2802aef9fd3180b13ff75961.tar.gz chromium_src-0ffba0eb5bcda99b2802aef9fd3180b13ff75961.tar.bz2 |
Remove user-related data from local_state and add to user_preferences, in preparation for multi-profile.
devtools
kDevToolsSplitLocation
browser
kBrowserWindowPlacement
Also add a method to browser_prefs to delete obsolete preferences from local state, and fix all related tests.
BUG=66717
TEST=all browser, interactive, and ui tests work properly
Review URL: http://codereview.chromium.org/5915006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@72153 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r-- | chrome/browser/ui/browser.cc | 21 | ||||
-rw-r--r-- | chrome/browser/ui/browser.h | 7 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/browser_window_controller.mm | 6 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/browser_window_controller_private.mm | 7 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/browser_window_controller_unittest.mm | 4 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/dev_tools_controller.h | 6 | ||||
-rw-r--r-- | chrome/browser/ui/cocoa/dev_tools_controller.mm | 19 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/browser_window_gtk.cc | 14 | ||||
-rw-r--r-- | chrome/browser/ui/views/chrome_views_delegate.cc | 20 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_view.cc | 8 | ||||
-rw-r--r-- | chrome/browser/ui/window_sizer.cc | 19 | ||||
-rw-r--r-- | chrome/browser/ui/window_sizer.h | 5 |
12 files changed, 73 insertions, 63 deletions
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index c733bf1..f46ee08 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -543,7 +543,7 @@ TabContents* Browser::OpenApplicationWindow( else app_name = web_app::GenerateApplicationNameFromURL(url); - RegisterAppPrefs(app_name); + RegisterAppPrefs(app_name, profile); bool as_panel = extension && (container == extension_misc::LAUNCH_PANEL); @@ -739,7 +739,7 @@ gfx::Rect Browser::GetSavedWindowBounds() const { gfx::Rect restored_bounds = override_bounds_; bool maximized; - WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, NULL, + WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, this, &restored_bounds, &maximized); return restored_bounds; } @@ -758,7 +758,7 @@ bool Browser::GetSavedMaximizedState() const { // An explicit maximized state was not set. Query the window sizer. gfx::Rect restored_bounds; bool maximized = false; - WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, NULL, + WindowSizer::GetBrowserWindowBounds(app_name_, restored_bounds, this, &restored_bounds, &maximized); return maximized; } @@ -1974,11 +1974,10 @@ void Browser::SetNewHomePagePrefs(PrefService* prefs) { // static void Browser::RegisterPrefs(PrefService* prefs) { - prefs->RegisterDictionaryPref(prefs::kBrowserWindowPlacement); prefs->RegisterIntegerPref(prefs::kOptionsWindowLastTabIndex, 0); - prefs->RegisterIntegerPref(prefs::kDevToolsSplitLocation, -1); prefs->RegisterDictionaryPref(prefs::kPreferencesWindowPlacement); prefs->RegisterIntegerPref(prefs::kExtensionSidebarWidth, -1); + prefs->RegisterIntegerPref(prefs::kMultipleProfilePrefMigration, 0); // Educated guess: Chrome has a bundled Flash version supporting // clearing LSO data, Chromium hasn't. #if defined(GOOGLE_CHROME_BUILD) @@ -2026,7 +2025,8 @@ void Browser::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterStringPref(prefs::kCloudPrintEmail, std::string()); prefs->RegisterBooleanPref(prefs::kDevToolsDisabled, false); prefs->RegisterRealPref(prefs::kDefaultZoomLevel, 0.0); - prefs->RegisterIntegerPref(prefs::kMultipleProfilePrefMigration, 0); + prefs->RegisterIntegerPref(prefs::kDevToolsSplitLocation, -1); + prefs->RegisterDictionaryPref(prefs::kBrowserWindowPlacement); // We need to register the type of this preference in order to query // it even though it's only typically controlled via policy. prefs->RegisterBooleanPref(prefs::kDisable3DAPIs, false); @@ -2964,7 +2964,7 @@ bool Browser::IsApplication() const { void Browser::ConvertContentsToApplication(TabContents* contents) { const GURL& url = contents->controller().GetActiveEntry()->url(); std::string app_name = web_app::GenerateApplicationNameFromURL(url); - RegisterAppPrefs(app_name); + RegisterAppPrefs(app_name, contents->profile()); DetachContents(contents); Browser* app_browser = Browser::CreateForApp( @@ -4121,7 +4121,7 @@ void Browser::TabDetachedAtImpl(TabContentsWrapper* contents, int index, } // static -void Browser::RegisterAppPrefs(const std::string& app_name) { +void Browser::RegisterAppPrefs(const std::string& app_name, Profile* profile) { // A set of apps that we've already started. static std::set<std::string>* g_app_names = NULL; @@ -4137,10 +4137,7 @@ void Browser::RegisterAppPrefs(const std::string& app_name) { std::string window_pref(prefs::kBrowserWindowPlacement); window_pref.append("_"); window_pref.append(app_name); - PrefService* prefs = g_browser_process->local_state(); - DCHECK(prefs); - - prefs->RegisterDictionaryPref(window_pref.c_str()); + profile->GetPrefs()->RegisterDictionaryPref(window_pref.c_str()); } void Browser::TabRestoreServiceChanged(TabRestoreService* service) { diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index a72e7e9..63f7d5c 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -959,9 +959,10 @@ class Browser : public TabHandlerDelegate, void TabDetachedAtImpl(TabContentsWrapper* contents, int index, DetachType type); - // Create a preference dictionary for the provided application name. This is - // done only once per application name / per session. - static void RegisterAppPrefs(const std::string& app_name); + // Create a preference dictionary for the provided application name, in the + // given user profile. This is done only once per application name / per + // session / per user profile. + static void RegisterAppPrefs(const std::string& app_name, Profile* profile); // Shared code between Reload() and ReloadIgnoringCache(). void ReloadInternal(WindowOpenDisposition disposition, bool ignore_cache); diff --git a/chrome/browser/ui/cocoa/browser_window_controller.mm b/chrome/browser/ui/cocoa/browser_window_controller.mm index d761f54..9ad91e5 100644 --- a/chrome/browser/ui/cocoa/browser_window_controller.mm +++ b/chrome/browser/ui/cocoa/browser_window_controller.mm @@ -479,7 +479,8 @@ } - (void)updateDevToolsForContents:(TabContents*)contents { - [devToolsController_ updateDevToolsForTabContents:contents]; + [devToolsController_ updateDevToolsForTabContents:contents + withProfile:browser_->profile()]; [devToolsController_ ensureContentsVisible]; } @@ -1428,7 +1429,8 @@ windowShim_->UpdateTitleBar(); [sidebarController_ updateSidebarForTabContents:contents]; - [devToolsController_ updateDevToolsForTabContents:contents]; + [devToolsController_ updateDevToolsForTabContents:contents + withProfile:browser_->profile()]; // Update the bookmark bar. // Must do it after sidebar and devtools update, otherwise bookmark bar might diff --git a/chrome/browser/ui/cocoa/browser_window_controller_private.mm b/chrome/browser/ui/cocoa/browser_window_controller_private.mm index 73c6e01..5898ba5 100644 --- a/chrome/browser/ui/cocoa/browser_window_controller_private.mm +++ b/chrome/browser/ui/cocoa/browser_window_controller_private.mm @@ -62,11 +62,12 @@ const CGFloat kLocBarBottomInset = 1; if (browser_ != BrowserList::GetLastActive()) return; - if (!g_browser_process || !g_browser_process->local_state() || - !browser_->ShouldSaveWindowPlacement()) + if (!browser_->profile()->GetPrefs() || + !browser_->ShouldSaveWindowPlacement()) { return; + } - [self saveWindowPositionToPrefs:g_browser_process->local_state()]; + [self saveWindowPositionToPrefs:browser_->profile()->GetPrefs()]; } - (void)saveWindowPositionToPrefs:(PrefService*)prefs { diff --git a/chrome/browser/ui/cocoa/browser_window_controller_unittest.mm b/chrome/browser/ui/cocoa/browser_window_controller_unittest.mm index 4351532..6fd75b4 100644 --- a/chrome/browser/ui/cocoa/browser_window_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/browser_window_controller_unittest.mm @@ -88,9 +88,7 @@ TEST_F(BrowserWindowControllerTest, TestSaveWindowPosition) { ASSERT_TRUE(prefs->GetDictionary(prefs::kBrowserWindowPlacement) == NULL); // Ask the window to save its position, then check that a preference - // exists. We're technically passing in a pointer to the user prefs - // and not the local state prefs, but a PrefService* is a - // PrefService*, and this is a unittest. + // exists. [controller_ saveWindowPositionToPrefs:prefs]; EXPECT_TRUE(prefs->GetDictionary(prefs::kBrowserWindowPlacement) != NULL); } diff --git a/chrome/browser/ui/cocoa/dev_tools_controller.h b/chrome/browser/ui/cocoa/dev_tools_controller.h index c89a9f8..4555b9a 100644 --- a/chrome/browser/ui/cocoa/dev_tools_controller.h +++ b/chrome/browser/ui/cocoa/dev_tools_controller.h @@ -14,11 +14,12 @@ @class NSSplitView; @class NSView; +class Profile; class TabContents; // A class that handles updates of the devTools view within a browser window. // It swaps in the relevant devTools contents for a given TabContents or removes -// the vew, if there's no devTools contents to show. +// the view, if there's no devTools contents to show. @interface DevToolsController : NSObject { @private // A view hosting docked devTools contents. @@ -40,7 +41,8 @@ class TabContents; // Depending on |contents|'s state, decides whether the docked web inspector // should be shown or hidden and adjusts its height (|delegate_| handles // the actual resize). -- (void)updateDevToolsForTabContents:(TabContents*)contents; +- (void)updateDevToolsForTabContents:(TabContents*)contents + withProfile:(Profile*)profile; // Call when the devTools view is properly sized and the render widget host view // should be put into the view hierarchy. diff --git a/chrome/browser/ui/cocoa/dev_tools_controller.mm b/chrome/browser/ui/cocoa/dev_tools_controller.mm index 4d29794..617d773 100644 --- a/chrome/browser/ui/cocoa/dev_tools_controller.mm +++ b/chrome/browser/ui/cocoa/dev_tools_controller.mm @@ -11,6 +11,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/debugger/devtools_window.h" #include "chrome/browser/prefs/pref_service.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/tab_contents/tab_contents.h" #import "chrome/browser/ui/cocoa/view_id_util.h" #include "chrome/common/pref_names.h" @@ -28,7 +29,8 @@ const int kMinWebHeight = 50; @interface DevToolsController (Private) -- (void)showDevToolsContents:(TabContents*)devToolsContents; +- (void)showDevToolsContents:(TabContents*)devToolsContents + withProfile:(Profile*)profile; - (void)resizeDevToolsToNewHeight:(CGFloat)height; @end @@ -63,19 +65,21 @@ const int kMinWebHeight = 50; return splitView_.get(); } -- (void)updateDevToolsForTabContents:(TabContents*)contents { +- (void)updateDevToolsForTabContents:(TabContents*)contents + withProfile:(Profile*)profile { // Get current devtools content. TabContents* devToolsContents = contents ? DevToolsWindow::GetDevToolsContents(contents) : NULL; - [self showDevToolsContents:devToolsContents]; + [self showDevToolsContents:devToolsContents withProfile:profile]; } - (void)ensureContentsVisible { [contentsController_ ensureContentsVisible]; } -- (void)showDevToolsContents:(TabContents*)devToolsContents { +- (void)showDevToolsContents:(TabContents*)devToolsContents + withProfile:(Profile*)profile { [contentsController_ ensureContentsSizeDoesNotChange]; NSArray* subviews = [splitView_ subviews]; @@ -91,8 +95,8 @@ const int kMinWebHeight = 50; CGFloat splitOffset = 0; if ([subviews count] == 1) { // Load the default split offset. - splitOffset = g_browser_process->local_state()->GetInteger( - prefs::kDevToolsSplitLocation); + splitOffset = profile->GetPrefs()-> + GetInteger(prefs::kDevToolsSplitLocation); if (splitOffset < 0) { // Initial load, set to default value. splitOffset = kDefaultContentsSplitOffset; @@ -117,7 +121,8 @@ const int kMinWebHeight = 50; NSView* oldDevToolsContentsView = [subviews objectAtIndex:1]; // Store split offset when hiding devtools window only. int splitOffset = NSHeight([oldDevToolsContentsView frame]); - g_browser_process->local_state()->SetInteger( + + profile->GetPrefs()->SetInteger( prefs::kDevToolsSplitLocation, splitOffset); [oldDevToolsContentsView removeFromSuperview]; [splitView_ adjustSubviews]; diff --git a/chrome/browser/ui/gtk/browser_window_gtk.cc b/chrome/browser/ui/gtk/browser_window_gtk.cc index 6b18b39..a4b5c0b 100644 --- a/chrome/browser/ui/gtk/browser_window_gtk.cc +++ b/chrome/browser/ui/gtk/browser_window_gtk.cc @@ -1273,8 +1273,8 @@ void BrowserWindowGtk::UpdateDevToolsForContents(TabContents* contents) { } else if (should_hide) { // Store split offset when hiding devtools window only. gint divider_offset = gtk_paned_get_position(GTK_PANED(contents_split_)); - g_browser_process->local_state()->SetInteger( - prefs::kDevToolsSplitLocation, divider_offset); + browser_->profile()->GetPrefs()-> + SetInteger(prefs::kDevToolsSplitLocation, divider_offset); gtk_widget_hide(devtools_container_->widget()); } } @@ -1597,8 +1597,8 @@ void BrowserWindowGtk::InitWidgets() { FALSE, TRUE); gtk_box_pack_end(GTK_BOX(render_area_vbox_), contents_split_, TRUE, TRUE, 0); // Restore split offset. - int split_offset = g_browser_process->local_state()->GetInteger( - prefs::kDevToolsSplitLocation); + int split_offset = browser_->profile()->GetPrefs()-> + GetInteger(prefs::kDevToolsSplitLocation); if (split_offset != -1) { if (split_offset < kMinDevToolsHeight) split_offset = kMinDevToolsHeight; @@ -1758,13 +1758,13 @@ void BrowserWindowGtk::SaveWindowPosition() { // We also need to save the placement for startup. // This is a web of calls between views and delegates on Windows, but the // crux of the logic follows. See also cocoa/browser_window_controller.mm. - if (!g_browser_process->local_state()) + if (!browser_->profile()->GetPrefs()) return; std::string window_name = browser_->GetWindowPlacementKey(); DictionaryValue* window_preferences = - g_browser_process->local_state()->GetMutableDictionary( - window_name.c_str()); + browser_->profile()->GetPrefs()-> + GetMutableDictionary(window_name.c_str()); // 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/views/chrome_views_delegate.cc b/chrome/browser/ui/views/chrome_views_delegate.cc index 86faf4c..8f3cd43 100644 --- a/chrome/browser/ui/views/chrome_views_delegate.cc +++ b/chrome/browser/ui/views/chrome_views_delegate.cc @@ -8,6 +8,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/prefs/pref_service.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" #include "gfx/rect.h" @@ -27,12 +28,12 @@ ui::Clipboard* ChromeViewsDelegate::GetClipboard() const { void ChromeViewsDelegate::SaveWindowPlacement(const std::wstring& window_name, const gfx::Rect& bounds, bool maximized) { - if (!g_browser_process->local_state()) + if (!g_browser_process->profile_manager()) return; DictionaryValue* window_preferences = - g_browser_process->local_state()->GetMutableDictionary( - WideToUTF8(window_name).c_str()); + g_browser_process->profile_manager()->GetDefaultProfile()->GetPrefs()-> + GetMutableDictionary(WideToUTF8(window_name).c_str()); window_preferences->SetInteger("left", bounds.x()); window_preferences->SetInteger("top", bounds.y()); window_preferences->SetInteger("right", bounds.right()); @@ -51,12 +52,12 @@ void ChromeViewsDelegate::SaveWindowPlacement(const std::wstring& window_name, bool ChromeViewsDelegate::GetSavedWindowBounds(const std::wstring& window_name, gfx::Rect* bounds) const { - if (!g_browser_process->local_state()) + if (!g_browser_process->profile_manager()) return false; const DictionaryValue* dictionary = - g_browser_process->local_state()->GetDictionary( - WideToUTF8(window_name).c_str()); + g_browser_process->profile_manager()->GetDefaultProfile()->GetPrefs()-> + GetDictionary(WideToUTF8(window_name).c_str()); int left, top, right, bottom; if (!dictionary || !dictionary->GetInteger("left", &left) || !dictionary->GetInteger("top", &top) || @@ -71,12 +72,13 @@ bool ChromeViewsDelegate::GetSavedWindowBounds(const std::wstring& window_name, bool ChromeViewsDelegate::GetSavedMaximizedState( const std::wstring& window_name, bool* maximized) const { - if (!g_browser_process->local_state()) + if (!g_browser_process->profile_manager()) return false; const DictionaryValue* dictionary = - g_browser_process->local_state()->GetDictionary( - WideToUTF8(window_name).c_str()); + g_browser_process->profile_manager()->GetDefaultProfile()->GetPrefs()-> + GetDictionary(WideToUTF8(window_name).c_str()); + return dictionary && dictionary->GetBoolean("maximized", maximized) && maximized; } diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index de9afc7..6275760 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -2102,8 +2102,8 @@ void BrowserView::UpdateDevToolsForContents(TabContentsWrapper* wrapper) { } // Restore split offset. - int split_offset = g_browser_process->local_state()->GetInteger( - prefs::kDevToolsSplitLocation); + int split_offset = browser_->profile()->GetPrefs()-> + GetInteger(prefs::kDevToolsSplitLocation); if (split_offset == -1) { // Initial load, set to default value. split_offset = 2 * contents_split_->height() / 3; @@ -2119,8 +2119,8 @@ void BrowserView::UpdateDevToolsForContents(TabContentsWrapper* wrapper) { Layout(); } else if (should_hide) { // Store split offset when hiding devtools window only. - g_browser_process->local_state()->SetInteger( - prefs::kDevToolsSplitLocation, contents_split_->divider_offset()); + browser_->profile()->GetPrefs()->SetInteger(prefs::kDevToolsSplitLocation, + contents_split_->divider_offset()); // Restore focus to the last focused view when hiding devtools window. devtools_focus_tracker_->FocusLastFocusedExternalView(); diff --git a/chrome/browser/ui/window_sizer.cc b/chrome/browser/ui/window_sizer.cc index 292f5fc..e1dd834 100644 --- a/chrome/browser/ui/window_sizer.cc +++ b/chrome/browser/ui/window_sizer.cc @@ -6,6 +6,7 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/prefs/pref_service.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_window.h" @@ -16,9 +17,9 @@ // and persistent state from the browser window and the user's profile. class DefaultStateProvider : public WindowSizer::StateProvider { public: - explicit DefaultStateProvider(const std::string& app_name, Browser* browser) - : app_name_(app_name), - browser_(browser) { + explicit DefaultStateProvider(const std::string& app_name, + const Browser* browser) : app_name_(app_name), + browser_(browser) { } // Overridden from WindowSizer::StateProvider: @@ -33,11 +34,11 @@ class DefaultStateProvider : public WindowSizer::StateProvider { key.append(app_name_); } - if (!g_browser_process->local_state()) + if (!browser_->profile()->GetPrefs()) return false; const DictionaryValue* wp_pref = - g_browser_process->local_state()->GetDictionary(key.c_str()); + browser_->profile()->GetPrefs()->GetDictionary(key.c_str()); int top = 0, left = 0, bottom = 0, right = 0; bool has_prefs = wp_pref && @@ -74,9 +75,9 @@ class DefaultStateProvider : public WindowSizer::StateProvider { // If a reference browser is set, use its window. Otherwise find last // active. BrowserWindow* window = NULL; - if (browser_) { + // Window may be null if browser is just starting up. + if (browser_ && browser_->window()) { window = browser_->window(); - DCHECK(window); } else { BrowserList::const_reverse_iterator it = BrowserList::begin_last_active(); BrowserList::const_reverse_iterator end = BrowserList::end_last_active(); @@ -102,7 +103,7 @@ class DefaultStateProvider : public WindowSizer::StateProvider { std::string app_name_; // If set, is used as the reference browser for GetLastActiveWindowState. - Browser* browser_; + const Browser* browser_; DISALLOW_COPY_AND_ASSIGN(DefaultStateProvider); }; @@ -132,7 +133,7 @@ WindowSizer::~WindowSizer() { // static void WindowSizer::GetBrowserWindowBounds(const std::string& app_name, const gfx::Rect& specified_bounds, - Browser* browser, + const Browser* browser, gfx::Rect* window_bounds, bool* maximized) { const WindowSizer sizer(new DefaultStateProvider(app_name, browser), diff --git a/chrome/browser/ui/window_sizer.h b/chrome/browser/ui/window_sizer.h index 7d34399..a943f43 100644 --- a/chrome/browser/ui/window_sizer.h +++ b/chrome/browser/ui/window_sizer.h @@ -121,7 +121,7 @@ class WindowSizer { // non-NULL value for |browser|. static void GetBrowserWindowBounds(const std::string& app_name, const gfx::Rect& specified_bounds, - Browser* browser, + const Browser* browser, gfx::Rect* window_bounds, bool* maximized); @@ -181,4 +181,5 @@ class WindowSizer { DISALLOW_COPY_AND_ASSIGN(WindowSizer); }; -#endif // CHROME_BROWSER_WINDOW_SIZER_H_ +#endif // CHROME_BROWSER_UI_WINDOW_SIZER_H_ + |