• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "chrome/browser/profile_resetter/brandcoded_default_settings.h"
6 
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"
12 
BrandcodedDefaultSettings()13 BrandcodedDefaultSettings::BrandcodedDefaultSettings() {
14 }
15 
BrandcodedDefaultSettings(const std::string & prefs)16 BrandcodedDefaultSettings::BrandcodedDefaultSettings(const std::string& prefs) {
17   if (!prefs.empty()) {
18     JSONStringValueSerializer json(prefs);
19     std::string error;
20     scoped_ptr<base::Value> root(json.Deserialize(NULL, &error));
21     if (!root.get()) {
22       VLOG(1) << "Failed to parse brandcode prefs file: " << error;
23       return;
24     }
25     if (!root->IsType(base::Value::TYPE_DICTIONARY)) {
26       VLOG(1) << "Failed to parse brandcode prefs file: "
27               << "Root item must be a dictionary.";
28       return;
29     }
30     master_dictionary_.reset(
31         static_cast<base::DictionaryValue*>(root.release()));
32   }
33 }
34 
~BrandcodedDefaultSettings()35 BrandcodedDefaultSettings::~BrandcodedDefaultSettings() {
36 }
37 
GetSearchProviderOverrides() const38 scoped_ptr<ListValue> BrandcodedDefaultSettings::GetSearchProviderOverrides(
39     ) const {
40   return ExtractList(prefs::kSearchProviderOverrides);
41 }
42 
GetHomepage(std::string * homepage) const43 bool BrandcodedDefaultSettings::GetHomepage(std::string* homepage) const {
44   return master_dictionary_ &&
45          master_dictionary_->GetString(prefs::kHomePage, homepage) &&
46          !homepage->empty();
47 }
48 
GetHomepageIsNewTab(bool * homepage_is_ntp) const49 bool BrandcodedDefaultSettings::GetHomepageIsNewTab(
50     bool* homepage_is_ntp) const {
51   return master_dictionary_ &&
52          master_dictionary_->GetBoolean(prefs::kHomePageIsNewTabPage,
53                                         homepage_is_ntp);
54 }
55 
GetShowHomeButton(bool * show_home_button) const56 bool BrandcodedDefaultSettings::GetShowHomeButton(
57     bool* show_home_button) const {
58   return master_dictionary_ &&
59          master_dictionary_->GetBoolean(prefs::kShowHomeButton,
60                                         show_home_button);
61 }
62 
GetExtensions(std::vector<std::string> * extension_ids) const63 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,
70           &extensions)) {
71     for (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());
75     }
76     return true;
77   }
78   return false;
79 }
80 
GetRestoreOnStartup(int * restore_on_startup) const81 bool BrandcodedDefaultSettings::GetRestoreOnStartup(
82     int* restore_on_startup) const {
83   return master_dictionary_ &&
84          master_dictionary_->GetInteger(prefs::kRestoreOnStartup,
85                                         restore_on_startup);
86 }
87 
GetUrlsToRestoreOnStartup() const88 scoped_ptr<ListValue> BrandcodedDefaultSettings::GetUrlsToRestoreOnStartup(
89     ) const {
90   return ExtractList(prefs::kURLsToRestoreOnStartup);
91 }
92 
ExtractList(const char * pref_name) const93 scoped_ptr<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) &&
98       !value->empty()) {
99     return scoped_ptr<ListValue>(value->DeepCopy());
100   }
101   return scoped_ptr<ListValue>();
102 }
103