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

Unified Diff: chrome/browser/prefs/browser_ui_prefs_migrator.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: update to ToT 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/prefs/browser_ui_prefs_migrator.cc
diff --git a/chrome/browser/prefs/browser_ui_prefs_migrator.cc b/chrome/browser/prefs/browser_ui_prefs_migrator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6a9fba318f2c10ca0d9b49725f850912d9c433c3
--- /dev/null
+++ b/chrome/browser/prefs/browser_ui_prefs_migrator.cc
@@ -0,0 +1,73 @@
+// Copyright (c) 2014 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.
+
+#include "chrome/browser/prefs/browser_ui_prefs_migrator.h"
+
+#include <set>
+
+#include "base/memory/scoped_ptr.h"
+#include "base/strings/string_util.h"
+#include "base/values.h"
+#include "chrome/common/pref_names.h"
+
+BrowserUIPrefsMigrator::BrowserUIPrefsMigrator(WriteablePrefStore* pref_store)
+ : pref_store_(pref_store) {
+}
+
+BrowserUIPrefsMigrator::~BrowserUIPrefsMigrator() {
+}
+
+void BrowserUIPrefsMigrator::OnInitializationCompleted(
+ bool succeeded) {
+ pref_store_->RemoveObserver(this);
+ scoped_ptr<BrowserUIPrefsMigrator> self_deleter(this);
+ if (!succeeded)
+ return;
+
+ base::Value* browser_value = NULL;
+ if (!pref_store_->GetMutableValue("browser", &browser_value))
+ return;
+
+ base::DictionaryValue* browser_dict = NULL;
+ if (!browser_value->GetAsDictionary(&browser_dict))
+ return;
+
+ // Don't bother scanning "browser" if the migration already occurred.
+ if (browser_dict->HasKey("app_window_placement"))
+ return;
+
+ // Get a set of keys in the dictionary. This must be done separately from the
+ // migration because the migration modifies the dictionary being iterated.
+ std::set<std::string> keys_to_check;
+ for (base::DictionaryValue::Iterator it(*browser_dict); !it.IsAtEnd();
+ it.Advance()) {
+ keys_to_check.insert(it.key());
+ }
+
+ scoped_ptr<base::DictionaryValue> app_window_placement;
+ // Apps used to have their window placement preferences registered as
+ // "browser.window_placement_$APPNAME".
+ const std::string search_for =
+ std::string(prefs::kBrowserWindowPlacement) + "_";
+ for (std::set<std::string>::const_iterator it = keys_to_check.begin();
+ it != keys_to_check.end();
+ ++it) {
+ std::string full_key("browser." + *it);
+ if (StartsWithASCII(full_key, search_for, true /* case_sensitive */)) {
+ if (full_key == prefs::kBrowserWindowPlacementPopup)
+ continue;
+ scoped_ptr<base::Value> single_app_placement_dict;
+ bool found = browser_dict->Remove(*it, &single_app_placement_dict);
+ DCHECK(found);
+ std::string new_key(full_key.substr(search_for.length()));
+ if (!app_window_placement)
+ app_window_placement.reset(new base::DictionaryValue);
+ app_window_placement->Set(new_key, single_app_placement_dict.release());
+ }
+ }
+ if (app_window_placement) {
+ pref_store_->SetValue(prefs::kAppWindowPlacement,
+ app_window_placement.release());
+ }
+}
« no previous file with comments | « chrome/browser/prefs/browser_ui_prefs_migrator.h ('k') | chrome/browser/prefs/browser_ui_prefs_migrator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698