blob: 922073aa31581d494efad55b31e0efc06517577e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/profile_resetter/brandcoded_default_settings.h"
#include "base/json/json_string_value_serializer.h"
#include "base/logging.h"
#include "chrome/common/pref_names.h"
#include "chrome/installer/util/master_preferences_constants.h"
#include "extensions/common/extension.h"
BrandcodedDefaultSettings::BrandcodedDefaultSettings() {
}
BrandcodedDefaultSettings::BrandcodedDefaultSettings(const std::string& prefs) {
if (!prefs.empty()) {
JSONStringValueSerializer json(prefs);
std::string error;
scoped_ptr<base::Value> root(json.Deserialize(NULL, &error));
if (!root.get()) {
VLOG(1) << "Failed to parse brandcode prefs file: " << error;
return;
}
if (!root->IsType(base::Value::TYPE_DICTIONARY)) {
VLOG(1) << "Failed to parse brandcode prefs file: "
<< "Root item must be a dictionary.";
return;
}
master_dictionary_.reset(
static_cast<base::DictionaryValue*>(root.release()));
}
}
BrandcodedDefaultSettings::~BrandcodedDefaultSettings() {
}
scoped_ptr<base::ListValue>
BrandcodedDefaultSettings::GetSearchProviderOverrides() const {
return ExtractList(prefs::kSearchProviderOverrides);
}
bool BrandcodedDefaultSettings::GetHomepage(std::string* homepage) const {
return master_dictionary_ &&
master_dictionary_->GetString(prefs::kHomePage, homepage) &&
!homepage->empty();
}
bool BrandcodedDefaultSettings::GetHomepageIsNewTab(
bool* homepage_is_ntp) const {
return master_dictionary_ &&
master_dictionary_->GetBoolean(prefs::kHomePageIsNewTabPage,
homepage_is_ntp);
}
bool BrandcodedDefaultSettings::GetShowHomeButton(
bool* show_home_button) const {
return master_dictionary_ &&
master_dictionary_->GetBoolean(prefs::kShowHomeButton,
show_home_button);
}
bool BrandcodedDefaultSettings::GetExtensions(
std::vector<std::string>* extension_ids) const {
DCHECK(extension_ids);
base::DictionaryValue* extensions = NULL;
if (master_dictionary_ &&
master_dictionary_->GetDictionary(
installer::master_preferences::kExtensionsBlock,
&extensions)) {
for (base::DictionaryValue::Iterator extension_id(*extensions);
!extension_id.IsAtEnd(); extension_id.Advance()) {
if (extensions::Extension::IdIsValid(extension_id.key()))
extension_ids->push_back(extension_id.key());
}
return true;
}
return false;
}
bool BrandcodedDefaultSettings::GetRestoreOnStartup(
int* restore_on_startup) const {
return master_dictionary_ &&
master_dictionary_->GetInteger(prefs::kRestoreOnStartup,
restore_on_startup);
}
scoped_ptr<base::ListValue>
BrandcodedDefaultSettings::GetUrlsToRestoreOnStartup() const {
return ExtractList(prefs::kURLsToRestoreOnStartup);
}
scoped_ptr<base::ListValue> BrandcodedDefaultSettings::ExtractList(
const char* pref_name) const {
const base::ListValue* value = NULL;
if (master_dictionary_ &&
master_dictionary_->GetList(pref_name, &value) &&
!value->empty()) {
return scoped_ptr<base::ListValue>(value->DeepCopy());
}
return scoped_ptr<base::ListValue>();
}
|