OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/safe_browsing/srt_fetcher_win.h" | 5 #include "chrome/browser/safe_browsing/srt_fetcher_win.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 #include "net/base/load_flags.h" | 49 #include "net/base/load_flags.h" |
50 #include "net/http/http_status_code.h" | 50 #include "net/http/http_status_code.h" |
51 #include "net/url_request/url_fetcher.h" | 51 #include "net/url_request/url_fetcher.h" |
52 #include "net/url_request/url_fetcher_delegate.h" | 52 #include "net/url_request/url_fetcher_delegate.h" |
53 #include "net/url_request/url_request_context_getter.h" | 53 #include "net/url_request/url_request_context_getter.h" |
54 | 54 |
55 using content::BrowserThread; | 55 using content::BrowserThread; |
56 | 56 |
57 namespace safe_browsing { | 57 namespace safe_browsing { |
58 | 58 |
59 // TODO(b/647763) Change the registry key to properly handle cases when the user | |
60 // runs Google Chrome stable alongside Google Chrome SxS. | |
59 const wchar_t kSoftwareRemovalToolRegistryKey[] = | 61 const wchar_t kSoftwareRemovalToolRegistryKey[] = |
60 L"Software\\Google\\Software Removal Tool"; | 62 L"Software\\Google\\Software Removal Tool"; |
61 | 63 |
62 const wchar_t kCleanerSubKey[] = L"Cleaner"; | 64 const wchar_t kCleanerSubKey[] = L"Cleaner"; |
63 | 65 |
64 const wchar_t kEndTimeValueName[] = L"EndTime"; | 66 const wchar_t kEndTimeValueName[] = L"EndTime"; |
65 const wchar_t kStartTimeValueName[] = L"StartTime"; | 67 const wchar_t kStartTimeValueName[] = L"StartTime"; |
66 | 68 |
67 const char kExtendedSafeBrowsingEnabledSwitch[] = | 69 const char kExtendedSafeBrowsingEnabledSwitch[] = |
68 "extended-safebrowsing-enabled"; | 70 "extended-safebrowsing-enabled"; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 SW_REPORTER_NO_LOCAL_STATE = 9, | 107 SW_REPORTER_NO_LOCAL_STATE = 9, |
106 SW_REPORTER_NO_PROMPT_NEEDED = 10, | 108 SW_REPORTER_NO_PROMPT_NEEDED = 10, |
107 SW_REPORTER_NO_PROMPT_FIELD_TRIAL = 11, | 109 SW_REPORTER_NO_PROMPT_FIELD_TRIAL = 11, |
108 SW_REPORTER_ALREADY_PROMPTED = 12, | 110 SW_REPORTER_ALREADY_PROMPTED = 12, |
109 SW_REPORTER_RAN_DAILY = 13, | 111 SW_REPORTER_RAN_DAILY = 13, |
110 SW_REPORTER_ADDED_TO_MENU = 14, | 112 SW_REPORTER_ADDED_TO_MENU = 14, |
111 | 113 |
112 SW_REPORTER_MAX, | 114 SW_REPORTER_MAX, |
113 }; | 115 }; |
114 | 116 |
117 // Used to send UMA information showing whether uploading of Software Reporter | |
118 // logs is enabled, or the reason why not. | |
119 // Replicated in the histograms.xml file, so the order MUST NOT CHANGE. | |
120 enum SwReporterLogsUploadsEnabled { | |
121 REPORTER_LOGS_UPLOADS_ENABLED = 0, | |
122 REPORTER_LOGS_UPLOADS_SBER_DISABLED = 1, | |
123 REPORTER_LOGS_UPLOADS_RECENTLY_SENT_LOGS = 2, | |
124 REPORTER_LOGS_UPLOADS_MAX, | |
125 }; | |
126 | |
115 const char kRunningTimeErrorMetricName[] = | 127 const char kRunningTimeErrorMetricName[] = |
116 "SoftwareReporter.RunningTimeRegistryError"; | 128 "SoftwareReporter.RunningTimeRegistryError"; |
117 | 129 |
118 SwReporterTestingDelegate* g_testing_delegate_ = nullptr; | 130 SwReporterTestingDelegate* g_testing_delegate_ = nullptr; |
119 | 131 |
120 const wchar_t kScanTimesSubKey[] = L"ScanTimes"; | 132 const wchar_t kScanTimesSubKey[] = L"ScanTimes"; |
121 const wchar_t kFoundUwsValueName[] = L"FoundUws"; | 133 const wchar_t kFoundUwsValueName[] = L"FoundUws"; |
122 const wchar_t kMemoryUsedValueName[] = L"MemoryUsed"; | 134 const wchar_t kMemoryUsedValueName[] = L"MemoryUsed"; |
135 const wchar_t kLogsUploadResultValueName[] = L"LogsUploadResult"; | |
123 | 136 |
124 const char kFoundUwsMetricName[] = "SoftwareReporter.FoundUwS"; | 137 const char kFoundUwsMetricName[] = "SoftwareReporter.FoundUwS"; |
125 const char kFoundUwsReadErrorMetricName[] = | 138 const char kFoundUwsReadErrorMetricName[] = |
126 "SoftwareReporter.FoundUwSReadError"; | 139 "SoftwareReporter.FoundUwSReadError"; |
127 const char kScanTimesMetricName[] = "SoftwareReporter.UwSScanTimes"; | 140 const char kScanTimesMetricName[] = "SoftwareReporter.UwSScanTimes"; |
128 const char kMemoryUsedMetricName[] = "SoftwareReporter.MemoryUsed"; | 141 const char kMemoryUsedMetricName[] = "SoftwareReporter.MemoryUsed"; |
142 const char kLogsUploadEnabledMetricName[] = | |
143 "SoftwareReporter.LogsUploadEnabled"; | |
144 const char kLogsUploadResultMetricName[] = "SoftwareReporter.LogsUploadResult"; | |
145 | |
146 // The max value for histogram SoftwareReporter.LogsUploadResult, which is used | |
147 // to send UMA information about the result of Software Reporter's attempt to | |
148 // upload logs, when logs are enabled. This value must be consistent with the | |
149 // SoftwareReporterLogsUploadResult enum defined in the histograms.xml file. | |
150 const int kSwReporterLogsUploadResultMax = 7; | |
129 | 151 |
130 // Reports metrics about the software reporter via UMA (and sometimes Rappor). | 152 // Reports metrics about the software reporter via UMA (and sometimes Rappor). |
131 class UMAHistogramReporter { | 153 class UMAHistogramReporter { |
132 public: | 154 public: |
133 UMAHistogramReporter() : UMAHistogramReporter(std::string()) {} | 155 UMAHistogramReporter() : UMAHistogramReporter(std::string()) {} |
134 | 156 |
135 explicit UMAHistogramReporter(const std::string& suffix) | 157 explicit UMAHistogramReporter(const std::string& suffix) |
136 : suffix_(suffix), | 158 : suffix_(suffix), |
137 registry_key_(suffix.empty() ? kSoftwareRemovalToolRegistryKey | 159 registry_key_(suffix.empty() ? kSoftwareRemovalToolRegistryKey |
138 : base::StringPrintf( | 160 : base::StringPrintf( |
(...skipping 29 matching lines...) Expand all Loading... | |
168 } | 190 } |
169 RecordSparseHistogram("SoftwareReporter.MajorVersion", major_version); | 191 RecordSparseHistogram("SoftwareReporter.MajorVersion", major_version); |
170 } | 192 } |
171 | 193 |
172 void ReportExitCode(int exit_code) const { | 194 void ReportExitCode(int exit_code) const { |
173 RecordSparseHistogram("SoftwareReporter.ExitCode", exit_code); | 195 RecordSparseHistogram("SoftwareReporter.ExitCode", exit_code); |
174 } | 196 } |
175 | 197 |
176 // Reports UwS found by the software reporter tool via UMA and RAPPOR. | 198 // Reports UwS found by the software reporter tool via UMA and RAPPOR. |
177 void ReportFoundUwS(bool use_rappor) const { | 199 void ReportFoundUwS(bool use_rappor) const { |
178 base::win::RegKey reporter_key(HKEY_CURRENT_USER, registry_key_.c_str(), | 200 base::win::RegKey reporter_key; |
179 KEY_QUERY_VALUE | KEY_SET_VALUE); | |
180 std::vector<base::string16> found_uws_strings; | 201 std::vector<base::string16> found_uws_strings; |
181 if (reporter_key.Valid() && | 202 if (reporter_key.Open(HKEY_CURRENT_USER, registry_key_.c_str(), |
182 reporter_key.ReadValues(kFoundUwsValueName, &found_uws_strings) == | 203 KEY_QUERY_VALUE | KEY_SET_VALUE) != ERROR_SUCCESS || |
204 reporter_key.ReadValues(kFoundUwsValueName, &found_uws_strings) != | |
183 ERROR_SUCCESS) { | 205 ERROR_SUCCESS) { |
184 rappor::RapporService* rappor_service = nullptr; | 206 return; |
185 if (use_rappor) | 207 } |
186 rappor_service = g_browser_process->rappor_service(); | |
187 | 208 |
188 bool parse_error = false; | 209 rappor::RapporService* rappor_service = nullptr; |
189 for (const base::string16& uws_string : found_uws_strings) { | 210 if (use_rappor) |
190 // All UwS ids are expected to be integers. | 211 rappor_service = g_browser_process->rappor_service(); |
191 uint32_t uws_id = 0; | 212 |
192 if (base::StringToUint(uws_string, &uws_id)) { | 213 bool parse_error = false; |
193 RecordSparseHistogram(kFoundUwsMetricName, uws_id); | 214 for (const base::string16& uws_string : found_uws_strings) { |
194 if (rappor_service) { | 215 // All UwS ids are expected to be integers. |
195 rappor_service->RecordSample(kFoundUwsMetricName, | 216 uint32_t uws_id = 0; |
196 rappor::COARSE_RAPPOR_TYPE, | 217 if (base::StringToUint(uws_string, &uws_id)) { |
197 base::UTF16ToUTF8(uws_string)); | 218 RecordSparseHistogram(kFoundUwsMetricName, uws_id); |
198 } | 219 if (rappor_service) { |
199 } else { | 220 rappor_service->RecordSample(kFoundUwsMetricName, |
200 parse_error = true; | 221 rappor::COARSE_RAPPOR_TYPE, |
222 base::UTF16ToUTF8(uws_string)); | |
201 } | 223 } |
224 } else { | |
225 parse_error = true; | |
202 } | 226 } |
203 | 227 |
204 // Clean up the old value. | 228 // Clean up the old value. |
205 reporter_key.DeleteValue(kFoundUwsValueName); | 229 reporter_key.DeleteValue(kFoundUwsValueName); |
206 | 230 |
207 RecordBooleanHistogram(kFoundUwsReadErrorMetricName, parse_error); | 231 RecordBooleanHistogram(kFoundUwsReadErrorMetricName, parse_error); |
208 } | 232 } |
209 } | 233 } |
210 | 234 |
211 // Reports to UMA the memory usage of the software reporter tool as reported | 235 // Reports to UMA the memory usage of the software reporter tool as reported |
212 // by the tool itself in the Windows registry. | 236 // by the tool itself in the Windows registry. |
213 void ReportMemoryUsage() const { | 237 void ReportMemoryUsage() const { |
214 base::win::RegKey reporter_key(HKEY_CURRENT_USER, registry_key_.c_str(), | 238 base::win::RegKey reporter_key; |
215 KEY_QUERY_VALUE | KEY_SET_VALUE); | |
216 DWORD memory_used = 0; | 239 DWORD memory_used = 0; |
217 if (reporter_key.Valid() && | 240 if (reporter_key.Open(HKEY_CURRENT_USER, registry_key_.c_str(), |
218 reporter_key.ReadValueDW(kMemoryUsedValueName, &memory_used) == | 241 KEY_QUERY_VALUE | KEY_SET_VALUE) != ERROR_SUCCESS || |
242 reporter_key.ReadValueDW(kMemoryUsedValueName, &memory_used) != | |
219 ERROR_SUCCESS) { | 243 ERROR_SUCCESS) { |
220 RecordMemoryKBHistogram(kMemoryUsedMetricName, memory_used); | 244 return; |
221 reporter_key.DeleteValue(kMemoryUsedValueName); | |
222 } | 245 } |
246 RecordMemoryKBHistogram(kMemoryUsedMetricName, memory_used); | |
247 reporter_key.DeleteValue(kMemoryUsedValueName); | |
223 } | 248 } |
224 | 249 |
225 // Reports the SwReporter run time with UMA both as reported by the tool via | 250 // Reports the SwReporter run time with UMA both as reported by the tool via |
226 // the registry and as measured by |ReporterRunner|. | 251 // the registry and as measured by |ReporterRunner|. |
227 void ReportRuntime(const base::TimeDelta& reporter_running_time) const { | 252 void ReportRuntime(const base::TimeDelta& reporter_running_time) const { |
228 RecordLongTimesHistogram("SoftwareReporter.RunningTimeAccordingToChrome", | 253 RecordLongTimesHistogram("SoftwareReporter.RunningTimeAccordingToChrome", |
229 reporter_running_time); | 254 reporter_running_time); |
230 | 255 |
231 // TODO(b/641081): This should only have KEY_QUERY_VALUE and KEY_SET_VALUE, | 256 // TODO(b/641081): This should only have KEY_QUERY_VALUE and KEY_SET_VALUE. |
232 // and use Open to avoid creating the key if it doesn't already exist. | 257 base::win::RegKey reporter_key; |
233 base::win::RegKey reporter_key(HKEY_CURRENT_USER, registry_key_.c_str(), | 258 if (reporter_key.Open(HKEY_CURRENT_USER, registry_key_.c_str(), |
234 KEY_ALL_ACCESS); | 259 KEY_ALL_ACCESS) != ERROR_SUCCESS) { |
235 if (!reporter_key.Valid()) { | |
236 RecordEnumerationHistogram( | 260 RecordEnumerationHistogram( |
237 kRunningTimeErrorMetricName, | 261 kRunningTimeErrorMetricName, |
238 REPORTER_RUNNING_TIME_ERROR_REGISTRY_KEY_INVALID, | 262 REPORTER_RUNNING_TIME_ERROR_REGISTRY_KEY_INVALID, |
239 REPORTER_RUNNING_TIME_ERROR_MAX); | 263 REPORTER_RUNNING_TIME_ERROR_MAX); |
240 return; | 264 return; |
241 } | 265 } |
242 | 266 |
243 bool has_start_time = false; | 267 bool has_start_time = false; |
244 int64_t start_time_value = 0; | 268 int64_t start_time_value = 0; |
245 if (reporter_key.HasValue(kStartTimeValueName) && | 269 if (reporter_key.HasValue(kStartTimeValueName) && |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 RecordEnumerationHistogram(kRunningTimeErrorMetricName, | 304 RecordEnumerationHistogram(kRunningTimeErrorMetricName, |
281 REPORTER_RUNNING_TIME_ERROR_MISSING_END_TIME, | 305 REPORTER_RUNNING_TIME_ERROR_MISSING_END_TIME, |
282 REPORTER_RUNNING_TIME_ERROR_MAX); | 306 REPORTER_RUNNING_TIME_ERROR_MAX); |
283 } | 307 } |
284 } | 308 } |
285 | 309 |
286 // Reports the UwS scan times of the software reporter tool via UMA. | 310 // Reports the UwS scan times of the software reporter tool via UMA. |
287 void ReportScanTimes() const { | 311 void ReportScanTimes() const { |
288 base::string16 scan_times_key_path = base::StringPrintf( | 312 base::string16 scan_times_key_path = base::StringPrintf( |
289 L"%ls\\%ls", registry_key_.c_str(), kScanTimesSubKey); | 313 L"%ls\\%ls", registry_key_.c_str(), kScanTimesSubKey); |
290 // TODO(b/641081): This should only have KEY_QUERY_VALUE and KEY_SET_VALUE, | 314 // TODO(b/641081): This should only have KEY_QUERY_VALUE and KEY_SET_VALUE. |
291 // and use Open to avoid creating the key if it doesn't already exist. | 315 base::win::RegKey scan_times_key; |
292 base::win::RegKey scan_times_key( | 316 if (scan_times_key.Open(HKEY_CURRENT_USER, scan_times_key_path.c_str(), |
293 HKEY_CURRENT_USER, scan_times_key_path.c_str(), KEY_ALL_ACCESS); | 317 KEY_ALL_ACCESS) != ERROR_SUCCESS) { |
294 if (!scan_times_key.Valid()) | |
295 return; | 318 return; |
319 } | |
296 | 320 |
297 base::string16 value_name; | 321 base::string16 value_name; |
298 int uws_id = 0; | 322 int uws_id = 0; |
299 int64_t raw_scan_time = 0; | 323 int64_t raw_scan_time = 0; |
300 int num_scan_times = scan_times_key.GetValueCount(); | 324 int num_scan_times = scan_times_key.GetValueCount(); |
301 for (int i = 0; i < num_scan_times; ++i) { | 325 for (int i = 0; i < num_scan_times; ++i) { |
302 if (scan_times_key.GetValueNameAt(i, &value_name) == ERROR_SUCCESS && | 326 if (scan_times_key.GetValueNameAt(i, &value_name) == ERROR_SUCCESS && |
303 base::StringToInt(value_name, &uws_id) && | 327 base::StringToInt(value_name, &uws_id) && |
304 scan_times_key.ReadInt64(value_name.c_str(), &raw_scan_time) == | 328 scan_times_key.ReadInt64(value_name.c_str(), &raw_scan_time) == |
305 ERROR_SUCCESS) { | 329 ERROR_SUCCESS) { |
306 base::TimeDelta scan_time = | 330 base::TimeDelta scan_time = |
307 base::TimeDelta::FromInternalValue(raw_scan_time); | 331 base::TimeDelta::FromInternalValue(raw_scan_time); |
308 // We report the number of seconds plus one because it can take less | 332 // We report the number of seconds plus one because it can take less |
309 // than one second to scan some UwS and the count passed to |AddCount| | 333 // than one second to scan some UwS and the count passed to |AddCount| |
310 // must be at least one. | 334 // must be at least one. |
311 RecordSparseHistogramCount(kScanTimesMetricName, uws_id, | 335 RecordSparseHistogramCount(kScanTimesMetricName, uws_id, |
312 scan_time.InSeconds() + 1); | 336 scan_time.InSeconds() + 1); |
313 } | 337 } |
314 } | 338 } |
315 // Clean up by deleting the scan times key, which is a subkey of the main | 339 // Clean up by deleting the scan times key, which is a subkey of the main |
316 // reporter key. | 340 // reporter key. |
317 scan_times_key.Close(); | 341 scan_times_key.Close(); |
318 base::win::RegKey reporter_key(HKEY_CURRENT_USER, registry_key_.c_str(), | 342 base::win::RegKey reporter_key; |
319 KEY_ENUMERATE_SUB_KEYS); | 343 if (reporter_key.Open(HKEY_CURRENT_USER, registry_key_.c_str(), |
320 if (reporter_key.Valid()) | 344 KEY_ENUMERATE_SUB_KEYS) == ERROR_SUCCESS) { |
321 reporter_key.DeleteKey(kScanTimesSubKey); | 345 reporter_key.DeleteKey(kScanTimesSubKey); |
346 } | |
322 } | 347 } |
323 | 348 |
324 void RecordReporterStep(SwReporterUmaValue value) { | 349 void RecordReporterStep(SwReporterUmaValue value) { |
325 RecordEnumerationHistogram("SoftwareReporter.Step", value, SW_REPORTER_MAX); | 350 RecordEnumerationHistogram("SoftwareReporter.Step", value, SW_REPORTER_MAX); |
326 } | 351 } |
327 | 352 |
353 void RecordLogsUploadEnabled(SwReporterLogsUploadsEnabled value) { | |
354 RecordEnumerationHistogram(kLogsUploadEnabledMetricName, value, | |
355 REPORTER_LOGS_UPLOADS_MAX); | |
356 } | |
357 | |
358 void RecordLogsUploadResult() { | |
359 base::win::RegKey reporter_key; | |
360 DWORD logs_upload_result = 0; | |
361 if (reporter_key.Open(HKEY_CURRENT_USER, registry_key_.c_str(), | |
362 KEY_QUERY_VALUE | KEY_SET_VALUE) != ERROR_SUCCESS || | |
363 reporter_key.ReadValueDW(kLogsUploadResultValueName, | |
364 &logs_upload_result) != ERROR_SUCCESS) { | |
365 return; | |
366 } | |
367 | |
csharp
2016/09/20 14:29:54
Before recording logs_upload_result, could you for
csharp
2016/09/20 15:19:28
Maybe limit it to 30 to allow possible values to g
ftirelo
2016/09/20 16:41:42
Done.
ftirelo
2016/09/20 16:41:42
Done.
| |
368 RecordEnumerationHistogram(kLogsUploadResultMetricName, | |
369 static_cast<Sample>(logs_upload_result), | |
370 kSwReporterLogsUploadResultMax); | |
371 reporter_key.DeleteValue(kLogsUploadResultValueName); | |
372 } | |
373 | |
328 private: | 374 private: |
329 using Sample = base::HistogramBase::Sample; | 375 using Sample = base::HistogramBase::Sample; |
330 | 376 |
331 static constexpr base::HistogramBase::Flags kUmaHistogramFlag = | 377 static constexpr base::HistogramBase::Flags kUmaHistogramFlag = |
332 base::HistogramBase::kUmaTargetedHistogramFlag; | 378 base::HistogramBase::kUmaTargetedHistogramFlag; |
333 | 379 |
334 // Helper functions to record histograms with an optional suffix added to the | 380 // Helper functions to record histograms with an optional suffix added to the |
335 // histogram name. The UMA_HISTOGRAM macros can't be used because they | 381 // histogram name. The UMA_HISTOGRAM macros can't be used because they |
336 // require a constant string. | 382 // require a constant string. |
337 | 383 |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
608 prefs->SetString(prefs::kSwReporterPromptVersion, | 654 prefs->SetString(prefs::kSwReporterPromptVersion, |
609 reporter_version.GetString()); | 655 reporter_version.GetString()); |
610 | 656 |
611 // Download the SRT. | 657 // Download the SRT. |
612 RecordReporterStepHistogram(SW_REPORTER_DOWNLOAD_START); | 658 RecordReporterStepHistogram(SW_REPORTER_DOWNLOAD_START); |
613 | 659 |
614 // All the work happens in the self-deleting class below. | 660 // All the work happens in the self-deleting class below. |
615 new SRTFetcher(profile); | 661 new SRTFetcher(profile); |
616 } | 662 } |
617 | 663 |
664 bool BehaviourIsEnabled(SwReporterInvocation::Behaviours behaviours, | |
csharp
2016/09/20 14:29:54
What about having this as a member of SwReporterIn
ftirelo
2016/09/20 16:41:42
Done.
| |
665 SwReporterInvocation::Behaviours intended_behaviour) { | |
666 return (behaviours & intended_behaviour) != 0; | |
667 } | |
668 | |
618 // This class tries to run a queue of reporters and react to their exit codes. | 669 // This class tries to run a queue of reporters and react to their exit codes. |
619 // It schedules subsequent runs of the queue as needed, or retries as soon as a | 670 // It schedules subsequent runs of the queue as needed, or retries as soon as a |
620 // browser is available when none is on first try. | 671 // browser is available when none is on first try. |
621 class ReporterRunner : public chrome::BrowserListObserver { | 672 class ReporterRunner : public chrome::BrowserListObserver { |
622 public: | 673 public: |
623 // Registers |invocations| to run next time |TryToRun| is scheduled. (And if | 674 // Registers |invocations| to run next time |TryToRun| is scheduled. (And if |
624 // it's not already scheduled, call it now.) | 675 // it's not already scheduled, call it now.) |
625 static void ScheduleInvocations( | 676 static void ScheduleInvocations( |
626 const SwReporterQueue& invocations, | 677 const SwReporterQueue& invocations, |
627 const base::Version& version, | 678 const base::Version& version, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
674 if (g_testing_delegate_) | 725 if (g_testing_delegate_) |
675 g_testing_delegate_->NotifyLaunchReady(); | 726 g_testing_delegate_->NotifyLaunchReady(); |
676 | 727 |
677 // Add switches for users who opted into extended Safe Browsing reporting. | 728 // Add switches for users who opted into extended Safe Browsing reporting. |
678 // The invocation object is changed locally right before the actual process | 729 // The invocation object is changed locally right before the actual process |
679 // is launched because user status can change between this and the next run | 730 // is launched because user status can change between this and the next run |
680 // for this ReporterRunner object. For example, the ReporterDone() callback | 731 // for this ReporterRunner object. For example, the ReporterDone() callback |
681 // schedules the next run for a few days later, and the user might have | 732 // schedules the next run for a few days later, and the user might have |
682 // changed settings in the meantime. | 733 // changed settings in the meantime. |
683 PrefService* local_state = g_browser_process->local_state(); | 734 PrefService* local_state = g_browser_process->local_state(); |
684 if (next_invocation.flags & SwReporterInvocation::FLAG_SEND_REPORTER_LOGS && | 735 if (BehaviourIsEnabled( |
736 next_invocation.supported_behaviours, | |
737 SwReporterInvocation::BEHAVIOUR_SEND_REPORTER_LOGS) && | |
685 local_state && ShouldSendReporterLogs(*local_state)) { | 738 local_state && ShouldSendReporterLogs(*local_state)) { |
739 next_invocation.logs_upload_enabled = true; | |
686 AddSwitchesForExtendedReporterUser(&next_invocation); | 740 AddSwitchesForExtendedReporterUser(&next_invocation); |
687 // Set the local state value before the first attempt to run the | 741 // Set the local state value before the first attempt to run the |
688 // reporter, because we only want to upload logs once in the window | 742 // reporter, because we only want to upload logs once in the window |
689 // defined by |kDaysBetweenReporterLogsSent|. If we set with other local | 743 // defined by |kDaysBetweenReporterLogsSent|. If we set with other local |
690 // state values after the reporter runs, we could send logs again too | 744 // state values after the reporter runs, we could send logs again too |
691 // quickly (for example, if Chrome stops before the reporter finishes). | 745 // quickly (for example, if Chrome stops before the reporter finishes). |
692 local_state->SetInt64(prefs::kSwReporterLastTimeSentReport, | 746 local_state->SetInt64(prefs::kSwReporterLastTimeSentReport, |
693 base::Time::Now().ToInternalValue()); | 747 base::Time::Now().ToInternalValue()); |
694 } | 748 } |
695 | 749 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
738 | 792 |
739 // If the reporter failed to launch, do not process the results. (The exit | 793 // If the reporter failed to launch, do not process the results. (The exit |
740 // code itself doesn't need to be logged in this case because | 794 // code itself doesn't need to be logged in this case because |
741 // SW_REPORTER_FAILED_TO_START is logged in |LaunchAndWaitForExit|.) | 795 // SW_REPORTER_FAILED_TO_START is logged in |LaunchAndWaitForExit|.) |
742 if (exit_code == kReporterFailureExitCode) | 796 if (exit_code == kReporterFailureExitCode) |
743 return; | 797 return; |
744 | 798 |
745 UMAHistogramReporter uma(finished_invocation.suffix); | 799 UMAHistogramReporter uma(finished_invocation.suffix); |
746 uma.ReportVersion(version); | 800 uma.ReportVersion(version); |
747 uma.ReportExitCode(exit_code); | 801 uma.ReportExitCode(exit_code); |
748 uma.ReportFoundUwS(finished_invocation.flags & | 802 uma.ReportFoundUwS( |
749 SwReporterInvocation::FLAG_LOG_TO_RAPPOR); | 803 BehaviourIsEnabled(finished_invocation.supported_behaviours, |
804 SwReporterInvocation::BEHAVIOUR_LOG_TO_RAPPOR)); | |
750 | 805 |
751 PrefService* local_state = g_browser_process->local_state(); | 806 PrefService* local_state = g_browser_process->local_state(); |
752 if (local_state) { | 807 if (local_state) { |
753 if (finished_invocation.flags & | 808 if (BehaviourIsEnabled( |
754 SwReporterInvocation::FLAG_LOG_EXIT_CODE_TO_PREFS) | 809 finished_invocation.supported_behaviours, |
810 SwReporterInvocation::BEHAVIOUR_LOG_EXIT_CODE_TO_PREFS)) { | |
755 local_state->SetInteger(prefs::kSwReporterLastExitCode, exit_code); | 811 local_state->SetInteger(prefs::kSwReporterLastExitCode, exit_code); |
812 } | |
756 local_state->SetInt64(prefs::kSwReporterLastTimeTriggered, | 813 local_state->SetInt64(prefs::kSwReporterLastTimeTriggered, |
757 base::Time::Now().ToInternalValue()); | 814 base::Time::Now().ToInternalValue()); |
758 } | 815 } |
759 uma.ReportRuntime(reporter_running_time); | 816 uma.ReportRuntime(reporter_running_time); |
760 uma.ReportScanTimes(); | 817 uma.ReportScanTimes(); |
761 uma.ReportMemoryUsage(); | 818 uma.ReportMemoryUsage(); |
819 if (finished_invocation.logs_upload_enabled) | |
820 uma.RecordLogsUploadResult(); | |
762 | 821 |
763 if (!(finished_invocation.flags & | 822 if (!BehaviourIsEnabled(finished_invocation.supported_behaviours, |
764 SwReporterInvocation::FLAG_TRIGGER_PROMPT)) | 823 SwReporterInvocation::BEHAVIOUR_TRIGGER_PROMPT)) { |
765 return; | 824 return; |
825 } | |
766 | 826 |
767 if (!IsInSRTPromptFieldTrialGroups()) { | 827 if (!IsInSRTPromptFieldTrialGroups()) { |
768 // Knowing about disabled field trial is more important than reporter not | 828 // Knowing about disabled field trial is more important than reporter not |
769 // finding anything to remove, so check this case first. | 829 // finding anything to remove, so check this case first. |
770 RecordReporterStepHistogram(SW_REPORTER_NO_PROMPT_FIELD_TRIAL); | 830 RecordReporterStepHistogram(SW_REPORTER_NO_PROMPT_FIELD_TRIAL); |
771 return; | 831 return; |
772 } | 832 } |
773 | 833 |
774 if (exit_code != kSwReporterPostRebootCleanupNeeded && | 834 if (exit_code != kSwReporterPostRebootCleanupNeeded && |
775 exit_code != kSwReporterCleanupNeeded) { | 835 exit_code != kSwReporterCleanupNeeded) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
833 FROM_HERE, | 893 FROM_HERE, |
834 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), | 894 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), |
835 next_trigger - now); | 895 next_trigger - now); |
836 } | 896 } |
837 } | 897 } |
838 | 898 |
839 // Returns true if the experiment to send reporter logs is enabled, the user | 899 // Returns true if the experiment to send reporter logs is enabled, the user |
840 // opted into Safe Browsing extended reporting, and logs have been sent at | 900 // opted into Safe Browsing extended reporting, and logs have been sent at |
841 // least |kSwReporterLastTimeSentReport| days ago. | 901 // least |kSwReporterLastTimeSentReport| days ago. |
842 bool ShouldSendReporterLogs(const PrefService& local_state) { | 902 bool ShouldSendReporterLogs(const PrefService& local_state) { |
843 if (!base::FeatureList::IsEnabled(kSwReporterExtendedSafeBrowsingFeature) || | 903 if (!base::FeatureList::IsEnabled(kSwReporterExtendedSafeBrowsingFeature)) |
844 !SafeBrowsingExtendedReportingEnabled()) { | 904 return false; |
905 | |
906 UMAHistogramReporter uma; | |
907 if (!SafeBrowsingExtendedReportingEnabled()) { | |
908 uma.RecordLogsUploadEnabled(REPORTER_LOGS_UPLOADS_SBER_DISABLED); | |
845 return false; | 909 return false; |
846 } | 910 } |
847 | 911 |
848 const base::Time now = base::Time::Now(); | 912 const base::Time now = base::Time::Now(); |
849 const base::Time last_time_sent_logs = base::Time::FromInternalValue( | 913 const base::Time last_time_sent_logs = base::Time::FromInternalValue( |
850 local_state.GetInt64(prefs::kSwReporterLastTimeSentReport)); | 914 local_state.GetInt64(prefs::kSwReporterLastTimeSentReport)); |
851 // Send the logs if the last send was in the future. This is intended as a | 915 const base::Time next_time_send_logs = |
852 // measure for failure recovery, in case the time in local state is | 916 last_time_sent_logs + |
853 // incorrectly set to the future. | 917 base::TimeDelta::FromDays(kDaysBetweenReporterLogsSent); |
854 if (last_time_sent_logs > now) | 918 // Send the logs if the last send is the future or if the interval has |
919 // passed. The former is intended as a measure for failure recovery, in | |
920 // case the time in local state is incorrectly set to the future. | |
921 if (last_time_sent_logs > now || next_time_send_logs <= now) { | |
922 uma.RecordLogsUploadEnabled(REPORTER_LOGS_UPLOADS_ENABLED); | |
855 return true; | 923 return true; |
856 // Otherwise, send them if the interval has passed. | 924 } |
857 return last_time_sent_logs + | 925 uma.RecordLogsUploadEnabled(REPORTER_LOGS_UPLOADS_RECENTLY_SENT_LOGS); |
858 base::TimeDelta::FromDays(kDaysBetweenReporterLogsSent) <= | 926 return false; |
859 now; | |
860 } | 927 } |
861 | 928 |
862 void AddSwitchesForExtendedReporterUser(SwReporterInvocation* invocation) { | 929 void AddSwitchesForExtendedReporterUser(SwReporterInvocation* invocation) { |
863 invocation->command_line.AppendSwitch(kExtendedSafeBrowsingEnabledSwitch); | 930 invocation->command_line.AppendSwitch(kExtendedSafeBrowsingEnabledSwitch); |
864 invocation->command_line.AppendSwitchASCII( | 931 invocation->command_line.AppendSwitchASCII( |
865 kChromeVersionSwitch, version_info::GetVersionNumber()); | 932 kChromeVersionSwitch, version_info::GetVersionNumber()); |
866 invocation->command_line.AppendSwitchNative( | 933 invocation->command_line.AppendSwitchNative( |
867 kChromeChannelSwitch, base::IntToString16(ChannelAsInt())); | 934 kChromeChannelSwitch, base::IntToString16(ChannelAsInt())); |
868 } | 935 } |
869 | 936 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
907 | 974 |
908 SwReporterInvocation SwReporterInvocation::FromCommandLine( | 975 SwReporterInvocation SwReporterInvocation::FromCommandLine( |
909 const base::CommandLine& command_line) { | 976 const base::CommandLine& command_line) { |
910 SwReporterInvocation invocation; | 977 SwReporterInvocation invocation; |
911 invocation.command_line = command_line; | 978 invocation.command_line = command_line; |
912 return invocation; | 979 return invocation; |
913 } | 980 } |
914 | 981 |
915 bool SwReporterInvocation::operator==(const SwReporterInvocation& other) const { | 982 bool SwReporterInvocation::operator==(const SwReporterInvocation& other) const { |
916 return command_line.argv() == other.command_line.argv() && | 983 return command_line.argv() == other.command_line.argv() && |
917 suffix == other.suffix && flags == other.flags; | 984 suffix == other.suffix && |
985 supported_behaviours == other.supported_behaviours && | |
986 logs_upload_enabled == other.logs_upload_enabled; | |
918 } | 987 } |
919 | 988 |
920 void RunSwReporters(const SwReporterQueue& invocations, | 989 void RunSwReporters(const SwReporterQueue& invocations, |
921 const base::Version& version, | 990 const base::Version& version, |
922 scoped_refptr<base::TaskRunner> main_thread_task_runner, | 991 scoped_refptr<base::TaskRunner> main_thread_task_runner, |
923 scoped_refptr<base::TaskRunner> blocking_task_runner) { | 992 scoped_refptr<base::TaskRunner> blocking_task_runner) { |
924 DCHECK(!invocations.empty()); | 993 DCHECK(!invocations.empty()); |
925 DCHECK(version.IsValid()); | 994 DCHECK(version.IsValid()); |
926 ReporterRunner::ScheduleInvocations(invocations, version, | 995 ReporterRunner::ScheduleInvocations(invocations, version, |
927 std::move(main_thread_task_runner), | 996 std::move(main_thread_task_runner), |
928 std::move(blocking_task_runner)); | 997 std::move(blocking_task_runner)); |
929 } | 998 } |
930 | 999 |
931 bool ReporterFoundUws() { | 1000 bool ReporterFoundUws() { |
932 PrefService* local_state = g_browser_process->local_state(); | 1001 PrefService* local_state = g_browser_process->local_state(); |
933 if (!local_state) | 1002 if (!local_state) |
934 return false; | 1003 return false; |
935 int exit_code = local_state->GetInteger(prefs::kSwReporterLastExitCode); | 1004 int exit_code = local_state->GetInteger(prefs::kSwReporterLastExitCode); |
936 return exit_code == kSwReporterCleanupNeeded; | 1005 return exit_code == kSwReporterCleanupNeeded; |
937 } | 1006 } |
938 | 1007 |
939 bool UserHasRunCleaner() { | 1008 bool UserHasRunCleaner() { |
940 base::string16 cleaner_key_path(kSoftwareRemovalToolRegistryKey); | 1009 base::string16 cleaner_key_path(kSoftwareRemovalToolRegistryKey); |
941 cleaner_key_path.append(L"\\").append(kCleanerSubKey); | 1010 cleaner_key_path.append(L"\\").append(kCleanerSubKey); |
942 | 1011 |
943 base::win::RegKey srt_cleaner_key(HKEY_CURRENT_USER, cleaner_key_path.c_str(), | 1012 base::win::RegKey srt_cleaner_key; |
944 KEY_QUERY_VALUE); | 1013 return srt_cleaner_key.Open(HKEY_CURRENT_USER, cleaner_key_path.c_str(), |
945 | 1014 KEY_QUERY_VALUE) == ERROR_SUCCESS && |
946 return srt_cleaner_key.Valid() && srt_cleaner_key.GetValueCount() > 0; | 1015 srt_cleaner_key.GetValueCount() > 0; |
947 } | 1016 } |
948 | 1017 |
949 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { | 1018 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { |
950 g_testing_delegate_ = delegate; | 1019 g_testing_delegate_ = delegate; |
951 } | 1020 } |
952 | 1021 |
953 } // namespace safe_browsing | 1022 } // namespace safe_browsing |
OLD | NEW |