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

Side by Side Diff: chrome/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: move to own file and start unit tests 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/prefs_migrator.h"
6
7 #include <set>
8
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_util.h"
11 #include "base/values.h"
12 #include "chrome/common/pref_names.h"
13
14 BrowserUIPrefsMigrationObserver::BrowserUIPrefsMigrationObserver(
15 scoped_refptr<WriteablePrefStore> pref_store)
16 : pref_store_(pref_store) {
17 }
18
19 BrowserUIPrefsMigrationObserver::~BrowserUIPrefsMigrationObserver() {
20 }
21
22 void BrowserUIPrefsMigrationObserver::OnInitializationCompleted(
23 bool succeeded) {
24 pref_store_->RemoveObserver(this);
25 scoped_ptr<BrowserUIPrefsMigrationObserver> self_deleter(this);
26 if (!succeeded)
27 return;
28
29 base::Value* browser_value = NULL;
30 if (!pref_store_->GetMutableValue("browser", &browser_value))
31 return;
32
33 base::DictionaryValue* browser_dict = NULL;
34 if (!browser_value->GetAsDictionary(&browser_dict))
35 return;
36
37 // Don't bother scanning "browser" if the migration already occurred.
38 if (browser_dict->HasKey(prefs::kAppWindowPlacement))
39 return;
40
41 // Get a set of keys in the dictionary. This must be done separately from the
42 // migration because the migration modifies the dictionary being iterated.
43 std::set<std::string> keys_to_check;
44 for (base::DictionaryValue::Iterator it(*browser_dict); !it.IsAtEnd();
45 it.Advance()) {
46 keys_to_check.insert(it.key());
47 }
48
49 scoped_ptr<base::DictionaryValue> app_window_placement;
50 // Apps used to have their window placement preferences registered as
51 // "browser.window_placement_$APPNAME".
52 const std::string search_for =
53 std::string(prefs::kBrowserWindowPlacement) + "_";
54 for (std::set<std::string>::const_iterator it = keys_to_check.begin();
55 it != keys_to_check.end();
56 ++it) {
57 std::string full_key("browser." + *it);
58 if (StartsWithASCII(full_key, search_for, true /* case_sensitive */)) {
59 if (full_key == prefs::kBrowserWindowPlacementPopup)
60 continue;
61 scoped_ptr<base::Value> single_app_placement_dict;
62 bool found = browser_dict->Remove(*it, &single_app_placement_dict);
63 DCHECK(found);
64 std::string new_key(full_key.substr(search_for.length()));
65 if (!app_window_placement)
66 app_window_placement.reset(new base::DictionaryValue);
67 app_window_placement->Set(new_key, single_app_placement_dict.release());
68 }
69 }
70 if (app_window_placement) {
71 pref_store_->SetValue(prefs::kAppWindowPlacement,
72 app_window_placement.release());
73 }
74 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698