Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / profile_resetter / brandcoded_default_settings.cc
blob20145fbbe57a14440df9965efba3bfbdd37e6328
1 // Copyright 2013 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.
5 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h"
7 #include "base/json/json_string_value_serializer.h"
8 #include "base/logging.h"
9 #include "chrome/common/pref_names.h"
10 #include "chrome/installer/util/master_preferences_constants.h"
11 #include "components/crx_file/id_util.h"
12 #include "components/search_engines/search_engines_pref_names.h"
14 BrandcodedDefaultSettings::BrandcodedDefaultSettings() {
17 BrandcodedDefaultSettings::BrandcodedDefaultSettings(const std::string& prefs) {
18 if (!prefs.empty()) {
19 JSONStringValueDeserializer json(prefs);
20 std::string error;
21 scoped_ptr<base::Value> root(json.Deserialize(NULL, &error));
22 if (!root.get()) {
23 VLOG(1) << "Failed to parse brandcode prefs file: " << error;
24 return;
26 if (!root->IsType(base::Value::TYPE_DICTIONARY)) {
27 VLOG(1) << "Failed to parse brandcode prefs file: "
28 << "Root item must be a dictionary.";
29 return;
31 master_dictionary_.reset(
32 static_cast<base::DictionaryValue*>(root.release()));
36 BrandcodedDefaultSettings::~BrandcodedDefaultSettings() {
39 scoped_ptr<base::ListValue>
40 BrandcodedDefaultSettings::GetSearchProviderOverrides() const {
41 return ExtractList(prefs::kSearchProviderOverrides);
44 bool BrandcodedDefaultSettings::GetHomepage(std::string* homepage) const {
45 return master_dictionary_ &&
46 master_dictionary_->GetString(prefs::kHomePage, homepage) &&
47 !homepage->empty();
50 bool BrandcodedDefaultSettings::GetHomepageIsNewTab(
51 bool* homepage_is_ntp) const {
52 return master_dictionary_ &&
53 master_dictionary_->GetBoolean(prefs::kHomePageIsNewTabPage,
54 homepage_is_ntp);
57 bool BrandcodedDefaultSettings::GetShowHomeButton(
58 bool* show_home_button) const {
59 return master_dictionary_ &&
60 master_dictionary_->GetBoolean(prefs::kShowHomeButton,
61 show_home_button);
64 bool BrandcodedDefaultSettings::GetExtensions(
65 std::vector<std::string>* extension_ids) const {
66 DCHECK(extension_ids);
67 base::DictionaryValue* extensions = NULL;
68 if (master_dictionary_ &&
69 master_dictionary_->GetDictionary(
70 installer::master_preferences::kExtensionsBlock,
71 &extensions)) {
72 for (base::DictionaryValue::Iterator extension_id(*extensions);
73 !extension_id.IsAtEnd(); extension_id.Advance()) {
74 if (crx_file::id_util::IdIsValid(extension_id.key()))
75 extension_ids->push_back(extension_id.key());
77 return true;
79 return false;
82 bool BrandcodedDefaultSettings::GetRestoreOnStartup(
83 int* restore_on_startup) const {
84 return master_dictionary_ &&
85 master_dictionary_->GetInteger(prefs::kRestoreOnStartup,
86 restore_on_startup);
89 scoped_ptr<base::ListValue>
90 BrandcodedDefaultSettings::GetUrlsToRestoreOnStartup() const {
91 return ExtractList(prefs::kURLsToRestoreOnStartup);
94 scoped_ptr<base::ListValue> BrandcodedDefaultSettings::ExtractList(
95 const char* pref_name) const {
96 const base::ListValue* value = NULL;
97 if (master_dictionary_ &&
98 master_dictionary_->GetList(pref_name, &value) &&
99 !value->empty()) {
100 return scoped_ptr<base::ListValue>(value->DeepCopy());
102 return scoped_ptr<base::ListValue>();