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 "extensions/common/extension.h"
13 BrandcodedDefaultSettings::BrandcodedDefaultSettings() {
16 BrandcodedDefaultSettings::BrandcodedDefaultSettings(const std::string
& prefs
) {
18 JSONStringValueSerializer
json(prefs
);
20 scoped_ptr
<base::Value
> root(json
.Deserialize(NULL
, &error
));
22 VLOG(1) << "Failed to parse brandcode prefs file: " << error
;
25 if (!root
->IsType(base::Value::TYPE_DICTIONARY
)) {
26 VLOG(1) << "Failed to parse brandcode prefs file: "
27 << "Root item must be a dictionary.";
30 master_dictionary_
.reset(
31 static_cast<base::DictionaryValue
*>(root
.release()));
35 BrandcodedDefaultSettings::~BrandcodedDefaultSettings() {
38 scoped_ptr
<base::ListValue
>
39 BrandcodedDefaultSettings::GetSearchProviderOverrides() const {
40 return ExtractList(prefs::kSearchProviderOverrides
);
43 bool BrandcodedDefaultSettings::GetHomepage(std::string
* homepage
) const {
44 return master_dictionary_
&&
45 master_dictionary_
->GetString(prefs::kHomePage
, homepage
) &&
49 bool BrandcodedDefaultSettings::GetHomepageIsNewTab(
50 bool* homepage_is_ntp
) const {
51 return master_dictionary_
&&
52 master_dictionary_
->GetBoolean(prefs::kHomePageIsNewTabPage
,
56 bool BrandcodedDefaultSettings::GetShowHomeButton(
57 bool* show_home_button
) const {
58 return master_dictionary_
&&
59 master_dictionary_
->GetBoolean(prefs::kShowHomeButton
,
63 bool BrandcodedDefaultSettings::GetExtensions(
64 std::vector
<std::string
>* extension_ids
) const {
65 DCHECK(extension_ids
);
66 base::DictionaryValue
* extensions
= NULL
;
67 if (master_dictionary_
&&
68 master_dictionary_
->GetDictionary(
69 installer::master_preferences::kExtensionsBlock
,
71 for (base::DictionaryValue::Iterator
extension_id(*extensions
);
72 !extension_id
.IsAtEnd(); extension_id
.Advance()) {
73 if (extensions::Extension::IdIsValid(extension_id
.key()))
74 extension_ids
->push_back(extension_id
.key());
81 bool BrandcodedDefaultSettings::GetRestoreOnStartup(
82 int* restore_on_startup
) const {
83 return master_dictionary_
&&
84 master_dictionary_
->GetInteger(prefs::kRestoreOnStartup
,
88 scoped_ptr
<base::ListValue
>
89 BrandcodedDefaultSettings::GetUrlsToRestoreOnStartup() const {
90 return ExtractList(prefs::kURLsToRestoreOnStartup
);
93 scoped_ptr
<base::ListValue
> BrandcodedDefaultSettings::ExtractList(
94 const char* pref_name
) const {
95 const base::ListValue
* value
= NULL
;
96 if (master_dictionary_
&&
97 master_dictionary_
->GetList(pref_name
, &value
) &&
99 return scoped_ptr
<base::ListValue
>(value
->DeepCopy());
101 return scoped_ptr
<base::ListValue
>();