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
) {
19 JSONStringValueSerializer
json(prefs
);
21 scoped_ptr
<base::Value
> root(json
.Deserialize(NULL
, &error
));
23 VLOG(1) << "Failed to parse brandcode prefs file: " << error
;
26 if (!root
->IsType(base::Value::TYPE_DICTIONARY
)) {
27 VLOG(1) << "Failed to parse brandcode prefs file: "
28 << "Root item must be a dictionary.";
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
) &&
50 bool BrandcodedDefaultSettings::GetHomepageIsNewTab(
51 bool* homepage_is_ntp
) const {
52 return master_dictionary_
&&
53 master_dictionary_
->GetBoolean(prefs::kHomePageIsNewTabPage
,
57 bool BrandcodedDefaultSettings::GetShowHomeButton(
58 bool* show_home_button
) const {
59 return master_dictionary_
&&
60 master_dictionary_
->GetBoolean(prefs::kShowHomeButton
,
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
,
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());
82 bool BrandcodedDefaultSettings::GetRestoreOnStartup(
83 int* restore_on_startup
) const {
84 return master_dictionary_
&&
85 master_dictionary_
->GetInteger(prefs::kRestoreOnStartup
,
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
) &&
100 return scoped_ptr
<base::ListValue
>(value
->DeepCopy());
102 return scoped_ptr
<base::ListValue
>();