Chromium Code Reviews| 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 <memory> | 9 #include <memory> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/callback_helpers.h" | 14 #include "base/callback_helpers.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/feature_list.h" | |
| 16 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 17 #include "base/macros.h" | 18 #include "base/macros.h" |
| 18 #include "base/metrics/field_trial.h" | 19 #include "base/metrics/field_trial.h" |
| 19 #include "base/metrics/histogram_macros.h" | 20 #include "base/metrics/histogram_macros.h" |
| 20 #include "base/metrics/sparse_histogram.h" | 21 #include "base/metrics/sparse_histogram.h" |
| 21 #include "base/process/launch.h" | 22 #include "base/process/launch.h" |
| 22 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
| 23 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 24 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 25 #include "base/task_runner_util.h" | 26 #include "base/task_runner_util.h" |
| 26 #include "base/time/time.h" | 27 #include "base/time/time.h" |
| 27 #include "base/win/registry.h" | 28 #include "base/win/registry.h" |
| 28 #include "chrome/browser/browser_process.h" | 29 #include "chrome/browser/browser_process.h" |
| 29 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 30 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
| 30 #include "chrome/browser/profiles/profile.h" | 31 #include "chrome/browser/profiles/profile.h" |
| 31 #include "chrome/browser/profiles/profile_io_data.h" | 32 #include "chrome/browser/profiles/profile_io_data.h" |
| 33 #include "chrome/browser/safe_browsing/srt_client_info_win.h" | |
| 32 #include "chrome/browser/safe_browsing/srt_global_error_win.h" | 34 #include "chrome/browser/safe_browsing/srt_global_error_win.h" |
| 33 #include "chrome/browser/ui/browser_finder.h" | 35 #include "chrome/browser/ui/browser_finder.h" |
| 34 #include "chrome/browser/ui/browser_list.h" | 36 #include "chrome/browser/ui/browser_list.h" |
| 35 #include "chrome/browser/ui/browser_list_observer.h" | 37 #include "chrome/browser/ui/browser_list_observer.h" |
| 36 #include "chrome/browser/ui/global_error/global_error_service.h" | 38 #include "chrome/browser/ui/global_error/global_error_service.h" |
| 37 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 39 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| 40 #include "chrome/common/pref_names.h" | |
| 38 #include "components/component_updater/pref_names.h" | 41 #include "components/component_updater/pref_names.h" |
| 39 #include "components/prefs/pref_service.h" | 42 #include "components/prefs/pref_service.h" |
| 40 #include "components/rappor/rappor_service.h" | 43 #include "components/rappor/rappor_service.h" |
| 41 #include "components/variations/net/variations_http_headers.h" | 44 #include "components/variations/net/variations_http_headers.h" |
| 45 #include "components/version_info/version_info.h" | |
| 42 #include "content/public/browser/browser_thread.h" | 46 #include "content/public/browser/browser_thread.h" |
| 43 #include "net/base/load_flags.h" | 47 #include "net/base/load_flags.h" |
| 44 #include "net/http/http_status_code.h" | 48 #include "net/http/http_status_code.h" |
| 45 #include "net/url_request/url_fetcher.h" | 49 #include "net/url_request/url_fetcher.h" |
| 46 #include "net/url_request/url_fetcher_delegate.h" | 50 #include "net/url_request/url_fetcher_delegate.h" |
| 47 #include "net/url_request/url_request_context_getter.h" | 51 #include "net/url_request/url_request_context_getter.h" |
| 48 | 52 |
| 49 using content::BrowserThread; | 53 using content::BrowserThread; |
| 50 | 54 |
| 51 namespace safe_browsing { | 55 namespace safe_browsing { |
| 52 | 56 |
| 53 const wchar_t kSoftwareRemovalToolRegistryKey[] = | 57 const wchar_t kSoftwareRemovalToolRegistryKey[] = |
| 54 L"Software\\Google\\Software Removal Tool"; | 58 L"Software\\Google\\Software Removal Tool"; |
| 55 | 59 |
| 56 const wchar_t kCleanerSubKey[] = L"Cleaner"; | 60 const wchar_t kCleanerSubKey[] = L"Cleaner"; |
| 57 | 61 |
| 58 const wchar_t kEndTimeValueName[] = L"EndTime"; | 62 const wchar_t kEndTimeValueName[] = L"EndTime"; |
| 59 const wchar_t kStartTimeValueName[] = L"StartTime"; | 63 const wchar_t kStartTimeValueName[] = L"StartTime"; |
| 60 | 64 |
| 65 const char kExtendedSafeBrowsingEnabledSwitch[] = | |
| 66 "extended-safebrowsing-enabled"; | |
| 67 | |
| 61 namespace { | 68 namespace { |
| 62 | 69 |
| 63 // Used to send UMA information about missing start and end time registry | 70 // Used to send UMA information about missing start and end time registry |
| 64 // values for the reporter. Replicated in the histograms.xml file, so the order | 71 // values for the reporter. Replicated in the histograms.xml file, so the order |
| 65 // MUST NOT CHANGE. | 72 // MUST NOT CHANGE. |
| 66 enum SwReporterRunningTimeRegistryError { | 73 enum SwReporterRunningTimeRegistryError { |
| 67 REPORTER_RUNNING_TIME_ERROR_NO_ERROR = 0, | 74 REPORTER_RUNNING_TIME_ERROR_NO_ERROR = 0, |
| 68 REPORTER_RUNNING_TIME_ERROR_REGISTRY_KEY_INVALID = 1, | 75 REPORTER_RUNNING_TIME_ERROR_REGISTRY_KEY_INVALID = 1, |
| 69 REPORTER_RUNNING_TIME_ERROR_MISSING_START_TIME = 2, | 76 REPORTER_RUNNING_TIME_ERROR_MISSING_START_TIME = 2, |
| 70 REPORTER_RUNNING_TIME_ERROR_MISSING_END_TIME = 3, | 77 REPORTER_RUNNING_TIME_ERROR_MISSING_END_TIME = 3, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 const wchar_t kScanTimesSubKey[] = L"ScanTimes"; | 115 const wchar_t kScanTimesSubKey[] = L"ScanTimes"; |
| 109 const wchar_t kFoundUwsValueName[] = L"FoundUws"; | 116 const wchar_t kFoundUwsValueName[] = L"FoundUws"; |
| 110 const wchar_t kMemoryUsedValueName[] = L"MemoryUsed"; | 117 const wchar_t kMemoryUsedValueName[] = L"MemoryUsed"; |
| 111 | 118 |
| 112 const char kFoundUwsMetricName[] = "SoftwareReporter.FoundUwS"; | 119 const char kFoundUwsMetricName[] = "SoftwareReporter.FoundUwS"; |
| 113 const char kFoundUwsReadErrorMetricName[] = | 120 const char kFoundUwsReadErrorMetricName[] = |
| 114 "SoftwareReporter.FoundUwSReadError"; | 121 "SoftwareReporter.FoundUwSReadError"; |
| 115 const char kScanTimesMetricName[] = "SoftwareReporter.UwSScanTimes"; | 122 const char kScanTimesMetricName[] = "SoftwareReporter.UwSScanTimes"; |
| 116 const char kMemoryUsedMetricName[] = "SoftwareReporter.MemoryUsed"; | 123 const char kMemoryUsedMetricName[] = "SoftwareReporter.MemoryUsed"; |
| 117 | 124 |
| 125 const base::Feature kSwReporterExtendedSafeBrowsingFeature { | |
| 126 "SwReporterExtendedSafeBrowsingFeature", base::FEATURE_DISABLED_BY_DEFAULT | |
| 127 }; | |
| 128 | |
| 118 // Reports metrics about the software reporter via UMA (and sometimes Rappor). | 129 // Reports metrics about the software reporter via UMA (and sometimes Rappor). |
| 119 class UMAHistogramReporter { | 130 class UMAHistogramReporter { |
| 120 public: | 131 public: |
| 121 // Reports the software reporter tool's version via UMA. | 132 // Reports the software reporter tool's version via UMA. |
| 122 void ReportVersion(const base::Version& version) const { | 133 void ReportVersion(const base::Version& version) const { |
| 123 DCHECK(!version.components().empty()); | 134 DCHECK(!version.components().empty()); |
| 124 // The minor version is the 2nd last component of the version, | 135 // The minor version is the 2nd last component of the version, |
| 125 // or just the first component if there is only 1. | 136 // or just the first component if there is only 1. |
| 126 uint32_t minor_version = 0; | 137 uint32_t minor_version = 0; |
| 127 if (version.components().size() > 1) | 138 if (version.components().size() > 1) |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 if (error->GetBubbleView()) { | 358 if (error->GetBubbleView()) { |
| 348 show_bubble = false; | 359 show_bubble = false; |
| 349 break; | 360 break; |
| 350 } | 361 } |
| 351 } | 362 } |
| 352 } | 363 } |
| 353 if (show_bubble) | 364 if (show_bubble) |
| 354 global_error->ShowBubbleView(browser); | 365 global_error->ShowBubbleView(browser); |
| 355 } | 366 } |
| 356 | 367 |
| 368 bool SafeBrowsingExtendedReportingEnabled() { | |
| 369 Browser* browser = chrome::FindLastActive(); | |
| 370 if (!browser) | |
| 371 return false; | |
| 372 Profile* profile = browser->profile(); | |
| 373 DCHECK(profile); | |
| 374 if (profile->IsOffTheRecord()) | |
|
robertshield
2016/08/27 04:04:29
Not sure this is correct as it will return false w
ftirelo
2016/08/29 00:10:37
Thanks for the suggestion. It's something that I w
| |
| 375 return false; | |
| 376 return profile->GetPrefs()->GetBoolean( | |
| 377 prefs::kSafeBrowsingExtendedReportingEnabled); | |
| 378 } | |
| 379 | |
| 357 // This function is called from a worker thread to launch the SwReporter and | 380 // This function is called from a worker thread to launch the SwReporter and |
| 358 // wait for termination to collect its exit code. This task could be | 381 // wait for termination to collect its exit code. This task could be |
| 359 // interrupted by a shutdown at any time, so it shouldn't depend on anything | 382 // interrupted by a shutdown at any time, so it shouldn't depend on anything |
| 360 // external that could be shut down beforehand. | 383 // external that could be shut down beforehand. |
| 361 int LaunchAndWaitForExit(const SwReporterInvocation& invocation) { | 384 int LaunchAndWaitForExit(const SwReporterInvocation& invocation) { |
| 362 if (g_testing_delegate_) | 385 if (g_testing_delegate_) |
| 363 return g_testing_delegate_->LaunchReporter(invocation); | 386 return g_testing_delegate_->LaunchReporter(invocation); |
| 364 base::Process reporter_process = | 387 base::Process reporter_process = |
| 365 base::LaunchProcess(invocation.command_line, base::LaunchOptions()); | 388 base::LaunchProcess(invocation.command_line, base::LaunchOptions()); |
| 366 // This exit code is used to identify that a reporter run didn't happen, so | 389 // This exit code is used to identify that a reporter run didn't happen, so |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 | 592 |
| 570 UMAHistogramReporter uma; | 593 UMAHistogramReporter uma; |
| 571 uma.ReportVersion(version); | 594 uma.ReportVersion(version); |
| 572 uma.ReportExitCode(exit_code); | 595 uma.ReportExitCode(exit_code); |
| 573 uma.ReportFoundUwS(); | 596 uma.ReportFoundUwS(); |
| 574 PrefService* local_state = g_browser_process->local_state(); | 597 PrefService* local_state = g_browser_process->local_state(); |
| 575 if (local_state) { | 598 if (local_state) { |
| 576 local_state->SetInteger(prefs::kSwReporterLastExitCode, exit_code); | 599 local_state->SetInteger(prefs::kSwReporterLastExitCode, exit_code); |
| 577 local_state->SetInt64(prefs::kSwReporterLastTimeTriggered, | 600 local_state->SetInt64(prefs::kSwReporterLastTimeTriggered, |
| 578 base::Time::Now().ToInternalValue()); | 601 base::Time::Now().ToInternalValue()); |
| 602 local_state->SetInt64(prefs::kSwReporterLastTimeSentReport, | |
|
alito
2016/08/26 23:18:08
Should this be set only if we actually did end up
ftirelo
2016/08/29 00:10:37
Good catch!
| |
| 603 base::Time::Now().ToInternalValue()); | |
| 579 } | 604 } |
| 580 uma.ReportRuntime(reporter_running_time); | 605 uma.ReportRuntime(reporter_running_time); |
| 581 uma.ReportScanTimes(); | 606 uma.ReportScanTimes(); |
| 582 uma.ReportMemoryUsage(); | 607 uma.ReportMemoryUsage(); |
| 583 | 608 |
| 584 if (!IsInSRTPromptFieldTrialGroups()) { | 609 if (!IsInSRTPromptFieldTrialGroups()) { |
| 585 // Knowing about disabled field trial is more important than reporter not | 610 // Knowing about disabled field trial is more important than reporter not |
| 586 // finding anything to remove, so check this case first. | 611 // finding anything to remove, so check this case first. |
| 587 RecordReporterStepHistogram(SW_REPORTER_NO_PROMPT_FIELD_TRIAL); | 612 RecordReporterStepHistogram(SW_REPORTER_NO_PROMPT_FIELD_TRIAL); |
| 588 return; | 613 return; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 632 last_time_triggered + | 657 last_time_triggered + |
| 633 base::TimeDelta::FromDays(days_between_reporter_runs_) - | 658 base::TimeDelta::FromDays(days_between_reporter_runs_) - |
| 634 base::Time::Now()); | 659 base::Time::Now()); |
| 635 if (next_trigger_delay.ToInternalValue() <= 0 || | 660 if (next_trigger_delay.ToInternalValue() <= 0 || |
| 636 // Also make sure the kSwReporterLastTimeTriggered value is not set in | 661 // Also make sure the kSwReporterLastTimeTriggered value is not set in |
| 637 // the future. | 662 // the future. |
| 638 last_time_triggered > base::Time::Now()) { | 663 last_time_triggered > base::Time::Now()) { |
| 639 if (g_testing_delegate_) | 664 if (g_testing_delegate_) |
| 640 g_testing_delegate_->NotifyLaunchReady(); | 665 g_testing_delegate_->NotifyLaunchReady(); |
| 641 | 666 |
| 667 // Creating a new invocation to add switches for users who opted into | |
| 668 // extended Safe Browsing reporting. The invocation object is changed | |
| 669 // locally right before the actual process is launched before the current | |
| 670 // user status can change if this runs doesn't complete and we invoke the | |
|
robertshield
2016/08/27 04:04:29
nit: s/runs/run/
ftirelo
2016/08/29 00:10:37
Done.
| |
| 671 // reporter again from the same ReporterRunner object. | |
|
robertshield
2016/08/27 04:04:29
Actually, I'm not sure I fully follow the last sen
ftirelo
2016/08/29 00:10:36
Yes. Changed wording to make the statement more pr
| |
| 672 SwReporterInvocation actual_invocation = | |
| 673 SwReporterInvocation::FromCommandLine(invocation_.command_line); | |
| 674 if (ShouldSendReporterLogs(*local_state)) { | |
|
grt (UTC plus 2)
2016/08/28 19:44:22
nit: omit braces
ftirelo
2016/08/29 00:10:37
Done.
| |
| 675 AddSwitchesForExtendedReporterUser(&actual_invocation); | |
| 676 } | |
| 677 | |
| 642 // It's OK to simply |PostTaskAndReplyWithResult| so that | 678 // It's OK to simply |PostTaskAndReplyWithResult| so that |
| 643 // |LaunchAndWaitForExit| doesn't need to access | 679 // |LaunchAndWaitForExit| doesn't need to access |
| 644 // |main_thread_task_runner_| since the callback is not delayed and the | 680 // |main_thread_task_runner_| since the callback is not delayed and the |
| 645 // test task runner won't need to force it. | 681 // test task runner won't need to force it. |
| 646 base::PostTaskAndReplyWithResult( | 682 base::PostTaskAndReplyWithResult( |
| 647 blocking_task_runner_.get(), FROM_HERE, | 683 blocking_task_runner_.get(), FROM_HERE, |
| 648 base::Bind(&LaunchAndWaitForExit, invocation_), | 684 base::Bind(&LaunchAndWaitForExit, actual_invocation), |
| 649 base::Bind(&ReporterRunner::ReporterDone, base::Unretained(this), | 685 base::Bind(&ReporterRunner::ReporterDone, base::Unretained(this), |
| 650 base::Time::Now(), version_)); | 686 base::Time::Now(), version_)); |
| 651 } else { | 687 } else { |
| 652 main_thread_task_runner_->PostDelayedTask( | 688 main_thread_task_runner_->PostDelayedTask( |
| 653 FROM_HERE, | 689 FROM_HERE, |
| 654 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), | 690 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), |
| 655 next_trigger_delay); | 691 next_trigger_delay); |
| 656 } | 692 } |
| 657 } | 693 } |
| 658 | 694 |
| 695 // Returns true if the experiment to send reporter logs is enabled, the user | |
| 696 // opted into Safe Browsing extended reporting, and logs have been sent at | |
| 697 // least | | |
|
robertshield
2016/08/27 04:04:29
truncated comment?
ftirelo
2016/08/29 00:10:37
Done.
| |
| 698 bool ShouldSendReporterLogs(const PrefService& local_state) { | |
| 699 if (!base::FeatureList::IsEnabled(kSwReporterExtendedSafeBrowsingFeature)) | |
| 700 return false; | |
| 701 | |
| 702 if (!SafeBrowsingExtendedReportingEnabled()) | |
| 703 return false; | |
|
robertshield
2016/08/27 04:04:29
nit:
if (!a || !b)
return false;
is a bit shor
ftirelo
2016/08/29 00:10:36
Done.
| |
| 704 | |
| 705 const base::Time last_time_sent_logs = base::Time::FromInternalValue( | |
| 706 local_state.GetInt64(prefs::kSwReporterLastTimeSentReport)); | |
| 707 base::TimeDelta next_time_send_logs( | |
|
robertshield
2016/08/27 04:04:29
nit: time_until_next_logs ?
ftirelo
2016/08/29 00:10:37
Done.
| |
| 708 last_time_sent_logs + | |
| 709 base::TimeDelta::FromDays(kDaysBetweenReporterLogsSent) - | |
| 710 base::Time::Now()); | |
| 711 return next_time_send_logs.ToInternalValue() <= 0 || | |
|
grt (UTC plus 2)
2016/08/28 19:44:22
using the internal value for this comparison isn't
ftirelo
2016/08/29 00:10:37
That's a good idea. Rewritten using both suggestio
| |
| 712 // Also make sure the kSwReporterLastTimeSentReport value is not set in | |
| 713 // the future. | |
| 714 last_time_sent_logs > base::Time::Now(); | |
| 715 } | |
| 716 | |
| 717 void AddSwitchesForExtendedReporterUser(SwReporterInvocation* invocation) { | |
| 718 invocation->command_line.AppendSwitch(kExtendedSafeBrowsingEnabledSwitch); | |
| 719 invocation->command_line.AppendSwitchASCII( | |
| 720 kChromeVersionSwitch, version_info::GetVersionNumber()); | |
| 721 invocation->command_line.AppendSwitchASCII( | |
|
grt (UTC plus 2)
2016/08/28 19:44:22
nit: avoid some string conversions by using Append
ftirelo
2016/08/29 00:10:37
Done.
| |
| 722 kChromeChannelSwitch, base::IntToString(ChannelAsInt())); | |
| 723 } | |
| 724 | |
| 659 bool first_run_ = true; | 725 bool first_run_ = true; |
| 660 SwReporterInvocation invocation_; | 726 SwReporterInvocation invocation_; |
| 661 base::Version version_; | 727 base::Version version_; |
| 662 scoped_refptr<base::TaskRunner> main_thread_task_runner_; | 728 scoped_refptr<base::TaskRunner> main_thread_task_runner_; |
| 663 scoped_refptr<base::TaskRunner> blocking_task_runner_; | 729 scoped_refptr<base::TaskRunner> blocking_task_runner_; |
| 664 | 730 |
| 665 // This value is used to identify how long to wait before starting a new run | 731 // This value is used to identify how long to wait before starting a new run |
| 666 // of the reporter. It's initialized with the default value and may be changed | 732 // of the reporter. It's initialized with the default value and may be changed |
| 667 // to a different value when a prompt is pending and the reporter should be | 733 // to a different value when a prompt is pending and the reporter should be |
| 668 // run before adding the global error to the Chrome menu. | 734 // run before adding the global error to the Chrome menu. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 723 KEY_QUERY_VALUE); | 789 KEY_QUERY_VALUE); |
| 724 | 790 |
| 725 return srt_cleaner_key.Valid() && srt_cleaner_key.GetValueCount() > 0; | 791 return srt_cleaner_key.Valid() && srt_cleaner_key.GetValueCount() > 0; |
| 726 } | 792 } |
| 727 | 793 |
| 728 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { | 794 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { |
| 729 g_testing_delegate_ = delegate; | 795 g_testing_delegate_ = delegate; |
| 730 } | 796 } |
| 731 | 797 |
| 732 } // namespace safe_browsing | 798 } // namespace safe_browsing |
| OLD | NEW |