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> |
| (...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 const base::Time last_time_triggered = base::Time::FromInternalValue( | 906 const base::Time last_time_triggered = base::Time::FromInternalValue( |
| 907 local_state->GetInt64(prefs::kSwReporterLastTimeTriggered)); | 907 local_state->GetInt64(prefs::kSwReporterLastTimeTriggered)); |
| 908 const base::Time next_trigger( | 908 const base::Time next_trigger( |
| 909 last_time_triggered + | 909 last_time_triggered + |
| 910 base::TimeDelta::FromDays(days_between_reporter_runs_)); | 910 base::TimeDelta::FromDays(days_between_reporter_runs_)); |
| 911 if (!pending_invocations_.empty() && | 911 if (!pending_invocations_.empty() && |
| 912 (next_trigger <= now || | 912 (next_trigger <= now || |
| 913 // Also make sure the kSwReporterLastTimeTriggered value is not set in | 913 // Also make sure the kSwReporterLastTimeTriggered value is not set in |
| 914 // the future. | 914 // the future. |
| 915 last_time_triggered > now)) { | 915 last_time_triggered > now)) { |
| 916 const base::Time now = base::Time::Now(); | |
|
ftirelo
2017/02/06 14:13:24
Please reuse |now| from line 905.
Joe Mason
2017/02/06 18:07:09
Good catch. Done.
| |
| 917 const base::Time last_time_sent_logs = base::Time::FromInternalValue( | |
| 918 local_state->GetInt64(prefs::kSwReporterLastTimeSentReport)); | |
| 919 const base::Time next_time_send_logs = | |
| 920 last_time_sent_logs + | |
| 921 base::TimeDelta::FromDays(kDaysBetweenReporterLogsSent); | |
| 922 // Send the logs for this whole queue of invocations if the last send is | |
| 923 // in the future or if logs have been sent at least | |
| 924 // |kSwReporterLastTimeSentReport| days ago. The former is intended as a | |
| 925 // measure for failure recovery, in case the time in local state is | |
| 926 // incorrectly set to the future. | |
| 927 in_logs_upload_period_ = | |
| 928 last_time_sent_logs > now || next_time_send_logs <= now; | |
| 929 | |
| 916 DCHECK(current_invocations_.empty()); | 930 DCHECK(current_invocations_.empty()); |
| 917 current_invocations_ = pending_invocations_; | 931 current_invocations_ = pending_invocations_; |
| 918 ScheduleNextInvocation(); | 932 ScheduleNextInvocation(); |
| 919 } else { | 933 } else { |
| 920 main_thread_task_runner_->PostDelayedTask( | 934 main_thread_task_runner_->PostDelayedTask( |
| 921 FROM_HERE, | 935 FROM_HERE, |
| 922 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), | 936 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), |
| 923 next_trigger - now); | 937 next_trigger - now); |
| 924 } | 938 } |
| 925 } | 939 } |
| 926 | 940 |
| 927 // Returns true if the experiment to send reporter logs is enabled, the user | 941 // Returns true if the experiment to send reporter logs is enabled, the user |
| 928 // opted into Safe Browsing extended reporting, and logs have been sent at | 942 // opted into Safe Browsing extended reporting, and this queue of invocations |
| 929 // least |kSwReporterLastTimeSentReport| days ago. | 943 // started during the logs upload interval. |
| 930 bool ShouldSendReporterLogs(const std::string& suffix, | 944 bool ShouldSendReporterLogs(const std::string& suffix, |
| 931 const PrefService& local_state) { | 945 const PrefService& local_state) { |
| 932 UMAHistogramReporter uma(suffix); | 946 UMAHistogramReporter uma(suffix); |
| 933 if (!SafeBrowsingExtendedReportingEnabled()) { | 947 if (!SafeBrowsingExtendedReportingEnabled()) { |
| 934 uma.RecordLogsUploadEnabled(REPORTER_LOGS_UPLOADS_SBER_DISABLED); | 948 uma.RecordLogsUploadEnabled(REPORTER_LOGS_UPLOADS_SBER_DISABLED); |
| 935 return false; | 949 return false; |
| 936 } | 950 } |
| 937 | 951 if (!in_logs_upload_period_) { |
| 938 const base::Time now = base::Time::Now(); | 952 uma.RecordLogsUploadEnabled(REPORTER_LOGS_UPLOADS_RECENTLY_SENT_LOGS); |
| 939 const base::Time last_time_sent_logs = base::Time::FromInternalValue( | 953 return false; |
| 940 local_state.GetInt64(prefs::kSwReporterLastTimeSentReport)); | |
| 941 const base::Time next_time_send_logs = | |
| 942 last_time_sent_logs + | |
| 943 base::TimeDelta::FromDays(kDaysBetweenReporterLogsSent); | |
| 944 // Send the logs if the last send is the future or if the interval has | |
| 945 // passed. The former is intended as a measure for failure recovery, in | |
| 946 // case the time in local state is incorrectly set to the future. | |
| 947 if (last_time_sent_logs > now || next_time_send_logs <= now) { | |
| 948 uma.RecordLogsUploadEnabled(REPORTER_LOGS_UPLOADS_ENABLED); | |
| 949 return true; | |
| 950 } | 954 } |
| 951 uma.RecordLogsUploadEnabled(REPORTER_LOGS_UPLOADS_RECENTLY_SENT_LOGS); | 955 uma.RecordLogsUploadEnabled(REPORTER_LOGS_UPLOADS_ENABLED); |
| 952 return false; | 956 return true; |
| 953 } | 957 } |
| 954 | 958 |
| 955 // Appends switches to the next invocation that depend on the user current | 959 // Appends switches to the next invocation that depend on the user current |
| 956 // state with respect to opting into extended Safe Browsing reporting and | 960 // state with respect to opting into extended Safe Browsing reporting and |
| 957 // metrics and crash reporting. The invocation object is changed locally right | 961 // metrics and crash reporting. The invocation object is changed locally right |
| 958 // before the actual process is launched because user status can change | 962 // before the actual process is launched because user status can change |
| 959 // between this and the next run for this ReporterRunner object. For example, | 963 // between this and the next run for this ReporterRunner object. For example, |
| 960 // the ReporterDone() callback schedules the next run for a few days later, | 964 // the ReporterDone() callback schedules the next run for a few days later, |
| 961 // and the user might have changed settings in the meantime. | 965 // and the user might have changed settings in the meantime. |
| 962 void AppendInvocationSpecificSwitches(SwReporterInvocation* next_invocation) { | 966 void AppendInvocationSpecificSwitches(SwReporterInvocation* next_invocation) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1002 base::Version version_; | 1006 base::Version version_; |
| 1003 scoped_refptr<base::TaskRunner> main_thread_task_runner_; | 1007 scoped_refptr<base::TaskRunner> main_thread_task_runner_; |
| 1004 scoped_refptr<base::TaskRunner> blocking_task_runner_; | 1008 scoped_refptr<base::TaskRunner> blocking_task_runner_; |
| 1005 | 1009 |
| 1006 // This value is used to identify how long to wait before starting a new run | 1010 // This value is used to identify how long to wait before starting a new run |
| 1007 // of the reporter queue. It's initialized with the default value and may be | 1011 // of the reporter queue. It's initialized with the default value and may be |
| 1008 // changed to a different value when a prompt is pending and the reporter | 1012 // changed to a different value when a prompt is pending and the reporter |
| 1009 // should be run before adding the global error to the Chrome menu. | 1013 // should be run before adding the global error to the Chrome menu. |
| 1010 int days_between_reporter_runs_ = kDaysBetweenSuccessfulSwReporterRuns; | 1014 int days_between_reporter_runs_ = kDaysBetweenSuccessfulSwReporterRuns; |
| 1011 | 1015 |
| 1016 bool in_logs_upload_period_ = false; | |
|
grt (UTC plus 2)
2017/02/06 08:25:35
please document this new member.
Joe Mason
2017/02/06 18:07:09
Done.
| |
| 1017 | |
| 1012 // A single leaky instance. | 1018 // A single leaky instance. |
| 1013 static ReporterRunner* instance_; | 1019 static ReporterRunner* instance_; |
| 1014 | 1020 |
| 1015 DISALLOW_COPY_AND_ASSIGN(ReporterRunner); | 1021 DISALLOW_COPY_AND_ASSIGN(ReporterRunner); |
| 1016 }; | 1022 }; |
| 1017 | 1023 |
| 1018 ReporterRunner* ReporterRunner::instance_ = nullptr; | 1024 ReporterRunner* ReporterRunner::instance_ = nullptr; |
| 1019 | 1025 |
| 1020 SwReporterInvocation::SwReporterInvocation() | 1026 SwReporterInvocation::SwReporterInvocation() |
| 1021 : command_line(base::CommandLine::NO_PROGRAM) {} | 1027 : command_line(base::CommandLine::NO_PROGRAM) {} |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1073 return srt_cleaner_key.Open(HKEY_CURRENT_USER, cleaner_key_path.c_str(), | 1079 return srt_cleaner_key.Open(HKEY_CURRENT_USER, cleaner_key_path.c_str(), |
| 1074 KEY_QUERY_VALUE) == ERROR_SUCCESS && | 1080 KEY_QUERY_VALUE) == ERROR_SUCCESS && |
| 1075 srt_cleaner_key.GetValueCount() > 0; | 1081 srt_cleaner_key.GetValueCount() > 0; |
| 1076 } | 1082 } |
| 1077 | 1083 |
| 1078 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { | 1084 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { |
| 1079 g_testing_delegate_ = delegate; | 1085 g_testing_delegate_ = delegate; |
| 1080 } | 1086 } |
| 1081 | 1087 |
| 1082 } // namespace safe_browsing | 1088 } // namespace safe_browsing |
| OLD | NEW |