Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2986)

Unified Diff: chrome/browser/ui/browser_window_state.cc

Issue 511393003: No longer register app window placement preference keys on the fly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: make member variables local Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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) {

Powered by Google App Engine
This is Rietveld 408576698