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

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

Issue 2669393003: Check the SRT logs upload time for an entire queue of SRT invocations at once. (Closed)
Patch Set: Use const ref in loop index Created 3 years, 10 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
« no previous file with comments | « chrome/browser/safe_browsing/srt_fetcher_browsertest_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 895 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 last_time_sent_logs = base::Time::FromInternalValue(
917 local_state->GetInt64(prefs::kSwReporterLastTimeSentReport));
918 const base::Time next_time_send_logs =
919 last_time_sent_logs +
920 base::TimeDelta::FromDays(kDaysBetweenReporterLogsSent);
921 // 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
923 // |kSwReporterLastTimeSentReport| days ago. The former is intended as a
924 // measure for failure recovery, in case the time in local state is
925 // incorrectly set to the future.
926 in_logs_upload_period_ =
927 last_time_sent_logs > now || next_time_send_logs <= now;
928
916 DCHECK(current_invocations_.empty()); 929 DCHECK(current_invocations_.empty());
917 current_invocations_ = pending_invocations_; 930 current_invocations_ = pending_invocations_;
918 ScheduleNextInvocation(); 931 ScheduleNextInvocation();
919 } else { 932 } else {
920 main_thread_task_runner_->PostDelayedTask( 933 main_thread_task_runner_->PostDelayedTask(
921 FROM_HERE, 934 FROM_HERE,
922 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), 935 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)),
923 next_trigger - now); 936 next_trigger - now);
924 } 937 }
925 } 938 }
926 939
927 // Returns true if the experiment to send reporter logs is enabled, the user 940 // 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 941 // opted into Safe Browsing extended reporting, and this queue of invocations
929 // least |kSwReporterLastTimeSentReport| days ago. 942 // started during the logs upload interval.
930 bool ShouldSendReporterLogs(const std::string& suffix, 943 bool ShouldSendReporterLogs(const std::string& suffix,
931 const PrefService& local_state) { 944 const PrefService& local_state) {
932 UMAHistogramReporter uma(suffix); 945 UMAHistogramReporter uma(suffix);
933 if (!SafeBrowsingExtendedReportingEnabled()) { 946 if (!SafeBrowsingExtendedReportingEnabled()) {
934 uma.RecordLogsUploadEnabled(REPORTER_LOGS_UPLOADS_SBER_DISABLED); 947 uma.RecordLogsUploadEnabled(REPORTER_LOGS_UPLOADS_SBER_DISABLED);
935 return false; 948 return false;
936 } 949 }
937 950 if (!in_logs_upload_period_) {
938 const base::Time now = base::Time::Now(); 951 uma.RecordLogsUploadEnabled(REPORTER_LOGS_UPLOADS_RECENTLY_SENT_LOGS);
939 const base::Time last_time_sent_logs = base::Time::FromInternalValue( 952 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 } 953 }
951 uma.RecordLogsUploadEnabled(REPORTER_LOGS_UPLOADS_RECENTLY_SENT_LOGS); 954 uma.RecordLogsUploadEnabled(REPORTER_LOGS_UPLOADS_ENABLED);
952 return false; 955 return true;
953 } 956 }
954 957
955 // Appends switches to the next invocation that depend on the user current 958 // Appends switches to the next invocation that depend on the user current
956 // state with respect to opting into extended Safe Browsing reporting and 959 // state with respect to opting into extended Safe Browsing reporting and
957 // metrics and crash reporting. The invocation object is changed locally right 960 // metrics and crash reporting. The invocation object is changed locally right
958 // before the actual process is launched because user status can change 961 // before the actual process is launched because user status can change
959 // between this and the next run for this ReporterRunner object. For example, 962 // 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, 963 // the ReporterDone() callback schedules the next run for a few days later,
961 // and the user might have changed settings in the meantime. 964 // and the user might have changed settings in the meantime.
962 void AppendInvocationSpecificSwitches(SwReporterInvocation* next_invocation) { 965 void AppendInvocationSpecificSwitches(SwReporterInvocation* next_invocation) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 base::Version version_; 1005 base::Version version_;
1003 scoped_refptr<base::TaskRunner> main_thread_task_runner_; 1006 scoped_refptr<base::TaskRunner> main_thread_task_runner_;
1004 scoped_refptr<base::TaskRunner> blocking_task_runner_; 1007 scoped_refptr<base::TaskRunner> blocking_task_runner_;
1005 1008
1006 // This value is used to identify how long to wait before starting a new run 1009 // 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 1010 // 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 1011 // 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. 1012 // should be run before adding the global error to the Chrome menu.
1010 int days_between_reporter_runs_ = kDaysBetweenSuccessfulSwReporterRuns; 1013 int days_between_reporter_runs_ = kDaysBetweenSuccessfulSwReporterRuns;
1011 1014
1015 // This will be true if the current queue of invocations started at a time
1016 // when logs should be uploaded.
1017 bool in_logs_upload_period_ = false;
1018
1012 // A single leaky instance. 1019 // A single leaky instance.
1013 static ReporterRunner* instance_; 1020 static ReporterRunner* instance_;
1014 1021
1015 DISALLOW_COPY_AND_ASSIGN(ReporterRunner); 1022 DISALLOW_COPY_AND_ASSIGN(ReporterRunner);
1016 }; 1023 };
1017 1024
1018 ReporterRunner* ReporterRunner::instance_ = nullptr; 1025 ReporterRunner* ReporterRunner::instance_ = nullptr;
1019 1026
1020 SwReporterInvocation::SwReporterInvocation() 1027 SwReporterInvocation::SwReporterInvocation()
1021 : command_line(base::CommandLine::NO_PROGRAM) {} 1028 : command_line(base::CommandLine::NO_PROGRAM) {}
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 return srt_cleaner_key.Open(HKEY_CURRENT_USER, cleaner_key_path.c_str(), 1080 return srt_cleaner_key.Open(HKEY_CURRENT_USER, cleaner_key_path.c_str(),
1074 KEY_QUERY_VALUE) == ERROR_SUCCESS && 1081 KEY_QUERY_VALUE) == ERROR_SUCCESS &&
1075 srt_cleaner_key.GetValueCount() > 0; 1082 srt_cleaner_key.GetValueCount() > 0;
1076 } 1083 }
1077 1084
1078 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { 1085 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) {
1079 g_testing_delegate_ = delegate; 1086 g_testing_delegate_ = delegate;
1080 } 1087 }
1081 1088
1082 } // namespace safe_browsing 1089 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/srt_fetcher_browsertest_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698