Chromium Code Reviews| 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(); | |
|
dgrogan
2014/09/04 00:50:51
An alternative to the GetBrowserDictionary method
| |
| 22 if (!browser_dict.get()) | |
|
Bernhard Bauer
2014/09/04 11:06:02
scoped_ptr has a bool conversion operator.
dgrogan
2014/09/04 20:26:33
Done.
| |
| 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*/)) { | |
|
Bernhard Bauer
2014/09/04 11:06:02
Nit: space inside of a /* comment */.
dgrogan
2014/09/04 20:26:33
Done.
| |
| 32 if (full_key == prefs::kBrowserWindowPlacementPopup) | |
| 33 continue; | |
| 34 const base::DictionaryValue* old_value; | |
| 35 // Test this on mac with a local app. | |
| 36 bool found = browser_dict->GetDictionary(it.key(), &old_value); | |
|
Bernhard Bauer
2014/09/04 11:06:02
You can use it.value() to get the value, then call
dgrogan
2014/09/04 20:26:33
I got rid of the conversion to dictionary. The onl
| |
| 37 DCHECK(found) << it.key(); | |
| 38 std::string new_key(full_key); | |
| 39 ReplaceFirstSubstringAfterOffset(&new_key, 0, search_for, ""); | |
| 40 update->Set(new_key, old_value->DeepCopy()); | |
| 41 | |
| 42 user_prefs::PrefRegistrySyncable* registry = | |
| 43 static_cast<user_prefs::PrefRegistrySyncable*>( | |
| 44 prefs->DeprecatedGetPrefRegistry()); | |
| 45 registry->RegisterDictionaryPref( | |
| 46 full_key.c_str(), | |
| 47 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 48 prefs->ClearPref(full_key.c_str()); | |
| 49 } | |
| 50 } | |
| 51 } | |
| 52 | |
| 17 void RegisterBrowserPrefs(PrefRegistrySimple* registry) { | 53 void RegisterBrowserPrefs(PrefRegistrySimple* registry) { |
| 18 registry->RegisterIntegerPref(prefs::kOptionsWindowLastTabIndex, 0); | 54 registry->RegisterIntegerPref(prefs::kOptionsWindowLastTabIndex, 0); |
| 19 registry->RegisterBooleanPref(prefs::kAllowFileSelectionDialogs, true); | 55 registry->RegisterBooleanPref(prefs::kAllowFileSelectionDialogs, true); |
| 20 registry->RegisterIntegerPref(prefs::kShowFirstRunBubbleOption, | 56 registry->RegisterIntegerPref(prefs::kShowFirstRunBubbleOption, |
| 21 first_run::FIRST_RUN_BUBBLE_DONT_SHOW); | 57 first_run::FIRST_RUN_BUBBLE_DONT_SHOW); |
| 22 } | 58 } |
| 23 | 59 |
| 24 void RegisterBrowserUserPrefs(user_prefs::PrefRegistrySyncable* registry) { | 60 void RegisterBrowserUserPrefs(user_prefs::PrefRegistrySyncable* registry) { |
| 25 registry->RegisterBooleanPref( | 61 registry->RegisterBooleanPref( |
| 26 prefs::kHomePageIsNewTabPage, | 62 prefs::kHomePageIsNewTabPage, |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 registry->RegisterBooleanPref( | 154 registry->RegisterBooleanPref( |
| 119 prefs::kDevToolsDisabled, | 155 prefs::kDevToolsDisabled, |
| 120 false, | 156 false, |
| 121 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 157 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 122 registry->RegisterDictionaryPref( | 158 registry->RegisterDictionaryPref( |
| 123 prefs::kBrowserWindowPlacement, | 159 prefs::kBrowserWindowPlacement, |
| 124 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 160 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 125 registry->RegisterDictionaryPref( | 161 registry->RegisterDictionaryPref( |
| 126 prefs::kBrowserWindowPlacementPopup, | 162 prefs::kBrowserWindowPlacementPopup, |
| 127 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 163 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 164 registry->RegisterDictionaryPref( | |
| 165 prefs::kAppWindowPlacement, | |
| 166 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 128 registry->RegisterBooleanPref( | 167 registry->RegisterBooleanPref( |
| 129 prefs::kImportBookmarks, | 168 prefs::kImportBookmarks, |
| 130 true, | 169 true, |
| 131 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 170 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 132 registry->RegisterBooleanPref( | 171 registry->RegisterBooleanPref( |
| 133 prefs::kImportHistory, | 172 prefs::kImportHistory, |
| 134 true, | 173 true, |
| 135 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 174 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 136 registry->RegisterBooleanPref( | 175 registry->RegisterBooleanPref( |
| 137 prefs::kImportHomepage, | 176 prefs::kImportHomepage, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 false, | 216 false, |
| 178 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 217 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 179 #if !defined(OS_MACOSX) | 218 #if !defined(OS_MACOSX) |
| 180 registry->RegisterBooleanPref( | 219 registry->RegisterBooleanPref( |
| 181 prefs::kFullscreenAllowed, | 220 prefs::kFullscreenAllowed, |
| 182 true, | 221 true, |
| 183 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 222 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 184 #endif | 223 #endif |
| 185 } | 224 } |
| 186 | 225 |
| 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 | 226 } // namespace chrome |
| OLD | NEW |