OLD | NEW |
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/files/file_util.h" | 8 #include "base/files/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" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 return static_cast<base::DictionaryValue*>(root.release()); | 66 return static_cast<base::DictionaryValue*>(root.release()); |
67 } | 67 } |
68 | 68 |
69 } // namespace | 69 } // namespace |
70 | 70 |
71 namespace installer { | 71 namespace installer { |
72 | 72 |
73 MasterPreferences::MasterPreferences() : distribution_(NULL), | 73 MasterPreferences::MasterPreferences() : distribution_(NULL), |
74 preferences_read_from_file_(false), | 74 preferences_read_from_file_(false), |
75 chrome_(true), | 75 chrome_(true), |
76 chrome_app_launcher_(false), | |
77 multi_install_(false) { | 76 multi_install_(false) { |
78 InitializeFromCommandLine(*base::CommandLine::ForCurrentProcess()); | 77 InitializeFromCommandLine(*base::CommandLine::ForCurrentProcess()); |
79 } | 78 } |
80 | 79 |
81 MasterPreferences::MasterPreferences(const base::CommandLine& cmd_line) | 80 MasterPreferences::MasterPreferences(const base::CommandLine& cmd_line) |
82 : distribution_(NULL), | 81 : distribution_(NULL), |
83 preferences_read_from_file_(false), | 82 preferences_read_from_file_(false), |
84 chrome_(true), | 83 chrome_(true), |
85 chrome_app_launcher_(false), | |
86 multi_install_(false) { | 84 multi_install_(false) { |
87 InitializeFromCommandLine(cmd_line); | 85 InitializeFromCommandLine(cmd_line); |
88 } | 86 } |
89 | 87 |
90 MasterPreferences::MasterPreferences(const base::FilePath& prefs_path) | 88 MasterPreferences::MasterPreferences(const base::FilePath& prefs_path) |
91 : distribution_(NULL), | 89 : distribution_(NULL), |
92 preferences_read_from_file_(false), | 90 preferences_read_from_file_(false), |
93 chrome_(true), | 91 chrome_(true), |
94 chrome_app_launcher_(false), | |
95 multi_install_(false) { | 92 multi_install_(false) { |
96 std::string json_data; | 93 std::string json_data; |
97 // Failure to read the file is ignored as |json_data| will be the empty string | 94 // Failure to read the file is ignored as |json_data| will be the empty string |
98 // and the remainder of this MasterPreferences object should still be | 95 // and the remainder of this MasterPreferences object should still be |
99 // initialized as best as possible. | 96 // initialized as best as possible. |
100 if (base::PathExists(prefs_path) && | 97 if (base::PathExists(prefs_path) && |
101 !base::ReadFileToString(prefs_path, &json_data)) { | 98 !base::ReadFileToString(prefs_path, &json_data)) { |
102 LOG(ERROR) << "Failed to read preferences from " << prefs_path.value(); | 99 LOG(ERROR) << "Failed to read preferences from " << prefs_path.value(); |
103 } | 100 } |
104 if (InitializeFromString(json_data)) | 101 if (InitializeFromString(json_data)) |
105 preferences_read_from_file_ = true; | 102 preferences_read_from_file_ = true; |
106 } | 103 } |
107 | 104 |
108 MasterPreferences::MasterPreferences(const std::string& prefs) | 105 MasterPreferences::MasterPreferences(const std::string& prefs) |
109 : distribution_(NULL), | 106 : distribution_(NULL), |
110 preferences_read_from_file_(false), | 107 preferences_read_from_file_(false), |
111 chrome_(true), | 108 chrome_(true), |
112 chrome_app_launcher_(false), | |
113 multi_install_(false) { | 109 multi_install_(false) { |
114 InitializeFromString(prefs); | 110 InitializeFromString(prefs); |
115 } | 111 } |
116 | 112 |
117 MasterPreferences::~MasterPreferences() { | 113 MasterPreferences::~MasterPreferences() { |
118 } | 114 } |
119 | 115 |
120 void MasterPreferences::InitializeFromCommandLine( | 116 void MasterPreferences::InitializeFromCommandLine( |
121 const base::CommandLine& cmd_line) { | 117 const base::CommandLine& cmd_line) { |
122 #if defined(OS_WIN) | 118 #if defined(OS_WIN) |
123 if (cmd_line.HasSwitch(installer::switches::kInstallerData)) { | 119 if (cmd_line.HasSwitch(installer::switches::kInstallerData)) { |
124 base::FilePath prefs_path(cmd_line.GetSwitchValuePath( | 120 base::FilePath prefs_path(cmd_line.GetSwitchValuePath( |
125 installer::switches::kInstallerData)); | 121 installer::switches::kInstallerData)); |
126 this->MasterPreferences::MasterPreferences(prefs_path); | 122 this->MasterPreferences::MasterPreferences(prefs_path); |
127 } else { | 123 } else { |
128 master_dictionary_.reset(new base::DictionaryValue()); | 124 master_dictionary_.reset(new base::DictionaryValue()); |
129 } | 125 } |
130 | 126 |
131 DCHECK(master_dictionary_.get()); | 127 DCHECK(master_dictionary_.get()); |
132 | 128 |
133 // A simple map from command line switches to equivalent switches in the | 129 // A simple map from command line switches to equivalent switches in the |
134 // distribution dictionary. Currently all switches added will be set to | 130 // distribution dictionary. Currently all switches added will be set to |
135 // 'true'. | 131 // 'true'. |
136 static const struct CmdLineSwitchToDistributionSwitch { | 132 static const struct CmdLineSwitchToDistributionSwitch { |
137 const char* cmd_line_switch; | 133 const char* cmd_line_switch; |
138 const char* distribution_switch; | 134 const char* distribution_switch; |
139 } translate_switches[] = { | 135 } translate_switches[] = { |
140 { installer::switches::kAutoLaunchChrome, | 136 { installer::switches::kAutoLaunchChrome, |
141 installer::master_preferences::kAutoLaunchChrome }, | 137 installer::master_preferences::kAutoLaunchChrome }, |
142 { installer::switches::kChromeAppHostDeprecated, | |
143 installer::master_preferences::kChromeAppHostDeprecated }, | |
144 { installer::switches::kChromeAppLauncher, | |
145 installer::master_preferences::kChromeAppLauncher }, | |
146 { installer::switches::kChrome, | 138 { installer::switches::kChrome, |
147 installer::master_preferences::kChrome }, | 139 installer::master_preferences::kChrome }, |
148 { installer::switches::kDisableLogging, | 140 { installer::switches::kDisableLogging, |
149 installer::master_preferences::kDisableLogging }, | 141 installer::master_preferences::kDisableLogging }, |
150 { installer::switches::kMsi, | 142 { installer::switches::kMsi, |
151 installer::master_preferences::kMsi }, | 143 installer::master_preferences::kMsi }, |
152 { installer::switches::kMultiInstall, | 144 { installer::switches::kMultiInstall, |
153 installer::master_preferences::kMultiInstall }, | 145 installer::master_preferences::kMultiInstall }, |
154 { installer::switches::kDoNotRegisterForUpdateLaunch, | 146 { installer::switches::kDoNotRegisterForUpdateLaunch, |
155 installer::master_preferences::kDoNotRegisterForUpdateLaunch }, | 147 installer::master_preferences::kDoNotRegisterForUpdateLaunch }, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 } | 210 } |
219 | 211 |
220 InitializeProductFlags(); | 212 InitializeProductFlags(); |
221 EnforceLegacyPreferences(); | 213 EnforceLegacyPreferences(); |
222 return data_is_valid; | 214 return data_is_valid; |
223 } | 215 } |
224 | 216 |
225 void MasterPreferences::InitializeProductFlags() { | 217 void MasterPreferences::InitializeProductFlags() { |
226 // Make sure we start out with the correct defaults. | 218 // Make sure we start out with the correct defaults. |
227 multi_install_ = false; | 219 multi_install_ = false; |
228 chrome_app_launcher_ = false; | |
229 chrome_ = true; | 220 chrome_ = true; |
230 | 221 |
231 GetBool(installer::master_preferences::kMultiInstall, &multi_install_); | 222 GetBool(installer::master_preferences::kMultiInstall, &multi_install_); |
232 | 223 |
233 GetBool(installer::master_preferences::kChromeAppLauncher, | |
234 &chrome_app_launcher_); | |
235 | |
236 // The deprecated switch --app-host behaves like --app-launcher. | |
237 bool chrome_app_host = false; | |
238 GetBool(installer::master_preferences::kChromeAppHostDeprecated, | |
239 &chrome_app_host); | |
240 chrome_app_launcher_ = chrome_app_launcher_ || chrome_app_host; | |
241 | |
242 // When multi-install is specified, the checks are pretty simple (in theory): | 224 // When multi-install is specified, the checks are pretty simple (in theory): |
243 // In order to be installed/uninstalled, each product must have its switch | 225 // In order to be installed/uninstalled, each product must have its switch |
244 // present on the command line. | 226 // present on the command line. |
245 // When multi-install is not set, operate on Chrome. | 227 // When multi-install is not set, operate on Chrome. |
246 if (multi_install_) { | 228 if (multi_install_) { |
247 if (!GetBool(installer::master_preferences::kChrome, &chrome_)) | 229 if (!GetBool(installer::master_preferences::kChrome, &chrome_)) |
248 chrome_ = false; | 230 chrome_ = false; |
249 } else { | 231 } else { |
250 chrome_ = true; | 232 chrome_ = true; |
251 } | 233 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 } | 310 } |
329 return result; | 311 return result; |
330 } | 312 } |
331 | 313 |
332 // static | 314 // static |
333 const MasterPreferences& MasterPreferences::ForCurrentProcess() { | 315 const MasterPreferences& MasterPreferences::ForCurrentProcess() { |
334 return g_master_preferences.Get(); | 316 return g_master_preferences.Get(); |
335 } | 317 } |
336 | 318 |
337 } // namespace installer | 319 } // namespace installer |
OLD | NEW |