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..b9cd42b5173a55324405cc901863ef3292d70162 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())) { |
+ return make_scoped_ptr( |
+ new DictionaryPrefUpdate(prefs, window_name.c_str())); |
+ } |
+ return make_scoped_ptr(new WindowPlacementPrefUpdate(prefs, window_name)) |
gab
2014/09/05 00:53:10
Isn't the whole point of WindowPlacementPrefUpdate
dgrogan
2014/09/06 00:47:06
The check here is for kBrowserWindowPlacement and
|
+ .PassAs<DictionaryPrefUpdate>(); |
+} |
+ |
+const base::DictionaryValue* GetWindowPlacementDictionaryReadOnly( |
+ const Browser* browser) { |
+ if (browser->app_name().empty()) { |
+ const char* entry = browser->is_type_popup() ? |
+ prefs::kBrowserWindowPlacementPopup : prefs::kBrowserWindowPlacement; |
+ return browser->profile()->GetPrefs()->GetDictionary(entry); |
+ } |
+ 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) { |