OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/browser_ui_prefs.h" | 5 #include "chrome/browser/ui/browser_ui_prefs.h" |
6 | 6 |
7 #include "base/prefs/pref_registry_simple.h" | 7 #include "base/prefs/pref_registry_simple.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/prefs/scoped_user_pref_update.h" | |
10 #include "base/strings/string_util.h" | |
9 #include "chrome/browser/first_run/first_run.h" | 11 #include "chrome/browser/first_run/first_run.h" |
10 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
12 #include "components/pref_registry/pref_registry_syncable.h" | 14 #include "components/pref_registry/pref_registry_syncable.h" |
13 #include "components/translate/core/common/translate_pref_names.h" | 15 #include "components/translate/core/common/translate_pref_names.h" |
14 | 16 |
15 namespace chrome { | 17 namespace chrome { |
16 | 18 |
19 void MigrateBrowserUIUserPrefs(PrefService* prefs) { | |
20 scoped_ptr<base::DictionaryValue> browser_dict = | |
21 prefs->GetBrowserDictionary(); | |
gab
2014/09/05 00:53:10
I'm torn here, you could do this without requiring
dgrogan
2014/09/06 00:47:06
I moved the migration to work off a PrefStoreObser
| |
22 if (!browser_dict) | |
23 return; | |
24 | |
25 DictionaryPrefUpdate update(prefs, prefs::kAppWindowPlacement); | |
26 const std::string search_for = | |
27 std::string(prefs::kBrowserWindowPlacement) + "_"; | |
28 for (base::DictionaryValue::Iterator it(*browser_dict); !it.IsAtEnd(); | |
29 it.Advance()) { | |
30 std::string full_key("browser." + it.key()); | |
31 if (StartsWithASCII(full_key, search_for, true /* case_sensitive */)) { | |
32 if (full_key == prefs::kBrowserWindowPlacementPopup) | |
33 continue; | |
34 std::string new_key(full_key); | |
35 ReplaceFirstSubstringAfterOffset(&new_key, 0, search_for, ""); | |
gab
2014/09/05 00:53:10
|new_key| (which is equal to |full_key| at this po
dgrogan
2014/09/06 00:47:06
Done.
| |
36 update->Set(new_key, it.value().DeepCopy()); | |
37 | |
38 user_prefs::PrefRegistrySyncable* registry = | |
39 static_cast<user_prefs::PrefRegistrySyncable*>( | |
40 prefs->DeprecatedGetPrefRegistry()); | |
41 registry->RegisterDictionaryPref( | |
42 full_key.c_str(), | |
43 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
44 prefs->ClearPref(full_key.c_str()); | |
45 } | |
46 } | |
47 } | |
48 | |
17 void RegisterBrowserPrefs(PrefRegistrySimple* registry) { | 49 void RegisterBrowserPrefs(PrefRegistrySimple* registry) { |
18 registry->RegisterIntegerPref(prefs::kOptionsWindowLastTabIndex, 0); | 50 registry->RegisterIntegerPref(prefs::kOptionsWindowLastTabIndex, 0); |
19 registry->RegisterBooleanPref(prefs::kAllowFileSelectionDialogs, true); | 51 registry->RegisterBooleanPref(prefs::kAllowFileSelectionDialogs, true); |
20 registry->RegisterIntegerPref(prefs::kShowFirstRunBubbleOption, | 52 registry->RegisterIntegerPref(prefs::kShowFirstRunBubbleOption, |
21 first_run::FIRST_RUN_BUBBLE_DONT_SHOW); | 53 first_run::FIRST_RUN_BUBBLE_DONT_SHOW); |
22 } | 54 } |
23 | 55 |
24 void RegisterBrowserUserPrefs(user_prefs::PrefRegistrySyncable* registry) { | 56 void RegisterBrowserUserPrefs(user_prefs::PrefRegistrySyncable* registry) { |
25 registry->RegisterBooleanPref( | 57 registry->RegisterBooleanPref( |
26 prefs::kHomePageIsNewTabPage, | 58 prefs::kHomePageIsNewTabPage, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 registry->RegisterBooleanPref( | 150 registry->RegisterBooleanPref( |
119 prefs::kDevToolsDisabled, | 151 prefs::kDevToolsDisabled, |
120 false, | 152 false, |
121 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 153 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
122 registry->RegisterDictionaryPref( | 154 registry->RegisterDictionaryPref( |
123 prefs::kBrowserWindowPlacement, | 155 prefs::kBrowserWindowPlacement, |
124 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 156 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
125 registry->RegisterDictionaryPref( | 157 registry->RegisterDictionaryPref( |
126 prefs::kBrowserWindowPlacementPopup, | 158 prefs::kBrowserWindowPlacementPopup, |
127 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 159 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
160 registry->RegisterDictionaryPref( | |
161 prefs::kAppWindowPlacement, | |
162 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
128 registry->RegisterBooleanPref( | 163 registry->RegisterBooleanPref( |
129 prefs::kImportBookmarks, | 164 prefs::kImportBookmarks, |
130 true, | 165 true, |
131 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 166 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
132 registry->RegisterBooleanPref( | 167 registry->RegisterBooleanPref( |
133 prefs::kImportHistory, | 168 prefs::kImportHistory, |
134 true, | 169 true, |
135 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 170 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
136 registry->RegisterBooleanPref( | 171 registry->RegisterBooleanPref( |
137 prefs::kImportHomepage, | 172 prefs::kImportHomepage, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 false, | 212 false, |
178 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 213 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
179 #if !defined(OS_MACOSX) | 214 #if !defined(OS_MACOSX) |
180 registry->RegisterBooleanPref( | 215 registry->RegisterBooleanPref( |
181 prefs::kFullscreenAllowed, | 216 prefs::kFullscreenAllowed, |
182 true, | 217 true, |
183 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 218 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
184 #endif | 219 #endif |
185 } | 220 } |
186 | 221 |
187 void RegisterAppPrefs(const std::string& app_name, Profile* profile) { | |
188 // We need to register the window position pref. | |
189 // | |
190 // TODO(mnissler): Use a separate pref name pointing to a single | |
191 // dictionary instead. Also tracked as http://crbug.com/167256 | |
192 std::string window_pref(prefs::kBrowserWindowPlacement); | |
193 window_pref.append("_"); | |
194 window_pref.append(app_name); | |
195 PrefService* prefs = profile->GetPrefs(); | |
196 if (!prefs->FindPreference(window_pref.c_str())) { | |
197 // TODO(joi): Do all registration up front. | |
198 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( | |
199 static_cast<user_prefs::PrefRegistrySyncable*>( | |
200 prefs->DeprecatedGetPrefRegistry())); | |
201 registry->RegisterDictionaryPref( | |
202 window_pref.c_str(), user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
203 } | |
204 } | |
205 | |
206 | |
207 } // namespace chrome | 222 } // namespace chrome |
OLD | NEW |