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 <map> | 10 #include <map> |
| 10 #include <memory> | 11 #include <memory> |
| 11 #include <string> | 12 #include <string> |
| 12 #include <utility> | 13 #include <utility> |
| 13 #include <vector> | 14 #include <vector> |
| 14 | 15 |
| 15 #include "base/base_paths.h" | 16 #include "base/base_paths.h" |
| 17 #include "base/command_line.h" | |
| 18 #include "base/feature_list.h" | |
| 16 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
| 17 #include "base/files/file_util.h" | 20 #include "base/files/file_util.h" |
| 18 #include "base/logging.h" | 21 #include "base/logging.h" |
| 19 #include "base/metrics/histogram.h" | 22 #include "base/metrics/histogram.h" |
| 20 #include "base/metrics/sparse_histogram.h" | 23 #include "base/metrics/sparse_histogram.h" |
| 21 #include "base/path_service.h" | 24 #include "base/path_service.h" |
| 22 #include "base/strings/string_tokenizer.h" | 25 #include "base/strings/string_tokenizer.h" |
| 26 #include "base/strings/stringprintf.h" | |
| 27 #include "base/strings/utf_string_conversions.h" | |
| 28 #include "base/sys_info.h" | |
| 23 #include "base/threading/thread_task_runner_handle.h" | 29 #include "base/threading/thread_task_runner_handle.h" |
| 24 #include "base/threading/worker_pool.h" | 30 #include "base/threading/worker_pool.h" |
| 25 #include "base/time/time.h" | 31 #include "base/time/time.h" |
| 26 #include "base/win/registry.h" | 32 #include "base/win/registry.h" |
| 27 #include "chrome/browser/browser_process.h" | 33 #include "chrome/browser/browser_process.h" |
| 28 #include "chrome/browser/safe_browsing/srt_fetcher_win.h" | 34 #include "chrome/browser/safe_browsing/srt_fetcher_win.h" |
| 29 #include "chrome/browser/safe_browsing/srt_field_trial_win.h" | 35 #include "chrome/browser/safe_browsing/srt_field_trial_win.h" |
| 30 #include "components/component_updater/component_updater_paths.h" | 36 #include "components/component_updater/component_updater_paths.h" |
| 31 #include "components/component_updater/component_updater_service.h" | 37 #include "components/component_updater/component_updater_service.h" |
| 32 #include "components/component_updater/default_component_installer.h" | 38 #include "components/component_updater/default_component_installer.h" |
| 33 #include "components/component_updater/pref_names.h" | 39 #include "components/component_updater/pref_names.h" |
| 34 #include "components/pref_registry/pref_registry_syncable.h" | 40 #include "components/pref_registry/pref_registry_syncable.h" |
| 35 #include "components/prefs/pref_registry_simple.h" | 41 #include "components/prefs/pref_registry_simple.h" |
| 36 #include "components/update_client/update_client.h" | 42 #include "components/update_client/update_client.h" |
| 37 #include "components/update_client/utils.h" | 43 #include "components/update_client/utils.h" |
| 44 #include "components/variations/variations_associated_data.h" | |
| 38 #include "content/public/browser/browser_thread.h" | 45 #include "content/public/browser/browser_thread.h" |
| 46 #include "third_party/re2/src/re2/re2.h" | |
| 39 | 47 |
| 40 namespace component_updater { | 48 namespace component_updater { |
| 41 | 49 |
| 42 namespace { | 50 namespace { |
| 43 | 51 |
| 44 // These two sets of values are used to send UMA information and are replicated | 52 // These two sets of values are used to send UMA information and are replicated |
| 45 // in the histograms.xml file, so the order MUST NOT CHANGE. | 53 // in the histograms.xml file, so the order MUST NOT CHANGE. |
| 46 enum SRTCompleted { | 54 enum SRTCompleted { |
| 47 SRT_COMPLETED_NOT_YET = 0, | 55 SRT_COMPLETED_NOT_YET = 0, |
| 48 SRT_COMPLETED_YES = 1, | 56 SRT_COMPLETED_YES = 1, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 60 | 68 |
| 61 const base::FilePath::CharType kSwReporterExeName[] = | 69 const base::FilePath::CharType kSwReporterExeName[] = |
| 62 FILE_PATH_LITERAL("software_reporter_tool.exe"); | 70 FILE_PATH_LITERAL("software_reporter_tool.exe"); |
| 63 | 71 |
| 64 // SRT registry keys and value names. | 72 // SRT registry keys and value names. |
| 65 const wchar_t kCleanerSuffixRegistryKey[] = L"Cleaner"; | 73 const wchar_t kCleanerSuffixRegistryKey[] = L"Cleaner"; |
| 66 const wchar_t kExitCodeValueName[] = L"ExitCode"; | 74 const wchar_t kExitCodeValueName[] = L"ExitCode"; |
| 67 const wchar_t kUploadResultsValueName[] = L"UploadResults"; | 75 const wchar_t kUploadResultsValueName[] = L"UploadResults"; |
| 68 const wchar_t kVersionValueName[] = L"Version"; | 76 const wchar_t kVersionValueName[] = L"Version"; |
| 69 | 77 |
| 78 // Experiment parameters for the new engine. | |
| 79 const base::Feature kExperimentalEngineFeature{ | |
| 80 "ExperimentalSwReporterEngine", base::FEATURE_DISABLED_BY_DEFAULT}; | |
| 81 | |
| 82 const char kExperimentalEngineTagParam[] = "tag"; | |
| 83 const re2::RE2 kExperimentalEngineArgsParam = "args(\\d+)"; | |
| 84 const re2::RE2 kExperimentalEngineSuffixParam = "suffix(\\d+)"; | |
| 85 | |
| 70 void SRTHasCompleted(SRTCompleted value) { | 86 void SRTHasCompleted(SRTCompleted value) { |
| 71 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.Cleaner.HasCompleted", value, | 87 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.Cleaner.HasCompleted", value, |
| 72 SRT_COMPLETED_MAX); | 88 SRT_COMPLETED_MAX); |
| 73 } | 89 } |
| 74 | 90 |
| 75 void ReportUploadsWithUma(const base::string16& upload_results) { | 91 void ReportUploadsWithUma(const base::string16& upload_results) { |
| 76 base::WStringTokenizer tokenizer(upload_results, L";"); | 92 base::WStringTokenizer tokenizer(upload_results, L";"); |
| 77 int failure_count = 0; | 93 int failure_count = 0; |
| 78 int success_count = 0; | 94 int success_count = 0; |
| 79 int longest_failure_run = 0; | 95 int longest_failure_run = 0; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 96 | 112 |
| 97 UMA_HISTOGRAM_COUNTS_100("SoftwareReporter.UploadFailureCount", | 113 UMA_HISTOGRAM_COUNTS_100("SoftwareReporter.UploadFailureCount", |
| 98 failure_count); | 114 failure_count); |
| 99 UMA_HISTOGRAM_COUNTS_100("SoftwareReporter.UploadSuccessCount", | 115 UMA_HISTOGRAM_COUNTS_100("SoftwareReporter.UploadSuccessCount", |
| 100 success_count); | 116 success_count); |
| 101 UMA_HISTOGRAM_COUNTS_100("SoftwareReporter.UploadLongestFailureRun", | 117 UMA_HISTOGRAM_COUNTS_100("SoftwareReporter.UploadLongestFailureRun", |
| 102 longest_failure_run); | 118 longest_failure_run); |
| 103 UMA_HISTOGRAM_BOOLEAN("SoftwareReporter.LastUploadResult", last_result); | 119 UMA_HISTOGRAM_BOOLEAN("SoftwareReporter.LastUploadResult", last_result); |
| 104 } | 120 } |
| 105 | 121 |
| 122 bool IsExperimentalEngineEnabled() { | |
| 123 // The experiment is only enabled on x86. Finch doesn't have a way to check | |
| 124 // this so we'll hard-code it. | |
| 125 if (base::SysInfo::OperatingSystemArchitecture() != "x86") | |
| 126 return false; | |
| 127 | |
| 128 return base::FeatureList::IsEnabled(kExperimentalEngineFeature); | |
| 129 } | |
| 130 | |
| 106 class SwReporterInstallerTraits : public ComponentInstallerTraits { | 131 class SwReporterInstallerTraits : public ComponentInstallerTraits { |
| 107 public: | 132 public: |
| 108 SwReporterInstallerTraits() {} | 133 SwReporterInstallerTraits() {} |
| 109 | 134 |
| 110 ~SwReporterInstallerTraits() override {} | 135 ~SwReporterInstallerTraits() override {} |
| 111 | 136 |
| 112 bool VerifyInstallation(const base::DictionaryValue& manifest, | 137 bool VerifyInstallation(const base::DictionaryValue& manifest, |
| 113 const base::FilePath& dir) const override { | 138 const base::FilePath& dir) const override { |
| 114 return base::PathExists(dir.Append(kSwReporterExeName)); | 139 return base::PathExists(dir.Append(kSwReporterExeName)); |
| 115 } | 140 } |
| 116 | 141 |
| 117 bool SupportsGroupPolicyEnabledComponentUpdates() const override { | 142 bool SupportsGroupPolicyEnabledComponentUpdates() const override { |
| 118 return true; | 143 return true; |
| 119 } | 144 } |
| 120 | 145 |
| 121 bool RequiresNetworkEncryption() const override { return false; } | 146 bool RequiresNetworkEncryption() const override { return false; } |
| 122 | 147 |
| 123 bool OnCustomInstall(const base::DictionaryValue& manifest, | 148 bool OnCustomInstall(const base::DictionaryValue& manifest, |
| 124 const base::FilePath& install_dir) override { | 149 const base::FilePath& install_dir) override { |
| 125 return true; | 150 return true; |
| 126 } | 151 } |
| 127 | 152 |
| 128 void ComponentReady( | 153 void ComponentReady( |
| 129 const base::Version& version, | 154 const base::Version& version, |
| 130 const base::FilePath& install_dir, | 155 const base::FilePath& install_dir, |
| 131 std::unique_ptr<base::DictionaryValue> manifest) override { | 156 std::unique_ptr<base::DictionaryValue> manifest) override { |
| 132 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 157 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 133 safe_browsing::RunSwReporter(install_dir.Append(kSwReporterExeName), | 158 |
| 134 version, base::ThreadTaskRunnerHandle::Get(), | 159 base::FilePath exe_path(install_dir.Append(kSwReporterExeName)); |
| 160 | |
| 161 // If this user is getting the experimental engine, read the command-line | |
| 162 // params and an UMA histogram suffix from the experiment parameters. | |
| 163 if (IsExperimentalEngineEnabled()) { | |
| 164 // TODO(joenotcharles): check the version or manifest to make sure we | |
| 165 // actually got an experimental version (unless in the control group). | |
| 166 std::vector<safe_browsing::SwReporterInvocation> invocations; | |
| 167 | |
| 168 // Command-line arguments are passed as args0, args1, ..., argsN. | |
| 169 // Suffixes are passed as suffix0, suffix1, ..., suffixN. | |
| 170 // | |
| 171 // Read all the parameters whose names match these patterns into maps, | |
| 172 // then make sure that all indices 0 through N are stored in both maps. | |
| 173 // If any are missing, the experiment config is badly formatted. If it's | |
| 174 // ok, add each pair (command line, suffix) to the invocations vector. | |
| 175 std::map<std::string, std::string> experiment_params; | |
| 176 if (variations::GetVariationParamsByFeature(kExperimentalEngineFeature, | |
| 177 &experiment_params)) { | |
| 178 std::map<int, std::string> arg_strings; | |
| 179 std::map<int, std::string> suffixes; | |
| 180 unsigned int max_index = 0; | |
| 181 for (const auto& param : experiment_params) { | |
| 182 unsigned int index = 0; | |
| 183 if (re2::RE2::FullMatch(param.first, kExperimentalEngineArgsParam, | |
| 184 &index)) { | |
| 185 arg_strings[index] = param.second; | |
| 186 max_index = std::max(index, max_index); | |
| 187 } else if (re2::RE2::FullMatch(param.first, | |
| 188 kExperimentalEngineSuffixParam, &index)) { | |
| 189 suffixes[index] = param.second; | |
| 190 max_index = std::max(index, max_index); | |
| 191 } | |
| 192 } | |
| 193 | |
| 194 invocations.reserve(max_index + 1); | |
| 195 for (unsigned int i = 0; i < max_index; ++i) { | |
| 196 auto args = arg_strings.find(i); | |
| 197 auto suffix = suffixes.find(i); | |
| 198 if (args == arg_strings.end() || | |
| 199 suffix == suffixes.end()) { | |
| 200 // TODO(joenotcharles): Report bad finch config. | |
| 201 invocations.clear(); | |
| 202 break; | |
| 203 } | |
| 204 | |
| 205 // Construct the command-line using a placeholder which is guaranteed | |
| 206 // not to need quoting for arg 0. Then replace it with the real path, | |
| 207 // which may contain spaces and other weirdness. | |
| 208 auto command_line = base::CommandLine::FromString(base::UTF8ToUTF16( | |
| 209 base::StringPrintf("%s %s", kSwReporterExeName, args->second))); | |
| 210 command_line.SetProgram(exe_path); | |
| 211 | |
| 212 // Add the histogram suffix to the command-line as well, so that the | |
| 213 // reporter will add the same suffix to registry keys where it writes | |
| 214 // metrics. | |
| 215 command_line.AppendSwitchNative("registry-suffix", | |
| 216 base::UTF8ToUTF16(suffix->second)); | |
|
Joe Mason
2016/08/09 15:24:26
pmbureau: This is what I was talking about in the
| |
| 217 | |
| 218 invocations[i] = safe_browsing::SwReporterInvocation( | |
| 219 command_line, suffix->second); | |
| 220 } | |
| 221 } | |
| 222 | |
| 223 // If there were no explicit command-lines found, fall through to the | |
| 224 // default invocation which is the binary name without arguments. | |
| 225 if (!invocations.empty()) { | |
| 226 safe_browsing::RunExperimentalSwReporters(invocations, version, | |
| 227 base::ThreadTaskRunnerHandle::Get(), | |
| 228 base::WorkerPool::GetTaskRunner(true)); | |
| 229 return; | |
| 230 } | |
| 231 } | |
| 232 | |
| 233 safe_browsing::RunSwReporter(exe_path, version, | |
| 234 base::ThreadTaskRunnerHandle::Get(), | |
| 135 base::WorkerPool::GetTaskRunner(true)); | 235 base::WorkerPool::GetTaskRunner(true)); |
| 136 } | 236 } |
| 137 | 237 |
| 138 base::FilePath GetRelativeInstallDir() const override { | 238 base::FilePath GetRelativeInstallDir() const override { |
| 139 return base::FilePath(FILE_PATH_LITERAL("SwReporter")); | 239 return base::FilePath(FILE_PATH_LITERAL("SwReporter")); |
| 140 } | 240 } |
| 141 | 241 |
| 142 void GetHash(std::vector<uint8_t>* hash) const override { GetPkHash(hash); } | 242 void GetHash(std::vector<uint8_t>* hash) const override { GetPkHash(hash); } |
| 143 | 243 |
| 144 std::string GetName() const override { return "Software Reporter Tool"; } | 244 std::string GetName() const override { return "Software Reporter Tool"; } |
| 145 | 245 |
| 146 update_client::InstallerAttributes GetInstallerAttributes() const override { | 246 update_client::InstallerAttributes GetInstallerAttributes() const override { |
| 147 return update_client::InstallerAttributes(); | 247 update_client::InstallerAttributes attributes; |
| 248 if (IsExperimentalEngineEnabled()) { | |
| 249 // Pass the "tag" parameter to the installer; it will be used to choose | |
| 250 // which binary is downloaded. | |
| 251 std::string tag = variations::GetVariationParamValueByFeature( | |
| 252 kExperimentalEngineFeature, kExperimentalEngineTagParam); | |
| 253 if (!tag.empty()) | |
| 254 attributes[kExperimentalEngineTagParam] = tag; | |
| 255 } | |
| 256 return attributes; | |
| 148 } | 257 } |
| 149 std::vector<std::string> GetMimeTypes() const override { | 258 std::vector<std::string> GetMimeTypes() const override { |
| 150 return std::vector<std::string>(); | 259 return std::vector<std::string>(); |
| 151 } | 260 } |
| 152 | 261 |
| 153 static std::string ID() { | 262 static std::string ID() { |
| 154 update_client::CrxComponent component; | 263 update_client::CrxComponent component; |
| 155 component.version = Version("0.0.0.0"); | 264 component.version = Version("0.0.0.0"); |
| 156 GetPkHash(&component.pk_hash); | 265 GetPkHash(&component.pk_hash); |
| 157 return update_client::GetCrxComponentID(component); | 266 return update_client::GetCrxComponentID(component); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 } | 367 } |
| 259 | 368 |
| 260 void RegisterProfilePrefsForSwReporter( | 369 void RegisterProfilePrefsForSwReporter( |
| 261 user_prefs::PrefRegistrySyncable* registry) { | 370 user_prefs::PrefRegistrySyncable* registry) { |
| 262 registry->RegisterStringPref(prefs::kSwReporterPromptVersion, ""); | 371 registry->RegisterStringPref(prefs::kSwReporterPromptVersion, ""); |
| 263 | 372 |
| 264 registry->RegisterStringPref(prefs::kSwReporterPromptSeed, ""); | 373 registry->RegisterStringPref(prefs::kSwReporterPromptSeed, ""); |
| 265 } | 374 } |
| 266 | 375 |
| 267 } // namespace component_updater | 376 } // namespace component_updater |
| OLD | NEW |