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 const base::Feature kExperimentalEngineFeature{ | |
79 "ExperimentalSwReporterEngine", base::FEATURE_DISABLED_BY_DEFAULT}; | |
80 | |
70 void SRTHasCompleted(SRTCompleted value) { | 81 void SRTHasCompleted(SRTCompleted value) { |
71 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.Cleaner.HasCompleted", value, | 82 UMA_HISTOGRAM_ENUMERATION("SoftwareReporter.Cleaner.HasCompleted", value, |
72 SRT_COMPLETED_MAX); | 83 SRT_COMPLETED_MAX); |
73 } | 84 } |
74 | 85 |
75 void ReportUploadsWithUma(const base::string16& upload_results) { | 86 void ReportUploadsWithUma(const base::string16& upload_results) { |
76 base::WStringTokenizer tokenizer(upload_results, L";"); | 87 base::WStringTokenizer tokenizer(upload_results, L";"); |
77 int failure_count = 0; | 88 int failure_count = 0; |
78 int success_count = 0; | 89 int success_count = 0; |
79 int longest_failure_run = 0; | 90 int longest_failure_run = 0; |
(...skipping 16 matching lines...) Expand all Loading... | |
96 | 107 |
97 UMA_HISTOGRAM_COUNTS_100("SoftwareReporter.UploadFailureCount", | 108 UMA_HISTOGRAM_COUNTS_100("SoftwareReporter.UploadFailureCount", |
98 failure_count); | 109 failure_count); |
99 UMA_HISTOGRAM_COUNTS_100("SoftwareReporter.UploadSuccessCount", | 110 UMA_HISTOGRAM_COUNTS_100("SoftwareReporter.UploadSuccessCount", |
100 success_count); | 111 success_count); |
101 UMA_HISTOGRAM_COUNTS_100("SoftwareReporter.UploadLongestFailureRun", | 112 UMA_HISTOGRAM_COUNTS_100("SoftwareReporter.UploadLongestFailureRun", |
102 longest_failure_run); | 113 longest_failure_run); |
103 UMA_HISTOGRAM_BOOLEAN("SoftwareReporter.LastUploadResult", last_result); | 114 UMA_HISTOGRAM_BOOLEAN("SoftwareReporter.LastUploadResult", last_result); |
104 } | 115 } |
105 | 116 |
117 bool IsExperimentalEngineEnabled() { | |
118 // The experiment is only enabled on x86. Finch doesn't have a way to check | |
grt (UTC plus 2)
2016/08/10 06:47:01
nit: please avoid "finch" if possible. i suggest:
Joe Mason
2016/08/15 17:24:39
Done.
| |
119 // this so we'll hard-code it. | |
120 if (base::SysInfo::OperatingSystemArchitecture() != "x86") | |
121 return false; | |
122 | |
123 return base::FeatureList::IsEnabled(kExperimentalEngineFeature); | |
124 } | |
125 | |
106 class SwReporterInstallerTraits : public ComponentInstallerTraits { | 126 class SwReporterInstallerTraits : public ComponentInstallerTraits { |
107 public: | 127 public: |
108 SwReporterInstallerTraits() {} | 128 SwReporterInstallerTraits() {} |
109 | 129 |
110 ~SwReporterInstallerTraits() override {} | 130 ~SwReporterInstallerTraits() override {} |
111 | 131 |
112 bool VerifyInstallation(const base::DictionaryValue& manifest, | 132 bool VerifyInstallation(const base::DictionaryValue& manifest, |
113 const base::FilePath& dir) const override { | 133 const base::FilePath& dir) const override { |
114 return base::PathExists(dir.Append(kSwReporterExeName)); | 134 return base::PathExists(dir.Append(kSwReporterExeName)); |
115 } | 135 } |
116 | 136 |
117 bool SupportsGroupPolicyEnabledComponentUpdates() const override { | 137 bool SupportsGroupPolicyEnabledComponentUpdates() const override { |
118 return true; | 138 return true; |
119 } | 139 } |
120 | 140 |
121 bool RequiresNetworkEncryption() const override { return false; } | 141 bool RequiresNetworkEncryption() const override { return false; } |
122 | 142 |
123 bool OnCustomInstall(const base::DictionaryValue& manifest, | 143 bool OnCustomInstall(const base::DictionaryValue& manifest, |
124 const base::FilePath& install_dir) override { | 144 const base::FilePath& install_dir) override { |
125 return true; | 145 return true; |
126 } | 146 } |
127 | 147 |
128 void ComponentReady( | 148 void ComponentReady( |
129 const base::Version& version, | 149 const base::Version& version, |
130 const base::FilePath& install_dir, | 150 const base::FilePath& install_dir, |
131 std::unique_ptr<base::DictionaryValue> manifest) override { | 151 std::unique_ptr<base::DictionaryValue> manifest) override { |
132 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 152 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
133 safe_browsing::RunSwReporter(install_dir.Append(kSwReporterExeName), | 153 |
134 version, base::ThreadTaskRunnerHandle::Get(), | 154 base::FilePath exe_path(install_dir.Append(kSwReporterExeName)); |
155 | |
156 // If this user is getting the experimental engine, read the command-line | |
157 // params and an UMA histogram suffix from the experiment parameters. | |
158 if (IsExperimentalEngineEnabled()) { | |
159 // TODO(joenotcharles): check the version or manifest to make sure we | |
160 // actually got an experimental version (unless in the control group). | |
161 std::vector<safe_browsing::SwReporterInvocation> invocations; | |
grt (UTC plus 2)
2016/08/10 06:47:01
the items in this vector are copied wholesale each
Joe Mason
2016/08/15 17:24:39
I'll switch to a queue, since the interface makes
grt (UTC plus 2)
2016/08/15 19:39:39
From my perspective, unique_ptr is the right thing
macourteau
2016/09/12 19:53:14
Done.
| |
162 | |
163 // Command-line arguments are passed as args0, args1, ..., argsN. | |
164 // Suffixes are passed as suffix0, suffix1, ..., suffixN. | |
165 // | |
166 // Read all the parameters whose names match these patterns into maps, | |
167 // then make sure that all indices 0 through N are stored in both maps. | |
168 // If any are missing, the experiment config is badly formatted. If it's | |
169 // ok, add each pair (command line, suffix) to the invocations vector. | |
170 std::map<std::string, std::string> experiment_params; | |
171 if (variations::GetVariationParamsByFeature(kExperimentalEngineFeature, | |
172 &experiment_params)) { | |
173 re2::RE2 args_pattern("args(\\d+)"); | |
csharp
2016/08/11 18:58:02
What about pulling this args and suffix creation c
Joe Mason
2016/08/15 17:24:39
Done.
| |
174 std::map<int, std::string> arg_strings; | |
175 | |
176 re2::RE2 suffix_pattern("suffix(\\d+)"); | |
177 std::map<int, std::string> suffixes; | |
178 | |
179 unsigned int max_index = 0; | |
grt (UTC plus 2)
2016/08/10 06:47:01
"unsigned int" is frowned upon (https://google.git
Joe Mason
2016/08/15 17:24:39
Done.
| |
180 for (const auto& param : experiment_params) { | |
grt (UTC plus 2)
2016/08/10 06:47:01
nit: param -> param_and_value or something like th
Joe Mason
2016/08/15 17:24:39
Done.
| |
181 unsigned int index = 0; | |
182 if (re2::RE2::FullMatch(param.first, args_pattern, &index)) { | |
183 arg_strings[index] = param.second; | |
184 max_index = std::max(index, max_index); | |
csharp
2016/08/11 18:58:02
nit: What about moving this line outside the if st
Joe Mason
2016/08/15 17:24:39
Done.
| |
185 } else if (re2::RE2::FullMatch(param.first, suffix_pattern, &index)) { | |
186 suffixes[index] = param.second; | |
187 max_index = std::max(index, max_index); | |
188 } | |
189 } | |
190 | |
191 invocations.reserve(max_index + 1); | |
192 for (unsigned int i = 0; i < max_index; ++i) { | |
193 auto args = arg_strings.find(i); | |
194 auto suffix = suffixes.find(i); | |
195 if (args == arg_strings.end() || | |
196 suffix == suffixes.end()) { | |
197 // TODO(joenotcharles): Report bad finch config. | |
198 invocations.clear(); | |
199 break; | |
csharp
2016/08/11 18:58:02
Shouldn't this return here, it seems a bit odd to
Joe Mason
2016/08/15 17:24:39
As we discussed, it now doesn't run the reporter a
| |
200 } | |
201 | |
202 // Construct the command-line using a placeholder which is guaranteed | |
203 // not to need quoting for arg 0. Then replace it with the real path, | |
grt (UTC plus 2)
2016/08/10 06:47:01
why jump through these hoops? Does CommandLine not
Joe Mason
2016/08/15 17:24:39
CommandLine doesn't have any method to append a st
| |
204 // which may contain spaces and other weirdness. | |
205 auto command_line = base::CommandLine::FromString(base::UTF8ToUTF16( | |
206 base::StringPrintf("%s %s", kSwReporterExeName, args->second))); | |
grt (UTC plus 2)
2016/08/10 06:47:01
kSwReporterExeName is a wide char literal on Windo
Joe Mason
2016/08/15 17:24:39
Done.
| |
207 command_line.SetProgram(exe_path); | |
208 | |
209 // Add the histogram suffix to the command-line as well, so that the | |
210 // reporter will add the same suffix to registry keys where it writes | |
211 // metrics. | |
212 command_line.AppendSwitchNative("registry-suffix", | |
213 base::UTF8ToUTF16(suffix->second)); | |
grt (UTC plus 2)
2016/08/10 06:47:01
can you guarantee that the suffixes are ASCII? if
Joe Mason
2016/08/15 17:24:39
Done.
| |
214 | |
215 invocations[i] = safe_browsing::SwReporterInvocation( | |
216 command_line, suffix->second); | |
217 } | |
218 } | |
219 | |
220 // If there were no explicit command-lines found, fall through to the | |
221 // default invocation which is the binary name without arguments. | |
222 if (!invocations.empty()) { | |
223 safe_browsing::RunExperimentalSwReporters(invocations, version, | |
224 base::ThreadTaskRunnerHandle::Get(), | |
225 base::WorkerPool::GetTaskRunner(true)); | |
226 return; | |
227 } | |
228 } | |
229 | |
230 safe_browsing::RunSwReporter(exe_path, version, | |
231 base::ThreadTaskRunnerHandle::Get(), | |
135 base::WorkerPool::GetTaskRunner(true)); | 232 base::WorkerPool::GetTaskRunner(true)); |
136 } | 233 } |
137 | 234 |
138 base::FilePath GetRelativeInstallDir() const override { | 235 base::FilePath GetRelativeInstallDir() const override { |
139 return base::FilePath(FILE_PATH_LITERAL("SwReporter")); | 236 return base::FilePath(FILE_PATH_LITERAL("SwReporter")); |
140 } | 237 } |
141 | 238 |
142 void GetHash(std::vector<uint8_t>* hash) const override { GetPkHash(hash); } | 239 void GetHash(std::vector<uint8_t>* hash) const override { GetPkHash(hash); } |
143 | 240 |
144 std::string GetName() const override { return "Software Reporter Tool"; } | 241 std::string GetName() const override { return "Software Reporter Tool"; } |
145 | 242 |
146 update_client::InstallerAttributes GetInstallerAttributes() const override { | 243 update_client::InstallerAttributes GetInstallerAttributes() const override { |
147 return update_client::InstallerAttributes(); | 244 update_client::InstallerAttributes attributes; |
245 if (IsExperimentalEngineEnabled()) { | |
246 // Pass the "tag" parameter to the installer; it will be used to choose | |
247 // which binary is downloaded. | |
248 static const char kTagParam[] = "tag"; | |
grt (UTC plus 2)
2016/08/10 06:47:01
static const -> constexpr
Joe Mason
2016/08/15 17:24:39
Done.
| |
249 std::string tag = variations::GetVariationParamValueByFeature( | |
250 kExperimentalEngineFeature, kTagParam); | |
251 if (!tag.empty()) | |
252 attributes[kTagParam] = tag; | |
253 } | |
254 return attributes; | |
148 } | 255 } |
149 std::vector<std::string> GetMimeTypes() const override { | 256 std::vector<std::string> GetMimeTypes() const override { |
150 return std::vector<std::string>(); | 257 return std::vector<std::string>(); |
151 } | 258 } |
152 | 259 |
153 static std::string ID() { | 260 static std::string ID() { |
154 update_client::CrxComponent component; | 261 update_client::CrxComponent component; |
155 component.version = Version("0.0.0.0"); | 262 component.version = Version("0.0.0.0"); |
156 GetPkHash(&component.pk_hash); | 263 GetPkHash(&component.pk_hash); |
157 return update_client::GetCrxComponentID(component); | 264 return update_client::GetCrxComponentID(component); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 } | 365 } |
259 | 366 |
260 void RegisterProfilePrefsForSwReporter( | 367 void RegisterProfilePrefsForSwReporter( |
261 user_prefs::PrefRegistrySyncable* registry) { | 368 user_prefs::PrefRegistrySyncable* registry) { |
262 registry->RegisterStringPref(prefs::kSwReporterPromptVersion, ""); | 369 registry->RegisterStringPref(prefs::kSwReporterPromptVersion, ""); |
263 | 370 |
264 registry->RegisterStringPref(prefs::kSwReporterPromptSeed, ""); | 371 registry->RegisterStringPref(prefs::kSwReporterPromptSeed, ""); |
265 } | 372 } |
266 | 373 |
267 } // namespace component_updater | 374 } // namespace component_updater |
OLD | NEW |