Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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/browser/component_updater/sw_reporter_installer_win.h" | 5 #include "chrome/browser/component_updater/sw_reporter_installer_win.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 | 114 |
| 115 void ReportExperimentError(SwReporterExperimentError error) { | 115 void ReportExperimentError(SwReporterExperimentError error) { |
| 116 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.ExperimentErrors", error, | 116 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.ExperimentErrors", error, |
| 117 SW_REPORTER_EXPERIMENT_ERROR_MAX); | 117 SW_REPORTER_EXPERIMENT_ERROR_MAX); |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Run the software reporter on the next Chrome startup after it's downloaded. | 120 // Run the software reporter on the next Chrome startup after it's downloaded. |
| 121 // (This is the default |reporter_runner| function passed to the | 121 // (This is the default |reporter_runner| function passed to the |
| 122 // |SwReporterInstallerTraits| constructor in |RegisterSwReporterComponent| | 122 // |SwReporterInstallerTraits| constructor in |RegisterSwReporterComponent| |
| 123 // below.) | 123 // below.) |
| 124 void RunSwReporterAfterStartup( | 124 void RunSwReportersAfterStartup( |
| 125 const safe_browsing::SwReporterInvocation& invocation, | 125 const safe_browsing::SwReporterQueue& invocations, |
| 126 const base::Version& version) { | 126 const base::Version& version) { |
| 127 content::BrowserThread::PostAfterStartupTask( | 127 content::BrowserThread::PostAfterStartupTask( |
| 128 FROM_HERE, base::ThreadTaskRunnerHandle::Get(), | 128 FROM_HERE, base::ThreadTaskRunnerHandle::Get(), |
| 129 base::Bind(&safe_browsing::RunSwReporter, invocation, version, | 129 base::Bind(&safe_browsing::RunSwReporters, invocations, version, |
| 130 base::ThreadTaskRunnerHandle::Get(), | 130 base::ThreadTaskRunnerHandle::Get(), |
| 131 base::WorkerPool::GetTaskRunner(true))); | 131 base::WorkerPool::GetTaskRunner(true))); |
| 132 } | 132 } |
| 133 | 133 |
| 134 // Ensures |str| contains only alphanumeric characters and characters from | 134 // Ensures |str| contains only alphanumeric characters and characters from |
| 135 // |extras|, and is not longer than |max_length|. | 135 // |extras|, and is not longer than |max_length|. |
| 136 bool ValidateString(const std::string& str, | 136 bool ValidateString(const std::string& str, |
| 137 const std::string& extras, | 137 const std::string& extras, |
| 138 size_t max_length) { | 138 size_t max_length) { |
| 139 return str.size() <= max_length && | 139 return str.size() <= max_length && |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 151 std::unique_ptr<base::DictionaryValue> manifest, | 151 std::unique_ptr<base::DictionaryValue> manifest, |
| 152 const SwReporterRunner& reporter_runner) { | 152 const SwReporterRunner& reporter_runner) { |
| 153 // The experiment requires launch_params so if they aren't present just | 153 // The experiment requires launch_params so if they aren't present just |
| 154 // return. This isn't an error because the user could get into the experiment | 154 // return. This isn't an error because the user could get into the experiment |
| 155 // group before they've downloaded the experiment component. | 155 // group before they've downloaded the experiment component. |
| 156 base::Value* launch_params = nullptr; | 156 base::Value* launch_params = nullptr; |
| 157 if (!manifest->Get("launch_params", &launch_params)) | 157 if (!manifest->Get("launch_params", &launch_params)) |
| 158 return; | 158 return; |
| 159 | 159 |
| 160 const base::ListValue* parameter_list = nullptr; | 160 const base::ListValue* parameter_list = nullptr; |
| 161 if (!launch_params->GetAsList(¶meter_list) || parameter_list->empty() || | 161 if (!launch_params->GetAsList(¶meter_list) || parameter_list->empty()) { |
| 162 // For future expansion, the manifest takes a list of invocation | |
| 163 // parameters, but currently we only support a single invocation. | |
| 164 parameter_list->GetSize() > 1) { | |
| 165 ReportExperimentError(SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS); | 162 ReportExperimentError(SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS); |
| 166 return; | 163 return; |
| 167 } | 164 } |
| 168 | 165 |
| 169 const base::DictionaryValue* invocation_params = nullptr; | 166 safe_browsing::SwReporterQueue invocations; |
| 170 if (!parameter_list->GetDictionary(0, &invocation_params)) { | 167 for (const auto& iter : *parameter_list) { |
| 171 ReportExperimentError(SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS); | 168 const base::DictionaryValue* invocation_params = nullptr; |
| 172 return; | 169 if (!iter->GetAsDictionary(&invocation_params)) { |
| 173 } | |
| 174 | |
| 175 // Max length of the registry and histogram suffix. Fairly arbitrary: the | |
| 176 // Windows registry accepts much longer keys, but we need to display this | |
| 177 // string in histograms as well. | |
| 178 constexpr size_t kMaxSuffixLength = 80; | |
| 179 | |
| 180 // The suffix must be an alphanumeric string. (Empty is fine as long as the | |
| 181 // "suffix" key is present.) | |
| 182 std::string suffix; | |
| 183 const base::Value* suffix_value = nullptr; | |
| 184 if (!invocation_params->Get("suffix", &suffix_value) || | |
| 185 !suffix_value->GetAsString(&suffix) || | |
| 186 (!suffix.empty() && | |
| 187 !ValidateString(suffix, std::string(), kMaxSuffixLength))) { | |
| 188 ReportExperimentError(SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS); | |
| 189 return; | |
| 190 } | |
| 191 | |
| 192 // Build a command line for the reporter out of the executable path and the | |
| 193 // arguments from the manifest. (The "arguments" key must be present, but | |
| 194 // it's ok if it's an empty list or a list of empty strings.) | |
| 195 std::vector<base::string16> argv = {exe_path.value()}; | |
| 196 const base::Value* arguments_value = nullptr; | |
| 197 const base::ListValue* arguments = nullptr; | |
| 198 if (!invocation_params->Get("arguments", &arguments_value) || | |
| 199 !arguments_value->GetAsList(&arguments)) { | |
| 200 ReportExperimentError(SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS); | |
| 201 return; | |
| 202 } | |
| 203 | |
| 204 for (const auto& value : *arguments) { | |
| 205 base::string16 argument; | |
| 206 if (!value->GetAsString(&argument)) { | |
| 207 ReportExperimentError(SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS); | 170 ReportExperimentError(SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS); |
| 208 return; | 171 return; |
| 209 } | 172 } |
| 210 if (!argument.empty()) | 173 |
| 211 argv.push_back(argument); | 174 // Max length of the registry and histogram suffix. Fairly arbitrary: the |
| 175 // Windows registry accepts much longer keys, but we need to display this | |
| 176 // string in histograms as well. | |
| 177 constexpr size_t kMaxSuffixLength = 80; | |
| 178 | |
| 179 // The suffix must be an alphanumeric string. (Empty is fine as long as the | |
| 180 // "suffix" key is present.) | |
| 181 std::string suffix; | |
| 182 const base::Value* suffix_value = nullptr; | |
| 183 if (!invocation_params->Get("suffix", &suffix_value) || | |
|
grt (UTC plus 2)
2016/09/01 21:08:55
if (!invocation_params->GetString("suffix", &suffi
Joe Mason
2016/09/02 02:24:30
Done.
| |
| 184 !suffix_value->GetAsString(&suffix) || | |
| 185 (!suffix.empty() && | |
|
grt (UTC plus 2)
2016/09/01 21:08:55
this check doesn't add anything beyond the comment
Joe Mason
2016/09/02 02:24:30
Done.
| |
| 186 !ValidateString(suffix, std::string(), kMaxSuffixLength))) { | |
| 187 ReportExperimentError(SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS); | |
| 188 return; | |
| 189 } | |
| 190 | |
| 191 // Build a command line for the reporter out of the executable path and the | |
| 192 // arguments from the manifest. (The "arguments" key must be present, but | |
| 193 // it's ok if it's an empty list or a list of empty strings.) | |
| 194 std::vector<base::string16> argv = {exe_path.value()}; | |
|
grt (UTC plus 2)
2016/09/01 21:08:55
nit: move down just before line 203
Joe Mason
2016/09/02 02:24:30
Done.
| |
| 195 const base::Value* arguments_value = nullptr; | |
| 196 const base::ListValue* arguments = nullptr; | |
| 197 if (!invocation_params->Get("arguments", &arguments_value) || | |
|
grt (UTC plus 2)
2016/09/01 21:08:55
if (!invocation_params->GetList("arguments", &argu
Joe Mason
2016/09/02 02:24:30
Done.
| |
| 198 !arguments_value->GetAsList(&arguments)) { | |
| 199 ReportExperimentError(SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS); | |
| 200 return; | |
| 201 } | |
| 202 | |
| 203 for (const auto& value : *arguments) { | |
| 204 base::string16 argument; | |
| 205 if (!value->GetAsString(&argument)) { | |
| 206 ReportExperimentError(SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS); | |
| 207 return; | |
| 208 } | |
| 209 if (!argument.empty()) | |
| 210 argv.push_back(argument); | |
| 211 } | |
| 212 | |
| 213 base::CommandLine command_line(argv); | |
| 214 | |
| 215 // Add the histogram suffix to the command-line as well, so that the | |
| 216 // reporter will add the same suffix to registry keys where it writes | |
| 217 // metrics. | |
| 218 if (!suffix.empty()) | |
| 219 command_line.AppendSwitchASCII("registry-suffix", suffix); | |
| 220 | |
| 221 // "prompt" is optional, but if present must be a boolean. | |
| 222 safe_browsing::SwReporterInvocation::Flags flags = 0; | |
| 223 const base::Value* prompt_value = nullptr; | |
| 224 if (invocation_params->Get("prompt", &prompt_value)) { | |
| 225 bool prompt = false; | |
| 226 if (!prompt_value->GetAsBoolean(&prompt)) { | |
| 227 ReportExperimentError(SW_REPORTER_EXPERIMENT_ERROR_BAD_PARAMS); | |
| 228 return; | |
| 229 } | |
| 230 if (prompt) | |
| 231 flags |= safe_browsing::SwReporterInvocation::FLAG_TRIGGER_PROMPT; | |
| 232 } | |
| 233 | |
| 234 auto invocation = | |
| 235 safe_browsing::SwReporterInvocation::FromCommandLine(command_line); | |
| 236 invocation.suffix = suffix; | |
| 237 invocation.flags = flags; | |
| 238 invocations.push(invocation); | |
| 212 } | 239 } |
| 213 | 240 |
| 214 base::CommandLine command_line(argv); | 241 DCHECK(!invocations.empty()); |
| 215 | 242 reporter_runner.Run(invocations, version); |
|
grt (UTC plus 2)
2016/09/01 21:08:55
how about std::move the collection into Run (and c
Joe Mason
2016/09/02 02:24:30
Done.
| |
| 216 // Add the histogram suffix to the command-line as well, so that the | |
| 217 // reporter will add the same suffix to registry keys where it writes | |
| 218 // metrics. | |
| 219 if (!suffix.empty()) | |
| 220 command_line.AppendSwitchASCII("registry-suffix", suffix); | |
| 221 | |
| 222 auto invocation = | |
| 223 safe_browsing::SwReporterInvocation::FromCommandLine(command_line); | |
| 224 invocation.suffix = suffix; | |
| 225 invocation.is_experimental = true; | |
| 226 | |
| 227 reporter_runner.Run(invocation, version); | |
| 228 } | 243 } |
| 229 | 244 |
| 230 } // namespace | 245 } // namespace |
| 231 | 246 |
| 232 SwReporterInstallerTraits::SwReporterInstallerTraits( | 247 SwReporterInstallerTraits::SwReporterInstallerTraits( |
| 233 const SwReporterRunner& reporter_runner, | 248 const SwReporterRunner& reporter_runner, |
| 234 bool is_experimental_engine_supported) | 249 bool is_experimental_engine_supported) |
| 235 : reporter_runner_(reporter_runner), | 250 : reporter_runner_(reporter_runner), |
| 236 is_experimental_engine_supported_(is_experimental_engine_supported) {} | 251 is_experimental_engine_supported_(is_experimental_engine_supported) {} |
| 237 | 252 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 261 void SwReporterInstallerTraits::ComponentReady( | 276 void SwReporterInstallerTraits::ComponentReady( |
| 262 const base::Version& version, | 277 const base::Version& version, |
| 263 const base::FilePath& install_dir, | 278 const base::FilePath& install_dir, |
| 264 std::unique_ptr<base::DictionaryValue> manifest) { | 279 std::unique_ptr<base::DictionaryValue> manifest) { |
| 265 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 280 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 266 const base::FilePath exe_path(install_dir.Append(kSwReporterExeName)); | 281 const base::FilePath exe_path(install_dir.Append(kSwReporterExeName)); |
| 267 if (IsExperimentalEngineEnabled()) { | 282 if (IsExperimentalEngineEnabled()) { |
| 268 RunExperimentalSwReporter(exe_path, version, std::move(manifest), | 283 RunExperimentalSwReporter(exe_path, version, std::move(manifest), |
| 269 reporter_runner_); | 284 reporter_runner_); |
| 270 } else { | 285 } else { |
| 271 reporter_runner_.Run( | 286 safe_browsing::SwReporterQueue invocations; |
| 272 safe_browsing::SwReporterInvocation::FromFilePath(exe_path), version); | 287 invocations.push( |
| 288 safe_browsing::SwReporterInvocation::FromFilePath(exe_path)); | |
| 289 reporter_runner_.Run(invocations, version); | |
| 273 } | 290 } |
| 274 } | 291 } |
| 275 | 292 |
| 276 base::FilePath SwReporterInstallerTraits::GetRelativeInstallDir() const { | 293 base::FilePath SwReporterInstallerTraits::GetRelativeInstallDir() const { |
| 277 return base::FilePath(FILE_PATH_LITERAL("SwReporter")); | 294 return base::FilePath(FILE_PATH_LITERAL("SwReporter")); |
| 278 } | 295 } |
| 279 | 296 |
| 280 void SwReporterInstallerTraits::GetHash(std::vector<uint8_t>* hash) const { | 297 void SwReporterInstallerTraits::GetHash(std::vector<uint8_t>* hash) const { |
| 281 DCHECK(hash); | 298 DCHECK(hash); |
| 282 hash->assign(kSha256Hash, kSha256Hash + sizeof(kSha256Hash)); | 299 hash->assign(kSha256Hash, kSha256Hash + sizeof(kSha256Hash)); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 } | 415 } |
| 399 | 416 |
| 400 // The experiment is only enabled on x86. There's no way to check this in the | 417 // The experiment is only enabled on x86. There's no way to check this in the |
| 401 // variations config so we'll hard-code it. | 418 // variations config so we'll hard-code it. |
| 402 const bool is_experimental_engine_supported = | 419 const bool is_experimental_engine_supported = |
| 403 base::win::OSInfo::GetInstance()->architecture() == | 420 base::win::OSInfo::GetInstance()->architecture() == |
| 404 base::win::OSInfo::X86_ARCHITECTURE; | 421 base::win::OSInfo::X86_ARCHITECTURE; |
| 405 | 422 |
| 406 // Install the component. | 423 // Install the component. |
| 407 std::unique_ptr<ComponentInstallerTraits> traits( | 424 std::unique_ptr<ComponentInstallerTraits> traits( |
| 408 new SwReporterInstallerTraits(base::Bind(&RunSwReporterAfterStartup), | 425 new SwReporterInstallerTraits(base::Bind(&RunSwReportersAfterStartup), |
| 409 is_experimental_engine_supported)); | 426 is_experimental_engine_supported)); |
| 410 // |cus| will take ownership of |installer| during installer->Register(cus). | 427 // |cus| will take ownership of |installer| during installer->Register(cus). |
| 411 DefaultComponentInstaller* installer = | 428 DefaultComponentInstaller* installer = |
| 412 new DefaultComponentInstaller(std::move(traits)); | 429 new DefaultComponentInstaller(std::move(traits)); |
| 413 installer->Register(cus, base::Closure()); | 430 installer->Register(cus, base::Closure()); |
| 414 } | 431 } |
| 415 | 432 |
| 416 void RegisterPrefsForSwReporter(PrefRegistrySimple* registry) { | 433 void RegisterPrefsForSwReporter(PrefRegistrySimple* registry) { |
| 417 registry->RegisterInt64Pref(prefs::kSwReporterLastTimeTriggered, 0); | 434 registry->RegisterInt64Pref(prefs::kSwReporterLastTimeTriggered, 0); |
| 418 registry->RegisterIntegerPref(prefs::kSwReporterLastExitCode, -1); | 435 registry->RegisterIntegerPref(prefs::kSwReporterLastExitCode, -1); |
| 419 registry->RegisterBooleanPref(prefs::kSwReporterPendingPrompt, false); | 436 registry->RegisterBooleanPref(prefs::kSwReporterPendingPrompt, false); |
| 420 } | 437 } |
| 421 | 438 |
| 422 void RegisterProfilePrefsForSwReporter( | 439 void RegisterProfilePrefsForSwReporter( |
| 423 user_prefs::PrefRegistrySyncable* registry) { | 440 user_prefs::PrefRegistrySyncable* registry) { |
| 424 registry->RegisterStringPref(prefs::kSwReporterPromptVersion, ""); | 441 registry->RegisterStringPref(prefs::kSwReporterPromptVersion, ""); |
| 425 | 442 |
| 426 registry->RegisterStringPref(prefs::kSwReporterPromptSeed, ""); | 443 registry->RegisterStringPref(prefs::kSwReporterPromptSeed, ""); |
| 427 } | 444 } |
| 428 | 445 |
| 429 } // namespace component_updater | 446 } // namespace component_updater |
| OLD | NEW |