Chromium Code Reviews| Index: chrome/browser/ui/browser_window_state.cc |
| diff --git a/chrome/browser/ui/browser_window_state.cc b/chrome/browser/ui/browser_window_state.cc |
| index a27924109c284b43cc710c2106ae2beda0ee0a7b..fa40588f0fab9aecf96e960610153ac15b629b1f 100644 |
| --- a/chrome/browser/ui/browser_window_state.cc |
| +++ b/chrome/browser/ui/browser_window_state.cc |
| @@ -6,6 +6,7 @@ |
| #include "base/command_line.h" |
| #include "base/prefs/pref_service.h" |
| +#include "base/prefs/scoped_user_pref_update.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "chrome/browser/defaults.h" |
| #include "chrome/browser/profiles/profile.h" |
| @@ -40,15 +41,67 @@ bool ParseCommaSeparatedIntegers(const std::string& str, |
| return true; |
| } |
| +class WindowPlacementPrefUpdate : public DictionaryPrefUpdate { |
| + public: |
| + WindowPlacementPrefUpdate(PrefService* service, |
| + const std::string& window_name) |
| + : DictionaryPrefUpdate(service, prefs::kAppWindowPlacement), |
| + window_name_(window_name) {} |
| + |
| + virtual ~WindowPlacementPrefUpdate() {} |
| + |
| + virtual base::DictionaryValue* Get() OVERRIDE { |
| + base::DictionaryValue* all_apps_dict = DictionaryPrefUpdate::Get(); |
| + base::DictionaryValue* this_app_dict = NULL; |
| + if (!all_apps_dict->GetDictionary(window_name_, &this_app_dict)) { |
| + this_app_dict = new base::DictionaryValue; |
| + all_apps_dict->Set(window_name_, this_app_dict); |
| + } |
| + return this_app_dict; |
| + } |
| + |
| + private: |
| + const std::string window_name_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WindowPlacementPrefUpdate); |
| +}; |
| + |
| } // namespace |
| -std::string GetWindowPlacementKey(const Browser* browser) { |
| +std::string GetWindowName(const Browser* browser) { |
| if (browser->app_name().empty()) { |
| return browser->is_type_popup() ? |
| prefs::kBrowserWindowPlacementPopup : prefs::kBrowserWindowPlacement; |
| } |
| - return std::string(prefs::kBrowserWindowPlacement) + "_" + |
| - browser->app_name(); |
| + return browser->app_name(); |
| +} |
| + |
| +scoped_ptr<DictionaryPrefUpdate> GetWindowPlacementDictionaryReadWrite( |
| + const std::string& window_name, |
| + PrefService* prefs) { |
| + DCHECK(!window_name.empty()); |
| + if (prefs->FindPreference(window_name.c_str())) { |
|
dgrogan
2014/09/04 00:50:51
This seems fragile... any window_name that isn't a
|
| + return make_scoped_ptr( |
| + new DictionaryPrefUpdate(prefs, window_name.c_str())); |
| + } |
| + return make_scoped_ptr(new WindowPlacementPrefUpdate(prefs, window_name)) |
| + .PassAs<DictionaryPrefUpdate>(); |
| +} |
| + |
| +const base::DictionaryValue* GetWindowPlacementDictionaryReadOnly( |
| + const Browser* browser) { |
| + if (browser->app_name().empty()) { |
| + const std::string entry = browser->is_type_popup() ? |
|
Bernhard Bauer
2014/09/04 11:06:03
Declare this as const char*?
dgrogan
2014/09/04 20:26:33
Done.
|
| + prefs::kBrowserWindowPlacementPopup : prefs::kBrowserWindowPlacement; |
| + return browser->profile()->GetPrefs()->GetDictionary(entry.c_str()); |
| + } |
| + const base::DictionaryValue* app_windows = |
| + browser->profile()->GetPrefs()->GetDictionary(prefs::kAppWindowPlacement); |
| + if (!app_windows) |
| + return NULL; |
| + const base::DictionaryValue* to_return = NULL; |
| + app_windows->GetDictionary(browser->app_name(), &to_return); |
| + return to_return; |
| } |
| bool ShouldSaveWindowPlacement(const Browser* browser) { |