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

Side by Side Diff: chrome/browser/extensions/api/settings_private/prefs_util.cc

Issue 1410993005: Support dictionary prefs in chrome.settingsPrivate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « no previous file | chrome/common/extensions/api/settings_private.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/extensions/api/settings_private/prefs_util.h" 5 #include "chrome/browser/extensions/api/settings_private/prefs_util.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/extensions/chrome_extension_function.h" 9 #include "chrome/browser/extensions/chrome_extension_function.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 case base::Value::Type::TYPE_BOOLEAN: 170 case base::Value::Type::TYPE_BOOLEAN:
171 return settings_private::PrefType::PREF_TYPE_BOOLEAN; 171 return settings_private::PrefType::PREF_TYPE_BOOLEAN;
172 case base::Value::Type::TYPE_INTEGER: 172 case base::Value::Type::TYPE_INTEGER:
173 case base::Value::Type::TYPE_DOUBLE: 173 case base::Value::Type::TYPE_DOUBLE:
174 return settings_private::PrefType::PREF_TYPE_NUMBER; 174 return settings_private::PrefType::PREF_TYPE_NUMBER;
175 case base::Value::Type::TYPE_STRING: 175 case base::Value::Type::TYPE_STRING:
176 return IsPrefTypeURL(name) ? settings_private::PrefType::PREF_TYPE_URL 176 return IsPrefTypeURL(name) ? settings_private::PrefType::PREF_TYPE_URL
177 : settings_private::PrefType::PREF_TYPE_STRING; 177 : settings_private::PrefType::PREF_TYPE_STRING;
178 case base::Value::Type::TYPE_LIST: 178 case base::Value::Type::TYPE_LIST:
179 return settings_private::PrefType::PREF_TYPE_LIST; 179 return settings_private::PrefType::PREF_TYPE_LIST;
180 case base::Value::Type::TYPE_DICTIONARY:
181 return settings_private::PrefType::PREF_TYPE_DICTIONARY;
180 default: 182 default:
181 return settings_private::PrefType::PREF_TYPE_NONE; 183 return settings_private::PrefType::PREF_TYPE_NONE;
182 } 184 }
183 } 185 }
184 186
185 scoped_ptr<settings_private::PrefObject> PrefsUtil::GetCrosSettingsPref( 187 scoped_ptr<settings_private::PrefObject> PrefsUtil::GetCrosSettingsPref(
186 const std::string& name) { 188 const std::string& name) {
187 scoped_ptr<settings_private::PrefObject> pref_object( 189 scoped_ptr<settings_private::PrefObject> pref_object(
188 new settings_private::PrefObject()); 190 new settings_private::PrefObject());
189 191
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 const PrefService::Preference* pref = pref_service->FindPreference(pref_name); 309 const PrefService::Preference* pref = pref_service->FindPreference(pref_name);
308 if (!pref) 310 if (!pref)
309 return PREF_NOT_FOUND; 311 return PREF_NOT_FOUND;
310 312
311 DCHECK_EQ(pref->GetType(), value->GetType()); 313 DCHECK_EQ(pref->GetType(), value->GetType());
312 314
313 switch (pref->GetType()) { 315 switch (pref->GetType()) {
314 case base::Value::TYPE_BOOLEAN: 316 case base::Value::TYPE_BOOLEAN:
315 case base::Value::TYPE_DOUBLE: 317 case base::Value::TYPE_DOUBLE:
316 case base::Value::TYPE_LIST: 318 case base::Value::TYPE_LIST:
319 case base::Value::TYPE_DICTIONARY:
317 pref_service->Set(pref_name, *value); 320 pref_service->Set(pref_name, *value);
318 break; 321 break;
319 case base::Value::TYPE_INTEGER: { 322 case base::Value::TYPE_INTEGER: {
320 // In JS all numbers are doubles. 323 // In JS all numbers are doubles.
321 double double_value; 324 double double_value;
322 if (!value->GetAsDouble(&double_value)) 325 if (!value->GetAsDouble(&double_value))
323 return PREF_TYPE_MISMATCH; 326 return PREF_TYPE_MISMATCH;
324 327
325 pref_service->SetInteger(pref_name, static_cast<int>(double_value)); 328 pref_service->SetInteger(pref_name, static_cast<int>(double_value));
326 break; 329 break;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 500
498 bool PrefsUtil::IsCrosSetting(const std::string& pref_name) { 501 bool PrefsUtil::IsCrosSetting(const std::string& pref_name) {
499 #if defined(OS_CHROMEOS) 502 #if defined(OS_CHROMEOS)
500 return CrosSettings::Get()->IsCrosSettings(pref_name); 503 return CrosSettings::Get()->IsCrosSettings(pref_name);
501 #else 504 #else
502 return false; 505 return false;
503 #endif 506 #endif
504 } 507 }
505 508
506 } // namespace extensions 509 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/api/settings_private.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698