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 <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
| 16 #include "base/callback_helpers.h" | 16 #include "base/callback_helpers.h" |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/debug/leak_annotations.h" | 18 #include "base/debug/leak_annotations.h" |
| 19 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
| 20 #include "base/macros.h" | 20 #include "base/macros.h" |
| 21 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
| 22 #include "base/metrics/field_trial.h" | 22 #include "base/metrics/field_trial.h" |
| 23 #include "base/metrics/histogram_macros.h" | 23 #include "base/metrics/histogram_macros.h" |
| 24 #include "base/metrics/sparse_histogram.h" | 24 #include "base/metrics/sparse_histogram.h" |
| 25 #include "base/process/launch.h" | 25 #include "base/process/launch.h" |
| 26 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
| 27 #include "base/strings/stringprintf.h" | 27 #include "base/strings/stringprintf.h" |
| 28 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
| 29 #include "base/task_runner_util.h" | 29 #include "base/task_runner_util.h" |
| 30 #include "base/task_scheduler/post_task.h" | |
| 31 #include "base/task_scheduler/task_traits.h" | |
| 30 #include "base/time/time.h" | 32 #include "base/time/time.h" |
| 33 #include "base/version.h" | |
| 31 #include "base/win/registry.h" | 34 #include "base/win/registry.h" |
| 32 #include "chrome/browser/browser_process.h" | 35 #include "chrome/browser/browser_process.h" |
| 33 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" | 36 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" |
| 34 #include "chrome/browser/profiles/profile.h" | 37 #include "chrome/browser/profiles/profile.h" |
| 35 #include "chrome/browser/profiles/profile_io_data.h" | 38 #include "chrome/browser/profiles/profile_io_data.h" |
| 36 #include "chrome/browser/safe_browsing/srt_client_info_win.h" | 39 #include "chrome/browser/safe_browsing/srt_client_info_win.h" |
| 37 #include "chrome/browser/safe_browsing/srt_global_error_win.h" | 40 #include "chrome/browser/safe_browsing/srt_global_error_win.h" |
| 38 #include "chrome/browser/ui/browser_finder.h" | 41 #include "chrome/browser/ui/browser_finder.h" |
| 39 #include "chrome/browser/ui/browser_list.h" | 42 #include "chrome/browser/ui/browser_list.h" |
| 40 #include "chrome/browser/ui/browser_list_observer.h" | 43 #include "chrome/browser/ui/browser_list_observer.h" |
| (...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 706 prefs->SetString(prefs::kSwReporterPromptVersion, | 709 prefs->SetString(prefs::kSwReporterPromptVersion, |
| 707 reporter_version.GetString()); | 710 reporter_version.GetString()); |
| 708 | 711 |
| 709 // Download the SRT. | 712 // Download the SRT. |
| 710 RecordReporterStepHistogram(SW_REPORTER_DOWNLOAD_START); | 713 RecordReporterStepHistogram(SW_REPORTER_DOWNLOAD_START); |
| 711 | 714 |
| 712 // All the work happens in the self-deleting class below. | 715 // All the work happens in the self-deleting class below. |
| 713 new SRTFetcher(profile); | 716 new SRTFetcher(profile); |
| 714 } | 717 } |
| 715 | 718 |
| 719 base::Time Now() { | |
| 720 if (g_testing_delegate_) | |
| 721 return g_testing_delegate_->Now(); | |
|
Sorin Jianu
2017/02/23 20:39:04
could use ?:
Joe Mason
2017/02/24 17:35:29
Done.
| |
| 722 return base::Time::Now(); | |
| 723 } | |
| 724 | |
| 716 } // namespace | 725 } // namespace |
| 717 | 726 |
| 718 // This class tries to run a queue of reporters and react to their exit codes. | 727 // This class tries to run a queue of reporters and react to their exit codes. |
| 719 // It schedules subsequent runs of the queue as needed, or retries as soon as a | 728 // It schedules subsequent runs of the queue as needed, or retries as soon as a |
| 720 // browser is available when none is on first try. | 729 // browser is available when none is on first try. |
| 721 class ReporterRunner : public chrome::BrowserListObserver { | 730 class ReporterRunner : public chrome::BrowserListObserver { |
| 722 public: | 731 public: |
| 723 // Registers |invocations| to run next time |TryToRun| is scheduled. (And if | 732 // Registers |invocations| to run next time |TryToRun| is scheduled. (And if |
| 724 // it's not already scheduled, call it now.) | 733 // it's not already scheduled, call it now.) |
| 725 static void ScheduleInvocations( | 734 static void ScheduleInvocations(const SwReporterQueue& invocations, |
| 726 const SwReporterQueue& invocations, | 735 const base::Version& version) { |
| 727 const base::Version& version, | |
| 728 scoped_refptr<base::TaskRunner> main_thread_task_runner, | |
| 729 scoped_refptr<base::TaskRunner> blocking_task_runner) { | |
| 730 if (!instance_) { | 736 if (!instance_) { |
| 731 instance_ = new ReporterRunner; | 737 instance_ = new ReporterRunner; |
| 732 ANNOTATE_LEAKING_OBJECT_PTR(instance_); | 738 ANNOTATE_LEAKING_OBJECT_PTR(instance_); |
| 733 } | 739 } |
| 734 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 740 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 735 | 741 |
| 736 // There's nothing to do if the invocation parameters and version of the | 742 // There's nothing to do if the invocation parameters and version of the |
| 737 // reporter have not changed, we just keep running the tasks that are | 743 // reporter have not changed, we just keep running the tasks that are |
| 738 // running now. | 744 // running now. |
| 739 if (instance_->pending_invocations_ == invocations && | 745 if (instance_->pending_invocations_ == invocations && |
| 740 instance_->version_.IsValid() && instance_->version_ == version) | 746 instance_->version_.IsValid() && instance_->version_ == version) |
| 741 return; | 747 return; |
| 742 | 748 |
| 743 instance_->pending_invocations_ = invocations; | 749 instance_->pending_invocations_ = invocations; |
| 744 instance_->version_ = version; | 750 instance_->version_ = version; |
| 745 instance_->main_thread_task_runner_ = std::move(main_thread_task_runner); | |
| 746 instance_->blocking_task_runner_ = std::move(blocking_task_runner); | |
| 747 | |
| 748 if (instance_->first_run_) { | 751 if (instance_->first_run_) { |
| 749 instance_->first_run_ = false; | 752 instance_->first_run_ = false; |
| 750 instance_->TryToRun(); | 753 instance_->TryToRun(); |
| 751 } | 754 } |
| 752 } | 755 } |
| 753 | 756 |
| 754 private: | 757 private: |
| 755 ReporterRunner() {} | 758 ReporterRunner() {} |
| 756 ~ReporterRunner() override {} | 759 ~ReporterRunner() override {} |
| 757 | 760 |
| 758 // BrowserListObserver. | 761 // BrowserListObserver. |
| 759 void OnBrowserSetLastActive(Browser* browser) override {} | 762 void OnBrowserSetLastActive(Browser* browser) override {} |
| 760 void OnBrowserRemoved(Browser* browser) override {} | 763 void OnBrowserRemoved(Browser* browser) override {} |
| 761 void OnBrowserAdded(Browser* browser) override { | 764 void OnBrowserAdded(Browser* browser) override { |
| 762 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 765 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 763 DCHECK(browser); | 766 DCHECK(browser); |
| 764 MaybeFetchSRT(browser, version_); | 767 MaybeFetchSRT(browser, version_); |
| 765 BrowserList::RemoveObserver(this); | 768 BrowserList::RemoveObserver(this); |
| 766 } | 769 } |
| 767 | 770 |
| 768 // Launches the command line at the head of the queue. | 771 // Launches the command line at the head of the queue. |
| 769 void ScheduleNextInvocation() { | 772 void ScheduleNextInvocation() { |
| 770 DCHECK(!current_invocations_.empty()); | 773 DCHECK(!current_invocations_.empty()); |
| 771 auto next_invocation = current_invocations_.front(); | 774 auto next_invocation = current_invocations_.front(); |
| 772 current_invocations_.pop(); | 775 current_invocations_.pop(); |
| 773 | 776 |
| 774 if (g_testing_delegate_) | |
| 775 g_testing_delegate_->NotifyLaunchReady(); | |
| 776 | |
| 777 AppendInvocationSpecificSwitches(&next_invocation); | 777 AppendInvocationSpecificSwitches(&next_invocation); |
| 778 | 778 |
| 779 // It's OK to simply |PostTaskAndReplyWithResult| so that | 779 base::TaskRunner* task_runner = |
| 780 // |LaunchAndWaitForExit| doesn't need to access |main_thread_task_runner_| | 780 g_testing_delegate_ ? g_testing_delegate_->BlockingTaskRunner() |
| 781 // since the callback is not delayed and the test task runner won't need to | 781 : blocking_task_runner_.get(); |
| 782 // force it. | |
| 783 base::PostTaskAndReplyWithResult( | 782 base::PostTaskAndReplyWithResult( |
| 784 blocking_task_runner_.get(), FROM_HERE, | 783 task_runner, FROM_HERE, |
| 785 base::Bind(&LaunchAndWaitForExit, next_invocation), | 784 base::Bind(&LaunchAndWaitForExit, next_invocation), |
| 786 base::Bind(&ReporterRunner::ReporterDone, base::Unretained(this), | 785 base::Bind(&ReporterRunner::ReporterDone, base::Unretained(this), Now(), |
| 787 base::Time::Now(), version_, next_invocation)); | 786 version_, next_invocation)); |
| 788 } | 787 } |
| 789 | 788 |
| 790 // This method is called on the UI thread when an invocation of the reporter | 789 // This method is called on the UI thread when an invocation of the reporter |
| 791 // has completed. This is run as a task posted from an interruptible worker | 790 // has completed. This is run as a task posted from an interruptible worker |
| 792 // thread so should be resilient to unexpected shutdown. | 791 // thread so should be resilient to unexpected shutdown. |
| 793 void ReporterDone(const base::Time& reporter_start_time, | 792 void ReporterDone(const base::Time& reporter_start_time, |
| 794 const base::Version& version, | 793 const base::Version& version, |
| 795 const SwReporterInvocation& finished_invocation, | 794 const SwReporterInvocation& finished_invocation, |
| 796 int exit_code) { | 795 int exit_code) { |
| 797 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 796 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 798 | 797 |
| 799 if (g_testing_delegate_) | 798 base::Time now = Now(); |
| 800 g_testing_delegate_->NotifyReporterDone(); | 799 base::TimeDelta reporter_running_time = now - reporter_start_time; |
| 801 | |
| 802 base::TimeDelta reporter_running_time = | |
| 803 base::Time::Now() - reporter_start_time; | |
| 804 | 800 |
| 805 // Don't continue the current queue of reporters if one failed to launch. | 801 // Don't continue the current queue of reporters if one failed to launch. |
| 806 if (exit_code == kReporterFailureExitCode) | 802 if (exit_code == kReporterFailureExitCode) |
| 807 current_invocations_ = SwReporterQueue(); | 803 current_invocations_ = SwReporterQueue(); |
| 808 | 804 |
| 809 // As soon as we're not running this queue, schedule the next overall queue | 805 // As soon as we're not running this queue, schedule the next overall queue |
| 810 // run after the regular delay. (If there was a failure it's not worth | 806 // run after the regular delay. (If there was a failure it's not worth |
| 811 // retrying earlier, risking running too often if it always fails, since | 807 // retrying earlier, risking running too often if it always fails, since |
| 812 // not many users fail here.) | 808 // not many users fail here.) |
| 813 if (current_invocations_.empty()) { | 809 if (current_invocations_.empty()) { |
| 814 main_thread_task_runner_->PostDelayedTask( | 810 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 815 FROM_HERE, | 811 FROM_HERE, |
| 816 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), | 812 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), |
| 817 base::TimeDelta::FromDays(days_between_reporter_runs_)); | 813 base::TimeDelta::FromDays(days_between_reporter_runs_)); |
| 818 } else { | 814 } else { |
| 819 ScheduleNextInvocation(); | 815 ScheduleNextInvocation(); |
| 820 } | 816 } |
| 821 | 817 |
| 822 // If the reporter failed to launch, do not process the results. (The exit | 818 // If the reporter failed to launch, do not process the results. (The exit |
| 823 // code itself doesn't need to be logged in this case because | 819 // code itself doesn't need to be logged in this case because |
| 824 // SW_REPORTER_FAILED_TO_START is logged in |LaunchAndWaitForExit|.) | 820 // SW_REPORTER_FAILED_TO_START is logged in |LaunchAndWaitForExit|.) |
| 825 if (exit_code == kReporterFailureExitCode) | 821 if (exit_code == kReporterFailureExitCode) |
| 826 return; | 822 return; |
| 827 | 823 |
| 828 UMAHistogramReporter uma(finished_invocation.suffix); | 824 UMAHistogramReporter uma(finished_invocation.suffix); |
| 829 uma.ReportVersion(version); | 825 uma.ReportVersion(version); |
| 830 uma.ReportExitCode(exit_code); | 826 uma.ReportExitCode(exit_code); |
| 831 uma.ReportEngineErrorCode(); | 827 uma.ReportEngineErrorCode(); |
| 832 uma.ReportFoundUwS(finished_invocation.BehaviourIsSupported( | 828 uma.ReportFoundUwS(finished_invocation.BehaviourIsSupported( |
| 833 SwReporterInvocation::BEHAVIOUR_LOG_TO_RAPPOR)); | 829 SwReporterInvocation::BEHAVIOUR_LOG_TO_RAPPOR)); |
| 834 | 830 |
| 835 PrefService* local_state = g_browser_process->local_state(); | 831 PrefService* local_state = g_browser_process->local_state(); |
| 836 if (local_state) { | 832 if (local_state) { |
| 837 if (finished_invocation.BehaviourIsSupported( | 833 if (finished_invocation.BehaviourIsSupported( |
| 838 SwReporterInvocation::BEHAVIOUR_LOG_EXIT_CODE_TO_PREFS)) { | 834 SwReporterInvocation::BEHAVIOUR_LOG_EXIT_CODE_TO_PREFS)) { |
| 839 local_state->SetInteger(prefs::kSwReporterLastExitCode, exit_code); | 835 local_state->SetInteger(prefs::kSwReporterLastExitCode, exit_code); |
| 840 } | 836 } |
| 841 local_state->SetInt64(prefs::kSwReporterLastTimeTriggered, | 837 local_state->SetInt64(prefs::kSwReporterLastTimeTriggered, |
| 842 base::Time::Now().ToInternalValue()); | 838 now.ToInternalValue()); |
| 843 } | 839 } |
| 844 uma.ReportRuntime(reporter_running_time); | 840 uma.ReportRuntime(reporter_running_time); |
| 845 uma.ReportScanTimes(); | 841 uma.ReportScanTimes(); |
| 846 uma.ReportMemoryUsage(); | 842 uma.ReportMemoryUsage(); |
| 847 if (finished_invocation.logs_upload_enabled) | 843 if (finished_invocation.logs_upload_enabled) |
| 848 uma.RecordLogsUploadResult(); | 844 uma.RecordLogsUploadResult(); |
| 849 | 845 |
| 850 if (!finished_invocation.BehaviourIsSupported( | 846 if (!finished_invocation.BehaviourIsSupported( |
| 851 SwReporterInvocation::BEHAVIOUR_TRIGGER_PROMPT)) { | 847 SwReporterInvocation::BEHAVIOUR_TRIGGER_PROMPT)) { |
| 852 return; | 848 return; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 895 | 891 |
| 896 // Run a queue of reporters if none have been triggered in the last | 892 // Run a queue of reporters if none have been triggered in the last |
| 897 // |days_between_reporter_runs_| days, which depends if there is a pending | 893 // |days_between_reporter_runs_| days, which depends if there is a pending |
| 898 // prompt to be added to Chrome's menu. | 894 // prompt to be added to Chrome's menu. |
| 899 if (local_state->GetBoolean(prefs::kSwReporterPendingPrompt)) { | 895 if (local_state->GetBoolean(prefs::kSwReporterPendingPrompt)) { |
| 900 days_between_reporter_runs_ = kDaysBetweenSwReporterRunsForPendingPrompt; | 896 days_between_reporter_runs_ = kDaysBetweenSwReporterRunsForPendingPrompt; |
| 901 RecordReporterStepHistogram(SW_REPORTER_RAN_DAILY); | 897 RecordReporterStepHistogram(SW_REPORTER_RAN_DAILY); |
| 902 } else { | 898 } else { |
| 903 days_between_reporter_runs_ = kDaysBetweenSuccessfulSwReporterRuns; | 899 days_between_reporter_runs_ = kDaysBetweenSuccessfulSwReporterRuns; |
| 904 } | 900 } |
| 905 const base::Time now = base::Time::Now(); | 901 const base::Time now = Now(); |
| 906 const base::Time last_time_triggered = base::Time::FromInternalValue( | 902 const base::Time last_time_triggered = base::Time::FromInternalValue( |
| 907 local_state->GetInt64(prefs::kSwReporterLastTimeTriggered)); | 903 local_state->GetInt64(prefs::kSwReporterLastTimeTriggered)); |
| 908 const base::Time next_trigger( | 904 const base::Time next_trigger( |
| 909 last_time_triggered + | 905 last_time_triggered + |
| 910 base::TimeDelta::FromDays(days_between_reporter_runs_)); | 906 base::TimeDelta::FromDays(days_between_reporter_runs_)); |
| 911 if (!pending_invocations_.empty() && | 907 if (!pending_invocations_.empty() && |
| 912 (next_trigger <= now || | 908 (next_trigger <= now || |
| 913 // Also make sure the kSwReporterLastTimeTriggered value is not set in | 909 // Also make sure the kSwReporterLastTimeTriggered value is not set in |
| 914 // the future. | 910 // the future. |
| 915 last_time_triggered > now)) { | 911 last_time_triggered > now)) { |
| 916 const base::Time last_time_sent_logs = base::Time::FromInternalValue( | 912 const base::Time last_time_sent_logs = base::Time::FromInternalValue( |
| 917 local_state->GetInt64(prefs::kSwReporterLastTimeSentReport)); | 913 local_state->GetInt64(prefs::kSwReporterLastTimeSentReport)); |
| 918 const base::Time next_time_send_logs = | 914 const base::Time next_time_send_logs = |
| 919 last_time_sent_logs + | 915 last_time_sent_logs + |
| 920 base::TimeDelta::FromDays(kDaysBetweenReporterLogsSent); | 916 base::TimeDelta::FromDays(kDaysBetweenReporterLogsSent); |
| 921 // Send the logs for this whole queue of invocations if the last send is | 917 // Send the logs for this whole queue of invocations if the last send is |
| 922 // in the future or if logs have been sent at least | 918 // in the future or if logs have been sent at least |
| 923 // |kSwReporterLastTimeSentReport| days ago. The former is intended as a | 919 // |kSwReporterLastTimeSentReport| days ago. The former is intended as a |
| 924 // measure for failure recovery, in case the time in local state is | 920 // measure for failure recovery, in case the time in local state is |
| 925 // incorrectly set to the future. | 921 // incorrectly set to the future. |
| 926 in_logs_upload_period_ = | 922 in_logs_upload_period_ = |
| 927 last_time_sent_logs > now || next_time_send_logs <= now; | 923 last_time_sent_logs > now || next_time_send_logs <= now; |
| 928 | 924 |
| 929 DCHECK(current_invocations_.empty()); | 925 DCHECK(current_invocations_.empty()); |
| 930 current_invocations_ = pending_invocations_; | 926 current_invocations_ = pending_invocations_; |
| 931 ScheduleNextInvocation(); | 927 ScheduleNextInvocation(); |
| 932 } else { | 928 } else { |
| 933 main_thread_task_runner_->PostDelayedTask( | 929 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 934 FROM_HERE, | 930 FROM_HERE, |
| 935 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), | 931 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), |
| 936 next_trigger - now); | 932 next_trigger - now); |
| 937 } | 933 } |
| 938 } | 934 } |
| 939 | 935 |
| 940 // Returns true if the experiment to send reporter logs is enabled, the user | 936 // Returns true if the experiment to send reporter logs is enabled, the user |
| 941 // opted into Safe Browsing extended reporting, and this queue of invocations | 937 // opted into Safe Browsing extended reporting, and this queue of invocations |
| 942 // started during the logs upload interval. | 938 // started during the logs upload interval. |
| 943 bool ShouldSendReporterLogs(const std::string& suffix, | 939 bool ShouldSendReporterLogs(const std::string& suffix, |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 970 local_state && | 966 local_state && |
| 971 ShouldSendReporterLogs(next_invocation->suffix, *local_state)) { | 967 ShouldSendReporterLogs(next_invocation->suffix, *local_state)) { |
| 972 next_invocation->logs_upload_enabled = true; | 968 next_invocation->logs_upload_enabled = true; |
| 973 AddSwitchesForExtendedReportingUser(next_invocation); | 969 AddSwitchesForExtendedReportingUser(next_invocation); |
| 974 // Set the local state value before the first attempt to run the | 970 // Set the local state value before the first attempt to run the |
| 975 // reporter, because we only want to upload logs once in the window | 971 // reporter, because we only want to upload logs once in the window |
| 976 // defined by |kDaysBetweenReporterLogsSent|. If we set with other local | 972 // defined by |kDaysBetweenReporterLogsSent|. If we set with other local |
| 977 // state values after the reporter runs, we could send logs again too | 973 // state values after the reporter runs, we could send logs again too |
| 978 // quickly (for example, if Chrome stops before the reporter finishes). | 974 // quickly (for example, if Chrome stops before the reporter finishes). |
| 979 local_state->SetInt64(prefs::kSwReporterLastTimeSentReport, | 975 local_state->SetInt64(prefs::kSwReporterLastTimeSentReport, |
| 980 base::Time::Now().ToInternalValue()); | 976 Now().ToInternalValue()); |
| 981 } | 977 } |
| 982 | 978 |
| 983 if (ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()) | 979 if (ChromeMetricsServiceAccessor::IsMetricsAndCrashReportingEnabled()) |
| 984 next_invocation->command_line.AppendSwitch(kEnableCrashReporting); | 980 next_invocation->command_line.AppendSwitch(kEnableCrashReporting); |
| 985 } | 981 } |
| 986 | 982 |
| 987 // Adds switches to be sent to the Software Reporter when the user opted into | 983 // Adds switches to be sent to the Software Reporter when the user opted into |
| 988 // extended Safe Browsing reporting and is not incognito. | 984 // extended Safe Browsing reporting and is not incognito. |
| 989 void AddSwitchesForExtendedReportingUser(SwReporterInvocation* invocation) { | 985 void AddSwitchesForExtendedReportingUser(SwReporterInvocation* invocation) { |
| 990 invocation->command_line.AppendSwitch(kExtendedSafeBrowsingEnabledSwitch); | 986 invocation->command_line.AppendSwitch(kExtendedSafeBrowsingEnabledSwitch); |
| 991 invocation->command_line.AppendSwitchASCII( | 987 invocation->command_line.AppendSwitchASCII( |
| 992 kChromeVersionSwitch, version_info::GetVersionNumber()); | 988 kChromeVersionSwitch, version_info::GetVersionNumber()); |
| 993 invocation->command_line.AppendSwitchNative( | 989 invocation->command_line.AppendSwitchNative( |
| 994 kChromeChannelSwitch, base::IntToString16(ChannelAsInt())); | 990 kChromeChannelSwitch, base::IntToString16(ChannelAsInt())); |
| 995 } | 991 } |
| 996 | 992 |
| 997 bool first_run_ = true; | 993 bool first_run_ = true; |
| 998 | 994 |
| 999 // The queue of invocations that are currently running. | 995 // The queue of invocations that are currently running. |
| 1000 SwReporterQueue current_invocations_; | 996 SwReporterQueue current_invocations_; |
| 1001 | 997 |
| 1002 // The invocations to run next time the SwReporter is run. | 998 // The invocations to run next time the SwReporter is run. |
| 1003 SwReporterQueue pending_invocations_; | 999 SwReporterQueue pending_invocations_; |
| 1004 | 1000 |
| 1005 base::Version version_; | 1001 base::Version version_; |
| 1006 scoped_refptr<base::TaskRunner> main_thread_task_runner_; | 1002 |
| 1007 scoped_refptr<base::TaskRunner> blocking_task_runner_; | 1003 scoped_refptr<base::TaskRunner> blocking_task_runner_ = |
| 1004 base::CreateTaskRunnerWithTraits( | |
|
Jialiu Lin
2017/02/23 18:28:00
nit: maybe put this initialization logic inside th
gab
2017/02/23 19:01:51
I this and think we should use C++11 member initia
gab
2017/02/23 19:02:25
I *like* this (i.e. the code as-is in this patch s
Joe Mason
2017/02/24 17:35:29
I agree.
| |
| 1005 // LaunchAndWaitForExit() creates (MayBlock()) and joins | |
| 1006 // (WithBaseSyncPrimitives()) a process. | |
| 1007 base::TaskTraits() | |
| 1008 .WithShutdownBehavior( | |
| 1009 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) | |
| 1010 .WithPriority(base::TaskPriority::BACKGROUND) | |
| 1011 .MayBlock() | |
| 1012 .WithBaseSyncPrimitives()); | |
| 1008 | 1013 |
| 1009 // This value is used to identify how long to wait before starting a new run | 1014 // This value is used to identify how long to wait before starting a new run |
| 1010 // of the reporter queue. It's initialized with the default value and may be | 1015 // of the reporter queue. It's initialized with the default value and may be |
| 1011 // changed to a different value when a prompt is pending and the reporter | 1016 // changed to a different value when a prompt is pending and the reporter |
| 1012 // should be run before adding the global error to the Chrome menu. | 1017 // should be run before adding the global error to the Chrome menu. |
| 1013 int days_between_reporter_runs_ = kDaysBetweenSuccessfulSwReporterRuns; | 1018 int days_between_reporter_runs_ = kDaysBetweenSuccessfulSwReporterRuns; |
| 1014 | 1019 |
| 1015 // This will be true if the current queue of invocations started at a time | 1020 // This will be true if the current queue of invocations started at a time |
| 1016 // when logs should be uploaded. | 1021 // when logs should be uploaded. |
| 1017 bool in_logs_upload_period_ = false; | 1022 bool in_logs_upload_period_ = false; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1047 supported_behaviours == other.supported_behaviours && | 1052 supported_behaviours == other.supported_behaviours && |
| 1048 logs_upload_enabled == other.logs_upload_enabled; | 1053 logs_upload_enabled == other.logs_upload_enabled; |
| 1049 } | 1054 } |
| 1050 | 1055 |
| 1051 bool SwReporterInvocation::BehaviourIsSupported( | 1056 bool SwReporterInvocation::BehaviourIsSupported( |
| 1052 SwReporterInvocation::Behaviours intended_behaviour) const { | 1057 SwReporterInvocation::Behaviours intended_behaviour) const { |
| 1053 return (supported_behaviours & intended_behaviour) != 0; | 1058 return (supported_behaviours & intended_behaviour) != 0; |
| 1054 } | 1059 } |
| 1055 | 1060 |
| 1056 void RunSwReporters(const SwReporterQueue& invocations, | 1061 void RunSwReporters(const SwReporterQueue& invocations, |
| 1057 const base::Version& version, | 1062 const base::Version& version) { |
| 1058 scoped_refptr<base::TaskRunner> main_thread_task_runner, | |
| 1059 scoped_refptr<base::TaskRunner> blocking_task_runner) { | |
| 1060 DCHECK(!invocations.empty()); | 1063 DCHECK(!invocations.empty()); |
| 1061 DCHECK(version.IsValid()); | 1064 DCHECK(version.IsValid()); |
| 1062 ReporterRunner::ScheduleInvocations(invocations, version, | 1065 ReporterRunner::ScheduleInvocations(invocations, version); |
| 1063 std::move(main_thread_task_runner), | |
| 1064 std::move(blocking_task_runner)); | |
| 1065 } | 1066 } |
| 1066 | 1067 |
| 1067 bool ReporterFoundUws() { | 1068 bool ReporterFoundUws() { |
| 1068 PrefService* local_state = g_browser_process->local_state(); | 1069 PrefService* local_state = g_browser_process->local_state(); |
| 1069 if (!local_state) | 1070 if (!local_state) |
| 1070 return false; | 1071 return false; |
| 1071 int exit_code = local_state->GetInteger(prefs::kSwReporterLastExitCode); | 1072 int exit_code = local_state->GetInteger(prefs::kSwReporterLastExitCode); |
| 1072 return exit_code == kSwReporterCleanupNeeded; | 1073 return exit_code == kSwReporterCleanupNeeded; |
| 1073 } | 1074 } |
| 1074 | 1075 |
| 1075 bool UserHasRunCleaner() { | 1076 bool UserHasRunCleaner() { |
| 1076 base::string16 cleaner_key_path(kSoftwareRemovalToolRegistryKey); | 1077 base::string16 cleaner_key_path(kSoftwareRemovalToolRegistryKey); |
| 1077 cleaner_key_path.append(L"\\").append(kCleanerSubKey); | 1078 cleaner_key_path.append(L"\\").append(kCleanerSubKey); |
| 1078 | 1079 |
| 1079 base::win::RegKey srt_cleaner_key; | 1080 base::win::RegKey srt_cleaner_key; |
| 1080 return srt_cleaner_key.Open(HKEY_CURRENT_USER, cleaner_key_path.c_str(), | 1081 return srt_cleaner_key.Open(HKEY_CURRENT_USER, cleaner_key_path.c_str(), |
| 1081 KEY_QUERY_VALUE) == ERROR_SUCCESS && | 1082 KEY_QUERY_VALUE) == ERROR_SUCCESS && |
| 1082 srt_cleaner_key.GetValueCount() > 0; | 1083 srt_cleaner_key.GetValueCount() > 0; |
| 1083 } | 1084 } |
| 1084 | 1085 |
| 1085 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { | 1086 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { |
| 1086 g_testing_delegate_ = delegate; | 1087 g_testing_delegate_ = delegate; |
| 1087 } | 1088 } |
| 1088 | 1089 |
| 1089 } // namespace safe_browsing | 1090 } // namespace safe_browsing |
| OLD | NEW |