Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: chrome/browser/safe_browsing/srt_fetcher_win.cc

Issue 2347753002: Adds histograms for tracking Software Reporter logs uploads in SRT Fetcher. (Closed)
Patch Set: More comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 Software Reporter logs uploads
grt (UTC plus 2) 2016/09/16 20:12:42 feel fee to ignore this if the terminology is cons
ftirelo 2016/09/16 21:00:10 Done.
118 // are 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
127
115 const char kRunningTimeErrorMetricName[] = 128 const char kRunningTimeErrorMetricName[] =
116 "SoftwareReporter.RunningTimeRegistryError"; 129 "SoftwareReporter.RunningTimeRegistryError";
117 130
118 SwReporterTestingDelegate* g_testing_delegate_ = nullptr; 131 SwReporterTestingDelegate* g_testing_delegate_ = nullptr;
119 132
120 const wchar_t kScanTimesSubKey[] = L"ScanTimes"; 133 const wchar_t kScanTimesSubKey[] = L"ScanTimes";
121 const wchar_t kFoundUwsValueName[] = L"FoundUws"; 134 const wchar_t kFoundUwsValueName[] = L"FoundUws";
122 const wchar_t kMemoryUsedValueName[] = L"MemoryUsed"; 135 const wchar_t kMemoryUsedValueName[] = L"MemoryUsed";
136 const wchar_t kLogsUploadResultValueName[] = L"LogsUploadResult";
123 137
124 const char kFoundUwsMetricName[] = "SoftwareReporter.FoundUwS"; 138 const char kFoundUwsMetricName[] = "SoftwareReporter.FoundUwS";
125 const char kFoundUwsReadErrorMetricName[] = 139 const char kFoundUwsReadErrorMetricName[] =
126 "SoftwareReporter.FoundUwSReadError"; 140 "SoftwareReporter.FoundUwSReadError";
127 const char kScanTimesMetricName[] = "SoftwareReporter.UwSScanTimes"; 141 const char kScanTimesMetricName[] = "SoftwareReporter.UwSScanTimes";
128 const char kMemoryUsedMetricName[] = "SoftwareReporter.MemoryUsed"; 142 const char kMemoryUsedMetricName[] = "SoftwareReporter.MemoryUsed";
143 const char kLogsUploadEnabledMetricName[] =
144 "SoftwareReporter.LogsUploadEnabled";
145 const char kLogsUploadResultMetricName[] = "SoftwareReporter.LogsUploadResult";
146
147 // The max value for histogram SoftwareReporter.LogsUploadResult, which is used
148 // to send UMA information about the result of Software Reporter's attempt to
149 // upload logs, when logs are enabled. This value must be consistent with the
150 // SoftwareReporterLogsUploadResult enum defined in the histograms.xml file.
151 const int kSwReporterLogsUploadResultMax = 7;
129 152
130 // Reports metrics about the software reporter via UMA (and sometimes Rappor). 153 // Reports metrics about the software reporter via UMA (and sometimes Rappor).
131 class UMAHistogramReporter { 154 class UMAHistogramReporter {
132 public: 155 public:
133 UMAHistogramReporter() : UMAHistogramReporter(std::string()) {} 156 UMAHistogramReporter() : UMAHistogramReporter(std::string()) {}
134 157
135 explicit UMAHistogramReporter(const std::string& suffix) 158 explicit UMAHistogramReporter(const std::string& suffix)
136 : suffix_(suffix), 159 : suffix_(suffix),
137 registry_key_(suffix.empty() ? kSoftwareRemovalToolRegistryKey 160 registry_key_(suffix.empty() ? kSoftwareRemovalToolRegistryKey
138 : base::StringPrintf( 161 : base::StringPrintf(
(...skipping 29 matching lines...) Expand all
168 } 191 }
169 RecordSparseHistogram("SoftwareReporter.MajorVersion", major_version); 192 RecordSparseHistogram("SoftwareReporter.MajorVersion", major_version);
170 } 193 }
171 194
172 void ReportExitCode(int exit_code) const { 195 void ReportExitCode(int exit_code) const {
173 RecordSparseHistogram("SoftwareReporter.ExitCode", exit_code); 196 RecordSparseHistogram("SoftwareReporter.ExitCode", exit_code);
174 } 197 }
175 198
176 // Reports UwS found by the software reporter tool via UMA and RAPPOR. 199 // Reports UwS found by the software reporter tool via UMA and RAPPOR.
177 void ReportFoundUwS(bool use_rappor) const { 200 void ReportFoundUwS(bool use_rappor) const {
178 base::win::RegKey reporter_key(HKEY_CURRENT_USER, registry_key_.c_str(), 201 base::win::RegKey reporter_key;
179 KEY_QUERY_VALUE | KEY_SET_VALUE);
180 std::vector<base::string16> found_uws_strings; 202 std::vector<base::string16> found_uws_strings;
181 if (reporter_key.Valid() && 203 if (reporter_key.Open(HKEY_CURRENT_USER, registry_key_.c_str(),
182 reporter_key.ReadValues(kFoundUwsValueName, &found_uws_strings) == 204 KEY_QUERY_VALUE | KEY_SET_VALUE) != ERROR_SUCCESS ||
205 reporter_key.ReadValues(kFoundUwsValueName, &found_uws_strings) !=
183 ERROR_SUCCESS) { 206 ERROR_SUCCESS) {
184 rappor::RapporService* rappor_service = nullptr; 207 return;
185 if (use_rappor) 208 }
186 rappor_service = g_browser_process->rappor_service();
187 209
188 bool parse_error = false; 210 rappor::RapporService* rappor_service = nullptr;
189 for (const base::string16& uws_string : found_uws_strings) { 211 if (use_rappor)
190 // All UwS ids are expected to be integers. 212 rappor_service = g_browser_process->rappor_service();
191 uint32_t uws_id = 0; 213
192 if (base::StringToUint(uws_string, &uws_id)) { 214 bool parse_error = false;
193 RecordSparseHistogram(kFoundUwsMetricName, uws_id); 215 for (const base::string16& uws_string : found_uws_strings) {
194 if (rappor_service) { 216 // All UwS ids are expected to be integers.
195 rappor_service->RecordSample(kFoundUwsMetricName, 217 uint32_t uws_id = 0;
196 rappor::COARSE_RAPPOR_TYPE, 218 if (base::StringToUint(uws_string, &uws_id)) {
197 base::UTF16ToUTF8(uws_string)); 219 RecordSparseHistogram(kFoundUwsMetricName, uws_id);
198 } 220 if (rappor_service) {
199 } else { 221 rappor_service->RecordSample(kFoundUwsMetricName,
200 parse_error = true; 222 rappor::COARSE_RAPPOR_TYPE,
223 base::UTF16ToUTF8(uws_string));
201 } 224 }
225 } else {
226 parse_error = true;
202 } 227 }
203 228
204 // Clean up the old value. 229 // Clean up the old value.
205 reporter_key.DeleteValue(kFoundUwsValueName); 230 reporter_key.DeleteValue(kFoundUwsValueName);
206 231
207 RecordBooleanHistogram(kFoundUwsReadErrorMetricName, parse_error); 232 RecordBooleanHistogram(kFoundUwsReadErrorMetricName, parse_error);
208 } 233 }
209 } 234 }
210 235
211 // Reports to UMA the memory usage of the software reporter tool as reported 236 // Reports to UMA the memory usage of the software reporter tool as reported
212 // by the tool itself in the Windows registry. 237 // by the tool itself in the Windows registry.
213 void ReportMemoryUsage() const { 238 void ReportMemoryUsage() const {
214 base::win::RegKey reporter_key(HKEY_CURRENT_USER, registry_key_.c_str(), 239 base::win::RegKey reporter_key;
215 KEY_QUERY_VALUE | KEY_SET_VALUE);
216 DWORD memory_used = 0; 240 DWORD memory_used = 0;
217 if (reporter_key.Valid() && 241 if (reporter_key.Open(HKEY_CURRENT_USER, registry_key_.c_str(),
218 reporter_key.ReadValueDW(kMemoryUsedValueName, &memory_used) == 242 KEY_QUERY_VALUE | KEY_SET_VALUE) != ERROR_SUCCESS ||
243 reporter_key.ReadValueDW(kMemoryUsedValueName, &memory_used) !=
219 ERROR_SUCCESS) { 244 ERROR_SUCCESS) {
220 RecordMemoryKBHistogram(kMemoryUsedMetricName, memory_used); 245 return;
221 reporter_key.DeleteValue(kMemoryUsedValueName);
222 } 246 }
247 RecordMemoryKBHistogram(kMemoryUsedMetricName, memory_used);
248 reporter_key.DeleteValue(kMemoryUsedValueName);
223 } 249 }
224 250
225 // Reports the SwReporter run time with UMA both as reported by the tool via 251 // Reports the SwReporter run time with UMA both as reported by the tool via
226 // the registry and as measured by |ReporterRunner|. 252 // the registry and as measured by |ReporterRunner|.
227 void ReportRuntime(const base::TimeDelta& reporter_running_time) const { 253 void ReportRuntime(const base::TimeDelta& reporter_running_time) const {
228 RecordLongTimesHistogram("SoftwareReporter.RunningTimeAccordingToChrome", 254 RecordLongTimesHistogram("SoftwareReporter.RunningTimeAccordingToChrome",
229 reporter_running_time); 255 reporter_running_time);
230 256
231 // TODO(b/641081): This should only have KEY_QUERY_VALUE and KEY_SET_VALUE, 257 // 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. 258 base::win::RegKey reporter_key;
233 base::win::RegKey reporter_key(HKEY_CURRENT_USER, registry_key_.c_str(), 259 if (reporter_key.Open(HKEY_CURRENT_USER, registry_key_.c_str(),
234 KEY_ALL_ACCESS); 260 KEY_ALL_ACCESS) != ERROR_SUCCESS) {
235 if (!reporter_key.Valid()) {
236 RecordEnumerationHistogram( 261 RecordEnumerationHistogram(
237 kRunningTimeErrorMetricName, 262 kRunningTimeErrorMetricName,
238 REPORTER_RUNNING_TIME_ERROR_REGISTRY_KEY_INVALID, 263 REPORTER_RUNNING_TIME_ERROR_REGISTRY_KEY_INVALID,
239 REPORTER_RUNNING_TIME_ERROR_MAX); 264 REPORTER_RUNNING_TIME_ERROR_MAX);
240 return; 265 return;
241 } 266 }
242 267
243 bool has_start_time = false; 268 bool has_start_time = false;
244 int64_t start_time_value = 0; 269 int64_t start_time_value = 0;
245 if (reporter_key.HasValue(kStartTimeValueName) && 270 if (reporter_key.HasValue(kStartTimeValueName) &&
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 RecordEnumerationHistogram(kRunningTimeErrorMetricName, 305 RecordEnumerationHistogram(kRunningTimeErrorMetricName,
281 REPORTER_RUNNING_TIME_ERROR_MISSING_END_TIME, 306 REPORTER_RUNNING_TIME_ERROR_MISSING_END_TIME,
282 REPORTER_RUNNING_TIME_ERROR_MAX); 307 REPORTER_RUNNING_TIME_ERROR_MAX);
283 } 308 }
284 } 309 }
285 310
286 // Reports the UwS scan times of the software reporter tool via UMA. 311 // Reports the UwS scan times of the software reporter tool via UMA.
287 void ReportScanTimes() const { 312 void ReportScanTimes() const {
288 base::string16 scan_times_key_path = base::StringPrintf( 313 base::string16 scan_times_key_path = base::StringPrintf(
289 L"%ls\\%ls", registry_key_.c_str(), kScanTimesSubKey); 314 L"%ls\\%ls", registry_key_.c_str(), kScanTimesSubKey);
290 // TODO(b/641081): This should only have KEY_QUERY_VALUE and KEY_SET_VALUE, 315 // 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. 316 base::win::RegKey scan_times_key;
292 base::win::RegKey scan_times_key( 317 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); 318 KEY_ALL_ACCESS) != ERROR_SUCCESS) {
294 if (!scan_times_key.Valid())
295 return; 319 return;
320 }
296 321
297 base::string16 value_name; 322 base::string16 value_name;
298 int uws_id = 0; 323 int uws_id = 0;
299 int64_t raw_scan_time = 0; 324 int64_t raw_scan_time = 0;
300 int num_scan_times = scan_times_key.GetValueCount(); 325 int num_scan_times = scan_times_key.GetValueCount();
301 for (int i = 0; i < num_scan_times; ++i) { 326 for (int i = 0; i < num_scan_times; ++i) {
302 if (scan_times_key.GetValueNameAt(i, &value_name) == ERROR_SUCCESS && 327 if (scan_times_key.GetValueNameAt(i, &value_name) == ERROR_SUCCESS &&
303 base::StringToInt(value_name, &uws_id) && 328 base::StringToInt(value_name, &uws_id) &&
304 scan_times_key.ReadInt64(value_name.c_str(), &raw_scan_time) == 329 scan_times_key.ReadInt64(value_name.c_str(), &raw_scan_time) ==
305 ERROR_SUCCESS) { 330 ERROR_SUCCESS) {
306 base::TimeDelta scan_time = 331 base::TimeDelta scan_time =
307 base::TimeDelta::FromInternalValue(raw_scan_time); 332 base::TimeDelta::FromInternalValue(raw_scan_time);
308 // We report the number of seconds plus one because it can take less 333 // 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| 334 // than one second to scan some UwS and the count passed to |AddCount|
310 // must be at least one. 335 // must be at least one.
311 RecordSparseHistogramCount(kScanTimesMetricName, uws_id, 336 RecordSparseHistogramCount(kScanTimesMetricName, uws_id,
312 scan_time.InSeconds() + 1); 337 scan_time.InSeconds() + 1);
313 } 338 }
314 } 339 }
315 // Clean up by deleting the scan times key, which is a subkey of the main 340 // Clean up by deleting the scan times key, which is a subkey of the main
316 // reporter key. 341 // reporter key.
317 scan_times_key.Close(); 342 scan_times_key.Close();
318 base::win::RegKey reporter_key(HKEY_CURRENT_USER, registry_key_.c_str(), 343 base::win::RegKey reporter_key;
319 KEY_ENUMERATE_SUB_KEYS); 344 if (reporter_key.Open(HKEY_CURRENT_USER, registry_key_.c_str(),
320 if (reporter_key.Valid()) 345 KEY_ENUMERATE_SUB_KEYS) == ERROR_SUCCESS) {
321 reporter_key.DeleteKey(kScanTimesSubKey); 346 reporter_key.DeleteKey(kScanTimesSubKey);
347 }
322 } 348 }
323 349
324 void RecordReporterStep(SwReporterUmaValue value) { 350 void RecordReporterStep(SwReporterUmaValue value) {
325 RecordEnumerationHistogram("SoftwareReporter.Step", value, SW_REPORTER_MAX); 351 RecordEnumerationHistogram("SoftwareReporter.Step", value, SW_REPORTER_MAX);
326 } 352 }
327 353
354 void RecordLogsUploadEnabled(SwReporterLogsUploadsEnabled value) {
355 RecordEnumerationHistogram(kLogsUploadEnabledMetricName, value,
356 REPORTER_LOGS_UPLOADS_MAX);
357 }
358
359 void RecordLogsUploadResult() {
360 base::win::RegKey reporter_key;
361 DWORD logs_upload_result = 0;
362 if (reporter_key.Open(HKEY_CURRENT_USER, registry_key_.c_str(),
363 KEY_QUERY_VALUE | KEY_SET_VALUE) != ERROR_SUCCESS ||
364 reporter_key.ReadValueDW(kLogsUploadResultValueName,
365 &logs_upload_result) != ERROR_SUCCESS) {
366 return;
367 }
368
369 RecordEnumerationHistogram(kLogsUploadResultMetricName,
370 static_cast<Sample>(logs_upload_result),
371 kSwReporterLogsUploadResultMax);
372 reporter_key.DeleteValue(kLogsUploadResultValueName);
373 }
374
328 private: 375 private:
329 using Sample = base::HistogramBase::Sample; 376 using Sample = base::HistogramBase::Sample;
330 377
331 static constexpr base::HistogramBase::Flags kUmaHistogramFlag = 378 static constexpr base::HistogramBase::Flags kUmaHistogramFlag =
332 base::HistogramBase::kUmaTargetedHistogramFlag; 379 base::HistogramBase::kUmaTargetedHistogramFlag;
333 380
334 // Helper functions to record histograms with an optional suffix added to the 381 // 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 382 // histogram name. The UMA_HISTOGRAM macros can't be used because they
336 // require a constant string. 383 // require a constant string.
337 384
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 if (g_testing_delegate_) 721 if (g_testing_delegate_)
675 g_testing_delegate_->NotifyLaunchReady(); 722 g_testing_delegate_->NotifyLaunchReady();
676 723
677 // Add switches for users who opted into extended Safe Browsing reporting. 724 // Add switches for users who opted into extended Safe Browsing reporting.
678 // The invocation object is changed locally right before the actual process 725 // 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 726 // is launched because user status can change between this and the next run
680 // for this ReporterRunner object. For example, the ReporterDone() callback 727 // for this ReporterRunner object. For example, the ReporterDone() callback
681 // schedules the next run for a few days later, and the user might have 728 // schedules the next run for a few days later, and the user might have
682 // changed settings in the meantime. 729 // changed settings in the meantime.
683 PrefService* local_state = g_browser_process->local_state(); 730 PrefService* local_state = g_browser_process->local_state();
684 if (next_invocation.flags & SwReporterInvocation::FLAG_SEND_REPORTER_LOGS && 731 if (BehaviourIsEnabled(next_invocation.supported_behaviours,
732 SwReporterBehaviours::SEND_REPORTER_LOGS) &&
685 local_state && ShouldSendReporterLogs(*local_state)) { 733 local_state && ShouldSendReporterLogs(*local_state)) {
734 next_invocation.logs_upload_enabled = true;
686 AddSwitchesForExtendedReporterUser(&next_invocation); 735 AddSwitchesForExtendedReporterUser(&next_invocation);
687 // Set the local state value before the first attempt to run the 736 // 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 737 // reporter, because we only want to upload logs once in the window
689 // defined by |kDaysBetweenReporterLogsSent|. If we set with other local 738 // defined by |kDaysBetweenReporterLogsSent|. If we set with other local
690 // state values after the reporter runs, we could send logs again too 739 // state values after the reporter runs, we could send logs again too
691 // quickly (for example, if Chrome stops before the reporter finishes). 740 // quickly (for example, if Chrome stops before the reporter finishes).
692 local_state->SetInt64(prefs::kSwReporterLastTimeSentReport, 741 local_state->SetInt64(prefs::kSwReporterLastTimeSentReport,
693 base::Time::Now().ToInternalValue()); 742 base::Time::Now().ToInternalValue());
694 } 743 }
695 744
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 787
739 // If the reporter failed to launch, do not process the results. (The exit 788 // 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 789 // code itself doesn't need to be logged in this case because
741 // SW_REPORTER_FAILED_TO_START is logged in |LaunchAndWaitForExit|.) 790 // SW_REPORTER_FAILED_TO_START is logged in |LaunchAndWaitForExit|.)
742 if (exit_code == kReporterFailureExitCode) 791 if (exit_code == kReporterFailureExitCode)
743 return; 792 return;
744 793
745 UMAHistogramReporter uma(finished_invocation.suffix); 794 UMAHistogramReporter uma(finished_invocation.suffix);
746 uma.ReportVersion(version); 795 uma.ReportVersion(version);
747 uma.ReportExitCode(exit_code); 796 uma.ReportExitCode(exit_code);
748 uma.ReportFoundUwS(finished_invocation.flags & 797 uma.ReportFoundUwS(
749 SwReporterInvocation::FLAG_LOG_TO_RAPPOR); 798 BehaviourIsEnabled(finished_invocation.supported_behaviours,
799 SwReporterBehaviours::LOG_TO_RAPPOR));
750 800
751 PrefService* local_state = g_browser_process->local_state(); 801 PrefService* local_state = g_browser_process->local_state();
752 if (local_state) { 802 if (local_state) {
753 if (finished_invocation.flags & 803 if (BehaviourIsEnabled(finished_invocation.supported_behaviours,
754 SwReporterInvocation::FLAG_LOG_EXIT_CODE_TO_PREFS) 804 SwReporterBehaviours::LOG_EXIT_CODE_TO_PREFS)) {
755 local_state->SetInteger(prefs::kSwReporterLastExitCode, exit_code); 805 local_state->SetInteger(prefs::kSwReporterLastExitCode, exit_code);
806 }
756 local_state->SetInt64(prefs::kSwReporterLastTimeTriggered, 807 local_state->SetInt64(prefs::kSwReporterLastTimeTriggered,
757 base::Time::Now().ToInternalValue()); 808 base::Time::Now().ToInternalValue());
758 } 809 }
759 uma.ReportRuntime(reporter_running_time); 810 uma.ReportRuntime(reporter_running_time);
760 uma.ReportScanTimes(); 811 uma.ReportScanTimes();
761 uma.ReportMemoryUsage(); 812 uma.ReportMemoryUsage();
813 if (finished_invocation.logs_upload_enabled)
814 uma.RecordLogsUploadResult();
762 815
763 if (!(finished_invocation.flags & 816 if (!BehaviourIsEnabled(finished_invocation.supported_behaviours,
764 SwReporterInvocation::FLAG_TRIGGER_PROMPT)) 817 SwReporterBehaviours::TRIGGER_PROMPT)) {
765 return; 818 return;
819 }
766 820
767 if (!IsInSRTPromptFieldTrialGroups()) { 821 if (!IsInSRTPromptFieldTrialGroups()) {
768 // Knowing about disabled field trial is more important than reporter not 822 // Knowing about disabled field trial is more important than reporter not
769 // finding anything to remove, so check this case first. 823 // finding anything to remove, so check this case first.
770 RecordReporterStepHistogram(SW_REPORTER_NO_PROMPT_FIELD_TRIAL); 824 RecordReporterStepHistogram(SW_REPORTER_NO_PROMPT_FIELD_TRIAL);
771 return; 825 return;
772 } 826 }
773 827
774 if (exit_code != kSwReporterPostRebootCleanupNeeded && 828 if (exit_code != kSwReporterPostRebootCleanupNeeded &&
775 exit_code != kSwReporterCleanupNeeded) { 829 exit_code != kSwReporterCleanupNeeded) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 FROM_HERE, 887 FROM_HERE,
834 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), 888 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)),
835 next_trigger - now); 889 next_trigger - now);
836 } 890 }
837 } 891 }
838 892
839 // Returns true if the experiment to send reporter logs is enabled, the user 893 // 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 894 // opted into Safe Browsing extended reporting, and logs have been sent at
841 // least |kSwReporterLastTimeSentReport| days ago. 895 // least |kSwReporterLastTimeSentReport| days ago.
842 bool ShouldSendReporterLogs(const PrefService& local_state) { 896 bool ShouldSendReporterLogs(const PrefService& local_state) {
843 if (!base::FeatureList::IsEnabled(kSwReporterExtendedSafeBrowsingFeature) || 897 if (!base::FeatureList::IsEnabled(kSwReporterExtendedSafeBrowsingFeature))
844 !SafeBrowsingExtendedReportingEnabled()) { 898 return false;
899
900 UMAHistogramReporter uma;
901 if (!SafeBrowsingExtendedReportingEnabled()) {
902 uma.RecordLogsUploadEnabled(REPORTER_LOGS_UPLOADS_SBER_DISABLED);
845 return false; 903 return false;
846 } 904 }
847 905
848 const base::Time now = base::Time::Now(); 906 const base::Time now = base::Time::Now();
849 const base::Time last_time_sent_logs = base::Time::FromInternalValue( 907 const base::Time last_time_sent_logs = base::Time::FromInternalValue(
850 local_state.GetInt64(prefs::kSwReporterLastTimeSentReport)); 908 local_state.GetInt64(prefs::kSwReporterLastTimeSentReport));
851 // Send the logs if the last send was in the future. This is intended as a 909 const base::Time next_time_send_logs =
852 // measure for failure recovery, in case the time in local state is 910 last_time_sent_logs +
853 // incorrectly set to the future. 911 base::TimeDelta::FromDays(kDaysBetweenReporterLogsSent);
854 if (last_time_sent_logs > now) 912 // Send the logs if the last send is the future or if the interval has
913 // passed. The former is intended as a measure for failure recovery, in
914 // case the time in local state is incorrectly set to the future.
915 if (last_time_sent_logs > now || next_time_send_logs <= now) {
916 uma.RecordLogsUploadEnabled(REPORTER_LOGS_UPLOADS_ENABLED);
855 return true; 917 return true;
856 // Otherwise, send them if the interval has passed. 918 }
857 return last_time_sent_logs + 919 uma.RecordLogsUploadEnabled(REPORTER_LOGS_UPLOADS_RECENTLY_SENT_LOGS);
858 base::TimeDelta::FromDays(kDaysBetweenReporterLogsSent) <= 920 return false;
859 now;
860 } 921 }
861 922
862 void AddSwitchesForExtendedReporterUser(SwReporterInvocation* invocation) { 923 void AddSwitchesForExtendedReporterUser(SwReporterInvocation* invocation) {
863 invocation->command_line.AppendSwitch(kExtendedSafeBrowsingEnabledSwitch); 924 invocation->command_line.AppendSwitch(kExtendedSafeBrowsingEnabledSwitch);
864 invocation->command_line.AppendSwitchASCII( 925 invocation->command_line.AppendSwitchASCII(
865 kChromeVersionSwitch, version_info::GetVersionNumber()); 926 kChromeVersionSwitch, version_info::GetVersionNumber());
866 invocation->command_line.AppendSwitchNative( 927 invocation->command_line.AppendSwitchNative(
867 kChromeChannelSwitch, base::IntToString16(ChannelAsInt())); 928 kChromeChannelSwitch, base::IntToString16(ChannelAsInt()));
868 } 929 }
869 930
(...skipping 18 matching lines...) Expand all
888 // A single leaky instance. 949 // A single leaky instance.
889 static ReporterRunner* instance_; 950 static ReporterRunner* instance_;
890 951
891 DISALLOW_COPY_AND_ASSIGN(ReporterRunner); 952 DISALLOW_COPY_AND_ASSIGN(ReporterRunner);
892 }; 953 };
893 954
894 ReporterRunner* ReporterRunner::instance_ = nullptr; 955 ReporterRunner* ReporterRunner::instance_ = nullptr;
895 956
896 } // namespace 957 } // namespace
897 958
959 SwReporterBehaviours operator&(SwReporterBehaviours a, SwReporterBehaviours b) {
960 return static_cast<SwReporterBehaviours>(static_cast<uint8_t>(a) &
961 static_cast<uint8_t>(b));
962 }
963
964 SwReporterBehaviours operator|(SwReporterBehaviours a, SwReporterBehaviours b) {
965 return static_cast<SwReporterBehaviours>(static_cast<uint8_t>(a) |
966 static_cast<uint8_t>(b));
967 }
968
969 bool BehaviourIsEnabled(SwReporterBehaviours behaviours,
970 SwReporterBehaviours intended_behaviour) {
971 return (behaviours & intended_behaviour) !=
972 SwReporterBehaviours::ALL_DISABLED;
973 }
974
898 SwReporterInvocation::SwReporterInvocation() 975 SwReporterInvocation::SwReporterInvocation()
899 : command_line(base::CommandLine::NO_PROGRAM) {} 976 : command_line(base::CommandLine::NO_PROGRAM) {}
900 977
901 SwReporterInvocation SwReporterInvocation::FromFilePath( 978 SwReporterInvocation SwReporterInvocation::FromFilePath(
902 const base::FilePath& exe_path) { 979 const base::FilePath& exe_path) {
903 SwReporterInvocation invocation; 980 SwReporterInvocation invocation;
904 invocation.command_line = base::CommandLine(exe_path); 981 invocation.command_line = base::CommandLine(exe_path);
905 return invocation; 982 return invocation;
906 } 983 }
907 984
908 SwReporterInvocation SwReporterInvocation::FromCommandLine( 985 SwReporterInvocation SwReporterInvocation::FromCommandLine(
909 const base::CommandLine& command_line) { 986 const base::CommandLine& command_line) {
910 SwReporterInvocation invocation; 987 SwReporterInvocation invocation;
911 invocation.command_line = command_line; 988 invocation.command_line = command_line;
912 return invocation; 989 return invocation;
913 } 990 }
914 991
915 bool SwReporterInvocation::operator==(const SwReporterInvocation& other) const { 992 bool SwReporterInvocation::operator==(const SwReporterInvocation& other) const {
916 return command_line.argv() == other.command_line.argv() && 993 return command_line.argv() == other.command_line.argv() &&
917 suffix == other.suffix && flags == other.flags; 994 suffix == other.suffix &&
995 supported_behaviours == other.supported_behaviours &&
996 logs_upload_enabled == other.logs_upload_enabled;
918 } 997 }
919 998
920 void RunSwReporters(const SwReporterQueue& invocations, 999 void RunSwReporters(const SwReporterQueue& invocations,
921 const base::Version& version, 1000 const base::Version& version,
922 scoped_refptr<base::TaskRunner> main_thread_task_runner, 1001 scoped_refptr<base::TaskRunner> main_thread_task_runner,
923 scoped_refptr<base::TaskRunner> blocking_task_runner) { 1002 scoped_refptr<base::TaskRunner> blocking_task_runner) {
924 DCHECK(!invocations.empty()); 1003 DCHECK(!invocations.empty());
925 DCHECK(version.IsValid()); 1004 DCHECK(version.IsValid());
926 ReporterRunner::ScheduleInvocations(invocations, version, 1005 ReporterRunner::ScheduleInvocations(invocations, version,
927 std::move(main_thread_task_runner), 1006 std::move(main_thread_task_runner),
928 std::move(blocking_task_runner)); 1007 std::move(blocking_task_runner));
929 } 1008 }
930 1009
931 bool ReporterFoundUws() { 1010 bool ReporterFoundUws() {
932 PrefService* local_state = g_browser_process->local_state(); 1011 PrefService* local_state = g_browser_process->local_state();
933 if (!local_state) 1012 if (!local_state)
934 return false; 1013 return false;
935 int exit_code = local_state->GetInteger(prefs::kSwReporterLastExitCode); 1014 int exit_code = local_state->GetInteger(prefs::kSwReporterLastExitCode);
936 return exit_code == kSwReporterCleanupNeeded; 1015 return exit_code == kSwReporterCleanupNeeded;
937 } 1016 }
938 1017
939 bool UserHasRunCleaner() { 1018 bool UserHasRunCleaner() {
940 base::string16 cleaner_key_path(kSoftwareRemovalToolRegistryKey); 1019 base::string16 cleaner_key_path(kSoftwareRemovalToolRegistryKey);
941 cleaner_key_path.append(L"\\").append(kCleanerSubKey); 1020 cleaner_key_path.append(L"\\").append(kCleanerSubKey);
942 1021
943 base::win::RegKey srt_cleaner_key(HKEY_CURRENT_USER, cleaner_key_path.c_str(), 1022 base::win::RegKey srt_cleaner_key;
944 KEY_QUERY_VALUE); 1023 return srt_cleaner_key.Open(HKEY_CURRENT_USER, cleaner_key_path.c_str(),
945 1024 KEY_QUERY_VALUE) == ERROR_SUCCESS &&
946 return srt_cleaner_key.Valid() && srt_cleaner_key.GetValueCount() > 0; 1025 srt_cleaner_key.GetValueCount() > 0;
947 } 1026 }
948 1027
949 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { 1028 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) {
950 g_testing_delegate_ = delegate; 1029 g_testing_delegate_ = delegate;
951 } 1030 }
952 1031
953 } // namespace safe_browsing 1032 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698