Index: chrome/browser/ui/views/chrome_views_delegate.cc |
=================================================================== |
--- chrome/browser/ui/views/chrome_views_delegate.cc (revision 73335) |
+++ chrome/browser/ui/views/chrome_views_delegate.cc (working copy) |
@@ -5,11 +5,14 @@ |
#include "chrome/browser/ui/views/chrome_views_delegate.h" |
#include "base/scoped_ptr.h" |
+#include "base/string_util.h" |
#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 "chrome/common/pref_names.h" |
#include "gfx/rect.h" |
#include "ui/base/clipboard/clipboard.h" |
@@ -17,6 +20,27 @@ |
#include "chrome/browser/app_icon_win.h" |
#endif |
+namespace { |
+ |
+// Some window data should be stored in local state, instead of by profile; use |
+// the window_name to differentiate between storage types. This function may |
+// return NULL if the necessary PrefService has not yet been initialized. |
+// TODO(mirandac): This function will also serve to separate windows by profile |
+// in a multiprofile environment. |
+PrefService* GetPrefsForWindow(const std::wstring& window_name) { |
+ if (LowerCaseEqualsASCII(window_name, prefs::kTaskManagerWindowPlacement)) { |
+ return g_browser_process->local_state(); |
+ } else { |
+ if (!g_browser_process->profile_manager()) { |
+ return NULL; |
+ } |
+ return g_browser_process->profile_manager()->GetDefaultProfile()-> |
+ GetPrefs(); |
+ } |
+} |
+ |
+} // namespace |
+ |
/////////////////////////////////////////////////////////////////////////////// |
// ChromeViewsDelegate, views::ViewsDelegate implementation: |
@@ -27,12 +51,12 @@ |
void ChromeViewsDelegate::SaveWindowPlacement(const std::wstring& window_name, |
const gfx::Rect& bounds, |
bool maximized) { |
- if (!g_browser_process->local_state()) |
+ PrefService* prefs = GetPrefsForWindow(window_name); |
+ if (!prefs) |
return; |
DictionaryValue* window_preferences = |
- g_browser_process->local_state()->GetMutableDictionary( |
- WideToUTF8(window_name).c_str()); |
+ prefs->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 +75,12 @@ |
bool ChromeViewsDelegate::GetSavedWindowBounds(const std::wstring& window_name, |
gfx::Rect* bounds) const { |
- if (!g_browser_process->local_state()) |
+ PrefService* prefs = GetPrefsForWindow(window_name); |
+ if (!prefs) |
return false; |
const DictionaryValue* dictionary = |
- g_browser_process->local_state()->GetDictionary( |
- WideToUTF8(window_name).c_str()); |
+ prefs->GetDictionary(WideToUTF8(window_name).c_str()); |
int left, top, right, bottom; |
if (!dictionary || !dictionary->GetInteger("left", &left) || |
!dictionary->GetInteger("top", &top) || |
@@ -71,12 +95,13 @@ |
bool ChromeViewsDelegate::GetSavedMaximizedState( |
const std::wstring& window_name, |
bool* maximized) const { |
- if (!g_browser_process->local_state()) |
+ PrefService* prefs = GetPrefsForWindow(window_name); |
+ if (!prefs) |
return false; |
const DictionaryValue* dictionary = |
- g_browser_process->local_state()->GetDictionary( |
- WideToUTF8(window_name).c_str()); |
+ prefs->GetDictionary(WideToUTF8(window_name).c_str()); |
+ |
return dictionary && dictionary->GetBoolean("maximized", maximized) && |
maximized; |
} |