Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(554)

Side by Side Diff: chrome/installer/util/master_preferences.cc

Issue 17034006: Add base namespace to more values in sync and elsewhere. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/policy/policy_map.h ('k') | chrome/tools/build/generate_policy_source.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/installer/util/master_preferences.h" 5 #include "chrome/installer/util/master_preferences.h"
6 6
7 #include "base/environment.h" 7 #include "base/environment.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/json/json_string_value_serializer.h" 9 #include "base/json/json_string_value_serializer.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "chrome/common/env_vars.h" 14 #include "chrome/common/env_vars.h"
15 #include "chrome/common/pref_names.h" 15 #include "chrome/common/pref_names.h"
16 #include "chrome/installer/util/master_preferences_constants.h" 16 #include "chrome/installer/util/master_preferences_constants.h"
17 #include "chrome/installer/util/util_constants.h" 17 #include "chrome/installer/util/util_constants.h"
18 18
19 namespace { 19 namespace {
20 20
21 const char kFirstRunTabs[] = "first_run_tabs"; 21 const char kFirstRunTabs[] = "first_run_tabs";
22 22
23 base::LazyInstance<installer::MasterPreferences> g_master_preferences = 23 base::LazyInstance<installer::MasterPreferences> g_master_preferences =
24 LAZY_INSTANCE_INITIALIZER; 24 LAZY_INSTANCE_INITIALIZER;
25 25
26 bool GetURLFromValue(const Value* in_value, std::string* out_value) { 26 bool GetURLFromValue(const base::Value* in_value, std::string* out_value) {
27 return in_value && out_value && in_value->GetAsString(out_value); 27 return in_value && out_value && in_value->GetAsString(out_value);
28 } 28 }
29 29
30 std::vector<std::string> GetNamedList(const char* name, 30 std::vector<std::string> GetNamedList(const char* name,
31 const DictionaryValue* prefs) { 31 const base::DictionaryValue* prefs) {
32 std::vector<std::string> list; 32 std::vector<std::string> list;
33 if (!prefs) 33 if (!prefs)
34 return list; 34 return list;
35 35
36 const ListValue* value_list = NULL; 36 const base::ListValue* value_list = NULL;
37 if (!prefs->GetList(name, &value_list)) 37 if (!prefs->GetList(name, &value_list))
38 return list; 38 return list;
39 39
40 list.reserve(value_list->GetSize()); 40 list.reserve(value_list->GetSize());
41 for (size_t i = 0; i < value_list->GetSize(); ++i) { 41 for (size_t i = 0; i < value_list->GetSize(); ++i) {
42 const Value* entry; 42 const base::Value* entry;
43 std::string url_entry; 43 std::string url_entry;
44 if (!value_list->Get(i, &entry) || !GetURLFromValue(entry, &url_entry)) { 44 if (!value_list->Get(i, &entry) || !GetURLFromValue(entry, &url_entry)) {
45 NOTREACHED(); 45 NOTREACHED();
46 break; 46 break;
47 } 47 }
48 list.push_back(url_entry); 48 list.push_back(url_entry);
49 } 49 }
50 return list; 50 return list;
51 } 51 }
52 52
53 DictionaryValue* ParseDistributionPreferences(const std::string& json_data) { 53 base::DictionaryValue* ParseDistributionPreferences(
54 const std::string& json_data) {
54 JSONStringValueSerializer json(json_data); 55 JSONStringValueSerializer json(json_data);
55 std::string error; 56 std::string error;
56 scoped_ptr<Value> root(json.Deserialize(NULL, &error)); 57 scoped_ptr<base::Value> root(json.Deserialize(NULL, &error));
57 if (!root.get()) { 58 if (!root.get()) {
58 LOG(WARNING) << "Failed to parse master prefs file: " << error; 59 LOG(WARNING) << "Failed to parse master prefs file: " << error;
59 return NULL; 60 return NULL;
60 } 61 }
61 if (!root->IsType(Value::TYPE_DICTIONARY)) { 62 if (!root->IsType(base::Value::TYPE_DICTIONARY)) {
62 LOG(WARNING) << "Failed to parse master prefs file: " 63 LOG(WARNING) << "Failed to parse master prefs file: "
63 << "Root item must be a dictionary."; 64 << "Root item must be a dictionary.";
64 return NULL; 65 return NULL;
65 } 66 }
66 return static_cast<DictionaryValue*>(root.release()); 67 return static_cast<base::DictionaryValue*>(root.release());
67 } 68 }
68 69
69 } // namespace 70 } // namespace
70 71
71 namespace installer { 72 namespace installer {
72 73
73 MasterPreferences::MasterPreferences() : distribution_(NULL), 74 MasterPreferences::MasterPreferences() : distribution_(NULL),
74 preferences_read_from_file_(false), 75 preferences_read_from_file_(false),
75 chrome_(true), 76 chrome_(true),
76 chrome_app_launcher_(false), 77 chrome_app_launcher_(false),
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 MasterPreferences::~MasterPreferences() { 122 MasterPreferences::~MasterPreferences() {
122 } 123 }
123 124
124 void MasterPreferences::InitializeFromCommandLine(const CommandLine& cmd_line) { 125 void MasterPreferences::InitializeFromCommandLine(const CommandLine& cmd_line) {
125 #if defined(OS_WIN) 126 #if defined(OS_WIN)
126 if (cmd_line.HasSwitch(installer::switches::kInstallerData)) { 127 if (cmd_line.HasSwitch(installer::switches::kInstallerData)) {
127 base::FilePath prefs_path(cmd_line.GetSwitchValuePath( 128 base::FilePath prefs_path(cmd_line.GetSwitchValuePath(
128 installer::switches::kInstallerData)); 129 installer::switches::kInstallerData));
129 this->MasterPreferences::MasterPreferences(prefs_path); 130 this->MasterPreferences::MasterPreferences(prefs_path);
130 } else { 131 } else {
131 master_dictionary_.reset(new DictionaryValue()); 132 master_dictionary_.reset(new base::DictionaryValue());
132 } 133 }
133 134
134 DCHECK(master_dictionary_.get()); 135 DCHECK(master_dictionary_.get());
135 136
136 // A simple map from command line switches to equivalent switches in the 137 // A simple map from command line switches to equivalent switches in the
137 // distribution dictionary. Currently all switches added will be set to 138 // distribution dictionary. Currently all switches added will be set to
138 // 'true'. 139 // 'true'.
139 static const struct CmdLineSwitchToDistributionSwitch { 140 static const struct CmdLineSwitchToDistributionSwitch {
140 const char* cmd_line_switch; 141 const char* cmd_line_switch;
141 const char* distribution_switch; 142 const char* distribution_switch;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 InitializeProductFlags(); 210 InitializeProductFlags();
210 #endif 211 #endif
211 } 212 }
212 213
213 bool MasterPreferences::InitializeFromString(const std::string& json_data) { 214 bool MasterPreferences::InitializeFromString(const std::string& json_data) {
214 if (!json_data.empty()) 215 if (!json_data.empty())
215 master_dictionary_.reset(ParseDistributionPreferences(json_data)); 216 master_dictionary_.reset(ParseDistributionPreferences(json_data));
216 217
217 bool data_is_valid = true; 218 bool data_is_valid = true;
218 if (!master_dictionary_.get()) { 219 if (!master_dictionary_.get()) {
219 master_dictionary_.reset(new DictionaryValue()); 220 master_dictionary_.reset(new base::DictionaryValue());
220 data_is_valid = false; 221 data_is_valid = false;
221 } else { 222 } else {
222 // Cache a pointer to the distribution dictionary. 223 // Cache a pointer to the distribution dictionary.
223 master_dictionary_->GetDictionary( 224 master_dictionary_->GetDictionary(
224 installer::master_preferences::kDistroDict, &distribution_); 225 installer::master_preferences::kDistroDict, &distribution_);
225 } 226 }
226 227
227 InitializeProductFlags(); 228 InitializeProductFlags();
228 EnforceLegacyPreferences(); 229 EnforceLegacyPreferences();
229 return data_is_valid; 230 return data_is_valid;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 bool ret = false; 299 bool ret = false;
299 if (distribution_) 300 if (distribution_)
300 ret = (distribution_->GetString(name, value) && !value->empty()); 301 ret = (distribution_->GetString(name, value) && !value->empty());
301 return ret; 302 return ret;
302 } 303 }
303 304
304 std::vector<std::string> MasterPreferences::GetFirstRunTabs() const { 305 std::vector<std::string> MasterPreferences::GetFirstRunTabs() const {
305 return GetNamedList(kFirstRunTabs, master_dictionary_.get()); 306 return GetNamedList(kFirstRunTabs, master_dictionary_.get());
306 } 307 }
307 308
308 bool MasterPreferences::GetExtensionsBlock(DictionaryValue** extensions) const { 309 bool MasterPreferences::GetExtensionsBlock(
310 base::DictionaryValue** extensions) const {
309 return master_dictionary_->GetDictionary( 311 return master_dictionary_->GetDictionary(
310 master_preferences::kExtensionsBlock, extensions); 312 master_preferences::kExtensionsBlock, extensions);
311 } 313 }
312 314
313 std::string MasterPreferences::GetVariationsSeed() const { 315 std::string MasterPreferences::GetVariationsSeed() const {
314 std::string variations_seed; 316 std::string variations_seed;
315 master_dictionary_->GetString(prefs::kVariationsSeed, &variations_seed); 317 master_dictionary_->GetString(prefs::kVariationsSeed, &variations_seed);
316 return variations_seed; 318 return variations_seed;
317 } 319 }
318 320
319 // static 321 // static
320 const MasterPreferences& MasterPreferences::ForCurrentProcess() { 322 const MasterPreferences& MasterPreferences::ForCurrentProcess() {
321 return g_master_preferences.Get(); 323 return g_master_preferences.Get();
322 } 324 }
323 325
324 } // namespace installer 326 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/browser/policy/policy_map.h ('k') | chrome/tools/build/generate_policy_source.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698