diff options
20 files changed, 231 insertions, 88 deletions
diff --git a/chrome/browser/debugger/devtools_window.cc b/chrome/browser/debugger/devtools_window.cc index 9e86f28..9407eb1 100644 --- a/chrome/browser/debugger/devtools_window.cc +++ b/chrome/browser/debugger/devtools_window.cc @@ -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. @@ -216,7 +216,7 @@ void DevToolsWindow::CreateDevToolsBrowser() { wp_key.append("_"); wp_key.append(kDevToolsApp); - PrefService* prefs = g_browser_process->local_state(); + PrefService* prefs = profile_->GetPrefs(); if (!prefs->FindPreference(wp_key.c_str())) { prefs->RegisterDictionaryPref(wp_key.c_str()); } diff --git a/chrome/browser/net/predictor_api.cc b/chrome/browser/net/predictor_api.cc index e16e8e9..52a1497 100644 --- a/chrome/browser/net/predictor_api.cc +++ b/chrome/browser/net/predictor_api.cc @@ -20,6 +20,7 @@ #include "chrome/browser/net/preconnect.h" #include "chrome/browser/net/referrer.h" #include "chrome/browser/net/url_info.h" +#include "chrome/browser/prefs/browser_prefs.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/prefs/session_startup_pref.h" #include "chrome/browser/profiles/profile.h" @@ -394,16 +395,15 @@ static void InitNetworkPredictor(TimeDelta max_dns_queue_delay, prefs::kDnsPrefetchingHostReferralList)->DeepCopy()); // Remove obsolete preferences from local state if necessary. - int dns_prefs_version = - user_prefs->GetInteger(prefs::kMultipleProfilePrefMigration); - if (dns_prefs_version < 1) { - // These prefs only need to be registered if they need to be cleared from - // local state. + int current_version = + local_state->GetInteger(prefs::kMultipleProfilePrefMigration); + if ((current_version & browser::DNS_PREFS) == 0) { local_state->RegisterListPref(prefs::kDnsStartupPrefetchList); local_state->RegisterListPref(prefs::kDnsHostReferralList); local_state->ClearPref(prefs::kDnsStartupPrefetchList); local_state->ClearPref(prefs::kDnsHostReferralList); - user_prefs->SetInteger(prefs::kMultipleProfilePrefMigration, 1); + local_state->SetInteger(prefs::kMultipleProfilePrefMigration, + current_version | browser::DNS_PREFS); } g_browser_process->io_thread()->InitNetworkPredictor( diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc index 4bbd995..9bf8f4e0 100644 --- a/chrome/browser/prefs/browser_prefs.cc +++ b/chrome/browser/prefs/browser_prefs.cc @@ -55,6 +55,7 @@ #include "chrome/browser/translate/translate_prefs.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/upgrade_detector.h" +#include "chrome/common/pref_names.h" #if defined(TOOLKIT_VIEWS) // TODO(port): whittle this down as we port #include "chrome/browser/ui/views/browser_actions_container.h" @@ -159,4 +160,35 @@ void RegisterUserPrefs(PrefService* user_prefs) { policy::ProfilePolicyContext::RegisterUserPrefs(user_prefs); } +void MigrateBrowserPrefs(PrefService* user_prefs, PrefService* local_state) { + // Copy pref values which have been migrated to user_prefs from local_state, + // or remove them from local_state outright, if copying is not required. + int current_version = + local_state->GetInteger(prefs::kMultipleProfilePrefMigration); + + if ((current_version & WINDOWS_PREFS) == 0) { + // Migrate the devtools split location preference. + local_state->RegisterIntegerPref(prefs::kDevToolsSplitLocation, -1); + DCHECK(user_prefs->FindPreference(prefs::kDevToolsSplitLocation)); + if (local_state->HasPrefPath(prefs::kDevToolsSplitLocation)) { + user_prefs->SetInteger(prefs::kDevToolsSplitLocation, + local_state->GetInteger(prefs::kDevToolsSplitLocation)); + } + local_state->ClearPref(prefs::kDevToolsSplitLocation); + + // Migrate the browser window placement preference. + local_state->RegisterDictionaryPref(prefs::kBrowserWindowPlacement); + DCHECK(user_prefs->FindPreference(prefs::kBrowserWindowPlacement)); + if (local_state->HasPrefPath(prefs::kBrowserWindowPlacement)) { + user_prefs->Set(prefs::kBrowserWindowPlacement, + *(local_state->FindPreference(prefs::kBrowserWindowPlacement)-> + GetValue()->DeepCopy())); + } + local_state->ClearPref(prefs::kBrowserWindowPlacement); + + local_state->SetInteger(prefs::kMultipleProfilePrefMigration, + current_version | WINDOWS_PREFS); + } +} + } // namespace browser diff --git a/chrome/browser/prefs/browser_prefs.h b/chrome/browser/prefs/browser_prefs.h index ef109a4..4df26c1 100644 --- a/chrome/browser/prefs/browser_prefs.h +++ b/chrome/browser/prefs/browser_prefs.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 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. @@ -10,11 +10,19 @@ class PrefService; namespace browser { +// Bitmask for kMultipleProfilePrefMigration. +enum MigratedPreferences { + NO_PREFS = 0, + DNS_PREFS = 1 << 0, + WINDOWS_PREFS = 1 << 1, +}; + // Makes the PrefService objects aware of all the prefs. void RegisterAllPrefs(PrefService* user_prefs, PrefService* local_state); void RegisterLocalState(PrefService* local_state); void RegisterUserPrefs(PrefService* user_prefs); - +// Migrate prefs from local_state to user_prefs. +void MigrateBrowserPrefs(PrefService* user_prefs, PrefService* local_state); } // namespace browser #endif // CHROME_BROWSER_PREFS_BROWSER_PREFS_H__ diff --git a/chrome/browser/prefs/pref_service_uitest.cc b/chrome/browser/prefs/pref_service_uitest.cc index 9712481..c6540d74 100644 --- a/chrome/browser/prefs/pref_service_uitest.cc +++ b/chrome/browser/prefs/pref_service_uitest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 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. @@ -29,17 +29,27 @@ class PreferenceServiceTest : public UITest { file_util::Delete(tmp_profile_, true); file_util::CreateDirectory(tmp_profile_); - FilePath reference_pref_file = - test_data_directory_ + FilePath reference_pref_file; + if (new_profile_) { + reference_pref_file = test_data_directory_ + .AppendASCII("profiles") + .AppendASCII("window_placement") + .AppendASCII("Default") + .Append(chrome::kPreferencesFilename); + tmp_pref_file_ = tmp_profile_.AppendASCII("Default"); + ASSERT_TRUE(file_util::CreateDirectory(tmp_pref_file_)); + tmp_pref_file_ = tmp_pref_file_.Append(chrome::kPreferencesFilename); + } else { + reference_pref_file = test_data_directory_ .AppendASCII("profiles") .AppendASCII("window_placement") .Append(chrome::kLocalStateFilename); - - tmp_pref_file_ = tmp_profile_.Append(chrome::kLocalStateFilename); + tmp_pref_file_ = tmp_profile_.Append(chrome::kLocalStateFilename); + } ASSERT_TRUE(file_util::PathExists(reference_pref_file)); - - // Copy only the Local State file, the rest will be automatically created + // Copy only the Preferences file if |new_profile_|, or Local State if not, + // and the rest will be automatically created. ASSERT_TRUE(file_util::CopyFile(reference_pref_file, tmp_pref_file_)); #if defined(OS_WIN) @@ -66,20 +76,21 @@ class PreferenceServiceTest : public UITest { } public: + bool new_profile_; FilePath tmp_pref_file_; FilePath tmp_profile_; }; -#if defined(OS_WIN) +#if !defined(OS_LINUX) // This test verifies that the window position from the prefs file is restored // when the app restores. This doesn't really make sense on Linux, where // the window manager might fight with you over positioning. However, we // might be able to make this work on buildbots. -// Also, not sure what should happen on the mac. In any case, the code below -// (minus the Windows bits) compiles fine on my Linux box now. // TODO(port): revisit this. TEST_F(PreferenceServiceTest, PreservedWindowPlacementIsLoaded) { - // The window should open with the reference profile + // The window should open with the new reference profile, with window + // placement values stored in the user data directory. + new_profile_ = true; ASSERT_TRUE(LaunchAppWithProfile()); ASSERT_TRUE(file_util::PathExists(tmp_pref_file_)); @@ -132,3 +143,66 @@ TEST_F(PreferenceServiceTest, PreservedWindowPlacementIsLoaded) { EXPECT_EQ(is_maximized, is_window_maximized); } #endif + +#if !defined(OS_LINUX) +TEST_F(PreferenceServiceTest, PreservedWindowPlacementIsMigrated) { + // The window should open with the old reference profile, with window + // placement values stored in Local State. + new_profile_ = false; + ASSERT_TRUE(LaunchAppWithProfile()); + + ASSERT_TRUE(file_util::PathExists(tmp_pref_file_)); + + JSONFileValueSerializer deserializer(tmp_pref_file_); + scoped_ptr<Value> root(deserializer.Deserialize(NULL, NULL)); + + ASSERT_TRUE(root.get()); + ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); + + // Retrieve the screen rect for the launched window + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(browser.get()); + scoped_refptr<WindowProxy> window(browser->GetWindow()); + ASSERT_TRUE(window.get()); + + gfx::Rect bounds; + ASSERT_TRUE(window->GetBounds(&bounds)); + + // Values from old reference profile in Local State should have been + // correctly migrated to the user's Preferences -- if so, the window + // should be set to values taken from the user's Local State. + DictionaryValue* root_dict = static_cast<DictionaryValue*>(root.get()); + + // Retrieve the expected rect values from User Preferences, where they + // should have been migrated from Local State. + int bottom = 0; + std::string kBrowserWindowPlacement(prefs::kBrowserWindowPlacement); + EXPECT_TRUE(root_dict->GetInteger(kBrowserWindowPlacement + ".bottom", + &bottom)); + EXPECT_EQ(bottom, bounds.y() + bounds.height()); + + int top = 0; + EXPECT_TRUE(root_dict->GetInteger(kBrowserWindowPlacement + ".top", + &top)); + EXPECT_EQ(top, bounds.y()); + + int left = 0; + EXPECT_TRUE(root_dict->GetInteger(kBrowserWindowPlacement + ".left", + &left)); + EXPECT_EQ(left, bounds.x()); + + int right = 0; + EXPECT_TRUE(root_dict->GetInteger(kBrowserWindowPlacement + ".right", + &right)); + EXPECT_EQ(right, bounds.x() + bounds.width()); + + // Find if launched window is maximized. + bool is_window_maximized = false; + ASSERT_TRUE(window->IsMaximized(&is_window_maximized)); + bool is_maximized = false; + EXPECT_TRUE(root_dict->GetBoolean(kBrowserWindowPlacement + ".maximized", + &is_maximized)); + EXPECT_EQ(is_maximized, is_window_maximized); +} +#endif + diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index 3b540d1..cdb7091 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -667,6 +667,11 @@ PrefService* ProfileImpl::GetPrefs() { // register known prefs as soon as possible. Profile::RegisterUserPrefs(prefs_.get()); browser::RegisterUserPrefs(prefs_.get()); + // TODO(mirandac): remove migration code after 6 months (crbug.com/69995). + if (g_browser_process->local_state()) { + browser::MigrateBrowserPrefs(prefs_.get(), + g_browser_process->local_state()); + } // The last session exited cleanly if there is no pref for // kSessionExitedCleanly or the value for kSessionExitedCleanly is true. 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_ + diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index e93d7af..de58311 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -252,11 +252,13 @@ const char kInstantPromo[] = "instant.promo"; // Used to migrate preferences from local state to user preferences to // enable multiple profiles. -// Holds possible values: -// 0: no preferences migrated yet. -// 1: dns prefetching preferences stored in user preferences. +// BITMASK with possible values (see browser_prefs.cc for enum): +// 0: No preferences migrated. +// 1: DNS preferences migrated: kDnsPrefetchingStartupList and HostReferralList +// 2: Browser window preferences migrated: kDevToolsSplitLocation and +// kBrowserWindowPlacement const char kMultipleProfilePrefMigration[] = - "profile.multiple_profile_prefs_version"; + "local_state.multiple_profile_prefs_version"; #if defined(USE_NSS) || defined(USE_OPENSSL) // Prefs for SSLConfigServicePref. Currently, these are only present on diff --git a/chrome/test/data/profiles/window_placement/Default/Preferences b/chrome/test/data/profiles/window_placement/Default/Preferences new file mode 100644 index 0000000..5a87bcd --- /dev/null +++ b/chrome/test/data/profiles/window_placement/Default/Preferences @@ -0,0 +1,12 @@ +{ + "browser" : { + "window_placement" : { + "bottom" : 400, + "left" : 50, + "maximized" : false, + "right" : 450, + "top" : 50 + } + } +} + |