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

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

Issue 2780873002: Basic IPC communication between Chrome and the SW Reporter. (Closed)
Patch Set: Rebase Created 3 years, 8 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 18 matching lines...) Expand all
29 #include "base/task_runner_util.h" 29 #include "base/task_runner_util.h"
30 #include "base/task_scheduler/post_task.h" 30 #include "base/task_scheduler/post_task.h"
31 #include "base/task_scheduler/task_traits.h" 31 #include "base/task_scheduler/task_traits.h"
32 #include "base/time/time.h" 32 #include "base/time/time.h"
33 #include "base/version.h" 33 #include "base/version.h"
34 #include "base/win/registry.h" 34 #include "base/win/registry.h"
35 #include "chrome/browser/browser_process.h" 35 #include "chrome/browser/browser_process.h"
36 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h" 36 #include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
37 #include "chrome/browser/profiles/profile.h" 37 #include "chrome/browser/profiles/profile.h"
38 #include "chrome/browser/profiles/profile_io_data.h" 38 #include "chrome/browser/profiles/profile_io_data.h"
39 #include "chrome/browser/safe_browsing/srt_chrome_prompt_impl.h"
39 #include "chrome/browser/safe_browsing/srt_client_info_win.h" 40 #include "chrome/browser/safe_browsing/srt_client_info_win.h"
40 #include "chrome/browser/safe_browsing/srt_global_error_win.h" 41 #include "chrome/browser/safe_browsing/srt_global_error_win.h"
41 #include "chrome/browser/ui/browser_finder.h" 42 #include "chrome/browser/ui/browser_finder.h"
42 #include "chrome/browser/ui/browser_list.h" 43 #include "chrome/browser/ui/browser_list.h"
43 #include "chrome/browser/ui/browser_list_observer.h" 44 #include "chrome/browser/ui/browser_list_observer.h"
44 #include "chrome/browser/ui/global_error/global_error_service.h" 45 #include "chrome/browser/ui/global_error/global_error_service.h"
45 #include "chrome/browser/ui/global_error/global_error_service_factory.h" 46 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
46 #include "chrome/common/pref_names.h" 47 #include "chrome/common/pref_names.h"
47 #include "components/component_updater/pref_names.h" 48 #include "components/component_updater/pref_names.h"
48 #include "components/data_use_measurement/core/data_use_user_data.h" 49 #include "components/data_use_measurement/core/data_use_user_data.h"
49 #include "components/prefs/pref_service.h" 50 #include "components/prefs/pref_service.h"
50 #include "components/variations/net/variations_http_headers.h" 51 #include "components/variations/net/variations_http_headers.h"
51 #include "components/version_info/version_info.h" 52 #include "components/version_info/version_info.h"
52 #include "content/public/browser/browser_thread.h" 53 #include "content/public/browser/browser_thread.h"
54 #include "mojo/edk/embedder/connection_params.h"
55 #include "mojo/edk/embedder/pending_process_connection.h"
56 #include "mojo/edk/embedder/platform_channel_pair.h"
57 #include "mojo/public/cpp/system/message_pipe.h"
53 #include "net/base/load_flags.h" 58 #include "net/base/load_flags.h"
54 #include "net/http/http_status_code.h" 59 #include "net/http/http_status_code.h"
55 #include "net/url_request/url_fetcher.h" 60 #include "net/url_request/url_fetcher.h"
56 #include "net/url_request/url_fetcher_delegate.h" 61 #include "net/url_request/url_fetcher_delegate.h"
57 #include "net/url_request/url_request_context_getter.h" 62 #include "net/url_request/url_request_context_getter.h"
63 #include "third_party/pipa/chrome_cleaner/public/interfaces/chrome_prompt.mojom. h"
58 64
59 using content::BrowserThread; 65 using content::BrowserThread;
60 66
61 namespace safe_browsing { 67 namespace safe_browsing {
62 68
63 // TODO(b/647763) Change the registry key to properly handle cases when the user 69 // TODO(b/647763) Change the registry key to properly handle cases when the user
64 // runs Google Chrome stable alongside Google Chrome SxS. 70 // runs Google Chrome stable alongside Google Chrome SxS.
65 const wchar_t kSoftwareRemovalToolRegistryKey[] = 71 const wchar_t kSoftwareRemovalToolRegistryKey[] =
66 L"Software\\Google\\Software Removal Tool"; 72 L"Software\\Google\\Software Removal Tool";
67 73
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 "SoftwareReporter.LogsUploadResultRegistryError"; 164 "SoftwareReporter.LogsUploadResultRegistryError";
159 const char kExitCodeMetricName[] = "SoftwareReporter.ExitCodeFromRegistry"; 165 const char kExitCodeMetricName[] = "SoftwareReporter.ExitCodeFromRegistry";
160 const char kEngineErrorCodeMetricName[] = "SoftwareReporter.EngineErrorCode"; 166 const char kEngineErrorCodeMetricName[] = "SoftwareReporter.EngineErrorCode";
161 167
162 // The max value for histogram SoftwareReporter.LogsUploadResult, which is used 168 // The max value for histogram SoftwareReporter.LogsUploadResult, which is used
163 // to send UMA information about the result of Software Reporter's attempt to 169 // to send UMA information about the result of Software Reporter's attempt to
164 // upload logs, when logs are enabled. This value must be consistent with the 170 // upload logs, when logs are enabled. This value must be consistent with the
165 // SoftwareReporterLogsUploadResult enum defined in the histograms.xml file. 171 // SoftwareReporterLogsUploadResult enum defined in the histograms.xml file.
166 const int kSwReporterLogsUploadResultMax = 30; 172 const int kSwReporterLogsUploadResultMax = 30;
167 173
174 const base::Feature kInBrowserCleanerUIFeature{
grt (UTC plus 2) 2017/03/29 13:01:42 constexpr
ftirelo 2017/03/30 22:13:51 This is also defined in the header file (I'll need
grt (UTC plus 2) 2017/03/31 11:32:33 can you not leave the declaration in the .h as-is
ftirelo 2017/04/06 15:29:25 If I use constexpr here and not in the header file
175 "InBrowserCleanerUI", base::FEATURE_DISABLED_BY_DEFAULT};
176
177 constexpr char kChromeMojoPipeTokenSwitch[] = "chrome-mojo-pipe-token";
grt (UTC plus 2) 2017/03/29 13:01:43 what other component uses this switch? do the two
Joe Mason 2017/03/29 13:31:01 The SRT, which is in a separate repo. The constan
ftirelo 2017/03/30 22:13:51 As soon as I land crrev/2782243002, I will move sh
ftirelo 2017/03/30 22:13:52 This will be landed in //components/chrome_cleaner
178
179 // DO NOT SUBMIT. This is for debugging only and will be removed before landing
180 // this CL.
181 constexpr bool kDebugOnlyForceReporterRun = true;
182
168 // Reports metrics about the software reporter via UMA (and sometimes Rappor). 183 // Reports metrics about the software reporter via UMA (and sometimes Rappor).
169 class UMAHistogramReporter { 184 class UMAHistogramReporter {
170 public: 185 public:
171 UMAHistogramReporter() : UMAHistogramReporter(std::string()) {} 186 UMAHistogramReporter() : UMAHistogramReporter(std::string()) {}
172 187
173 explicit UMAHistogramReporter(const std::string& suffix) 188 explicit UMAHistogramReporter(const std::string& suffix)
174 : suffix_(suffix), 189 : suffix_(suffix),
175 registry_key_(suffix.empty() ? kSoftwareRemovalToolRegistryKey 190 registry_key_(suffix.empty() ? kSoftwareRemovalToolRegistryKey
176 : base::StringPrintf( 191 : base::StringPrintf(
177 L"%ls\\%ls", 192 L"%ls\\%ls",
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 if (error->GetBubbleView()) { 561 if (error->GetBubbleView()) {
547 show_bubble = false; 562 show_bubble = false;
548 break; 563 break;
549 } 564 }
550 } 565 }
551 } 566 }
552 if (show_bubble) 567 if (show_bubble)
553 global_error->ShowBubbleView(browser); 568 global_error->ShowBubbleView(browser);
554 } 569 }
555 570
556 // This function is called from a worker thread to launch the SwReporter and 571 // Class responsible for launching the reporter process and waiting for its
grt (UTC plus 2) 2017/03/29 13:01:43 maybe here is a good place to document this class'
ftirelo 2017/03/30 22:13:51 Done.
557 // wait for termination to collect its exit code. This task could be 572 // completion. If feature InBrowserCleanerUI is enabled, this object will also
558 // interrupted by a shutdown at any time, so it shouldn't depend on anything 573 // be responsible for starting the ChromePromptImpl object in the IO thread and
559 // external that could be shut down beforehand. 574 // controlling its lifetime.
560 int LaunchAndWaitForExit(const SwReporterInvocation& invocation) { 575 class SwReporterProcess : public base::RefCounted<SwReporterProcess> {
576 public:
577 explicit SwReporterProcess(const SwReporterInvocation& invocation)
578 : invocation_(invocation) {}
579 virtual ~SwReporterProcess();
grt (UTC plus 2) 2017/03/29 13:01:42 why are these methods virutal?
ftirelo 2017/03/30 22:13:51 No need to, since they are in the anonymous namesp
580
581 // This function is called from a worker thread to launch the SwReporter and
582 // wait for termination to collect its exit code. This task could be
583 // interrupted by a shutdown at any time, so it shouldn't depend on anything
584 // external that could be shut down beforehand.
585 virtual int LaunchAndWaitForExit();
586
587 virtual const SwReporterInvocation& invocation() const { return invocation_; }
588
589 private:
590 // Starts a new IPC service implementing the ChromePrompt interface and
591 // launches a new reporter process that can connect to the IPC.
592 base::Process LaunchConnectedReporterProcess();
593
594 // Starts a new instance of ChromePromptImpl to receive requests from the
595 // reporter. Must be run in the IO thread.
596 void CreateChromePromptImpl(mojo::ScopedMessagePipeHandle my_pipe);
597
598 // The invocation for the current reporter process.
599 SwReporterInvocation invocation_;
600
601 // Implementation of the ChromePrompt service to be used by the current
602 // reporter process.
603 std::unique_ptr<ChromePromptImpl> chrome_prompt_impl_;
Joe Mason 2017/03/29 13:04:31 This file could use a comment ... somewhere ... ex
ftirelo 2017/03/30 22:13:51 Done.
604 };
605
606 SwReporterProcess::~SwReporterProcess() {
607 if (!chrome_prompt_impl_)
608 return;
609
610 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)
611 ->PostTask(FROM_HERE, base::Bind(&base::DeletePointer<ChromePromptImpl>,
grt (UTC plus 2) 2017/03/29 13:01:42 nit: ->DeleteSoon(FROM_HERE, chrome_prompt_i
ftirelo 2017/03/30 22:13:51 Done.
612 chrome_prompt_impl_.release()));
613 }
614
615 int SwReporterProcess::LaunchAndWaitForExit() {
grt (UTC plus 2) 2017/03/29 13:01:42 nit: consider renaming this LaunchAndWaitForExitOn
ftirelo 2017/03/30 22:13:52 Done.
561 if (g_testing_delegate_) 616 if (g_testing_delegate_)
562 return g_testing_delegate_->LaunchReporter(invocation); 617 return g_testing_delegate_->LaunchReporter(invocation_);
618
563 base::Process reporter_process = 619 base::Process reporter_process =
564 base::LaunchProcess(invocation.command_line, base::LaunchOptions()); 620 base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature)
621 ? LaunchConnectedReporterProcess()
622 : base::LaunchProcess(invocation_.command_line,
623 base::LaunchOptions());
624
565 // This exit code is used to identify that a reporter run didn't happen, so 625 // This exit code is used to identify that a reporter run didn't happen, so
566 // the result should be ignored and a rerun scheduled for the usual delay. 626 // the result should be ignored and a rerun scheduled for the usual delay.
567 int exit_code = kReporterFailureExitCode; 627 int exit_code = kReporterFailureExitCode;
568 UMAHistogramReporter uma(invocation.suffix); 628 UMAHistogramReporter uma(invocation_.suffix);
569 if (reporter_process.IsValid()) { 629 if (reporter_process.IsValid()) {
570 uma.RecordReporterStep(SW_REPORTER_START_EXECUTION); 630 uma.RecordReporterStep(SW_REPORTER_START_EXECUTION);
571 bool success = reporter_process.WaitForExit(&exit_code); 631 bool success = reporter_process.WaitForExit(&exit_code);
572 DCHECK(success); 632 DCHECK(success);
573 } else { 633 } else {
574 uma.RecordReporterStep(SW_REPORTER_FAILED_TO_START); 634 uma.RecordReporterStep(SW_REPORTER_FAILED_TO_START);
575 } 635 }
576 return exit_code; 636 return exit_code;
577 } 637 }
578 638
639 base::Process SwReporterProcess::LaunchConnectedReporterProcess() {
640 DCHECK(base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature));
641
642 mojo::edk::PendingProcessConnection pending_process_connection;
643 std::string mojo_pipe_token;
644 mojo::ScopedMessagePipeHandle mojo_pipe =
645 pending_process_connection.CreateMessagePipe(&mojo_pipe_token);
646 invocation_.command_line.AppendSwitchASCII(kChromeMojoPipeTokenSwitch,
647 mojo_pipe_token);
648
649 mojo::edk::PlatformChannelPair channel;
650 base::HandlesToInheritVector handles_to_inherit;
651 channel.PrepareToPassClientHandleToChildProcess(&invocation_.command_line,
652 &handles_to_inherit);
653
654 base::LaunchOptions launch_options;
655 launch_options.handles_to_inherit = &handles_to_inherit;
656 base::Process reporter_process =
657 base::LaunchProcess(invocation_.command_line, launch_options);
Joe Mason 2017/03/29 13:04:31 Should return early here if !reporter_process.IsVa
ftirelo 2017/03/30 22:13:51 Done.
658
grt (UTC plus 2) 2017/03/29 13:01:42 ? if (!reporter_process.IsValid()) return re
ftirelo 2017/03/30 22:13:51 Done.
659 pending_process_connection.Connect(
660 reporter_process.Handle(),
661 mojo::edk::ConnectionParams(channel.PassServerHandle()));
662
663 // ChromePromptImpl tasks will need to run in the IO thread. There is no
664 // need to synchronize its creation, since the client end will wait for this
665 // initialization to be done before sending requests.
666 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)
667 ->PostTask(FROM_HERE,
668 base::Bind(&SwReporterProcess::CreateChromePromptImpl,
669 base::Unretained(this), base::Passed(&mojo_pipe)));
grt (UTC plus 2) 2017/03/29 13:01:42 i think this could result in walking off the end o
Joe Mason 2017/03/29 13:04:31 And there's another race condition here - what hap
ftirelo 2017/03/30 22:13:52 Please take a look at the new implementation to se
ftirelo 2017/03/30 22:13:52 Please take a look at the new implementation to se
670
671 return reporter_process;
672 }
673
674 void SwReporterProcess::CreateChromePromptImpl(
675 mojo::ScopedMessagePipeHandle mojo_pipe) {
676 DCHECK_CURRENTLY_ON(BrowserThread::IO);
677
678 chrome_cleaner::mojom::ChromePromptRequest chrome_prompt_request;
679 chrome_prompt_request.Bind(std::move(mojo_pipe));
680 chrome_prompt_impl_ =
grt (UTC plus 2) 2017/03/29 13:01:43 you have a data race here between this store (on t
ftirelo 2017/03/30 22:13:51 Please take a look at the new implementation to se
681 base::MakeUnique<ChromePromptImpl>(std::move(chrome_prompt_request));
682 }
683
579 } // namespace 684 } // namespace
580 685
581 void DisplaySRTPromptForTesting(const base::FilePath& download_path) { 686 void DisplaySRTPromptForTesting(const base::FilePath& download_path) {
582 DisplaySRTPrompt(download_path); 687 DisplaySRTPrompt(download_path);
583 } 688 }
584 689
585 // Class that will attempt to download the SRT, showing the SRT notification 690 // Class that will attempt to download the SRT, showing the SRT notification
586 // bubble when the download operation is complete. Instances of SRTFetcher own 691 // bubble when the download operation is complete. Instances of SRTFetcher own
587 // themselves, they will self-delete on completion of the network request when 692 // themselves, they will self-delete on completion of the network request when
588 // OnURLFetchComplete is called. 693 // OnURLFetchComplete is called.
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 void ScheduleNextInvocation() { 869 void ScheduleNextInvocation() {
765 DCHECK(!current_invocations_.empty()); 870 DCHECK(!current_invocations_.empty());
766 auto next_invocation = current_invocations_.front(); 871 auto next_invocation = current_invocations_.front();
767 current_invocations_.pop(); 872 current_invocations_.pop();
768 873
769 AppendInvocationSpecificSwitches(&next_invocation); 874 AppendInvocationSpecificSwitches(&next_invocation);
770 875
771 base::TaskRunner* task_runner = 876 base::TaskRunner* task_runner =
772 g_testing_delegate_ ? g_testing_delegate_->BlockingTaskRunner() 877 g_testing_delegate_ ? g_testing_delegate_->BlockingTaskRunner()
773 : blocking_task_runner_.get(); 878 : blocking_task_runner_.get();
879 scoped_refptr<SwReporterProcess> sw_reporter_process(
grt (UTC plus 2) 2017/03/29 13:01:42 please document the expected lifetime of SwReporte
Joe Mason 2017/03/29 13:31:01 With scoped_refptr we can have references to it in
ftirelo 2017/03/30 22:13:51 Done.
ftirelo 2017/03/30 22:13:52 Done.
880 new SwReporterProcess(next_invocation));
Joe Mason 2017/03/29 13:04:31 I think make_scoped_refptr is preferred here.
ftirelo 2017/03/30 22:13:52 Done.
774 base::PostTaskAndReplyWithResult( 881 base::PostTaskAndReplyWithResult(
775 task_runner, FROM_HERE, 882 task_runner, FROM_HERE,
776 base::Bind(&LaunchAndWaitForExit, next_invocation), 883 base::Bind(&SwReporterProcess::LaunchAndWaitForExit,
884 base::Unretained(sw_reporter_process.get())),
Joe Mason 2017/03/29 13:31:00 Nit: if you do keep scoped_refptr, I think it make
ftirelo 2017/03/30 22:13:51 Done.
777 base::Bind(&ReporterRunner::ReporterDone, base::Unretained(this), Now(), 885 base::Bind(&ReporterRunner::ReporterDone, base::Unretained(this), Now(),
778 version_, next_invocation)); 886 version_, sw_reporter_process));
grt (UTC plus 2) 2017/03/29 13:01:42 nit: std::move(sw_reporter_process)
ftirelo 2017/03/30 22:13:51 Saved both callbacks in auxiliary variables to enf
779 } 887 }
780 888
781 // This method is called on the UI thread when an invocation of the reporter 889 // This method is called on the UI thread when an invocation of the reporter
782 // has completed. This is run as a task posted from an interruptible worker 890 // has completed. This is run as a task posted from an interruptible worker
783 // thread so should be resilient to unexpected shutdown. 891 // thread so should be resilient to unexpected shutdown.
784 void ReporterDone(const base::Time& reporter_start_time, 892 void ReporterDone(const base::Time& reporter_start_time,
785 const base::Version& version, 893 const base::Version& version,
786 const SwReporterInvocation& finished_invocation, 894 scoped_refptr<SwReporterProcess> sw_reporter_process,
787 int exit_code) { 895 int exit_code) {
788 DCHECK_CURRENTLY_ON(BrowserThread::UI); 896 DCHECK_CURRENTLY_ON(BrowserThread::UI);
789 897
790 base::Time now = Now(); 898 base::Time now = Now();
791 base::TimeDelta reporter_running_time = now - reporter_start_time; 899 base::TimeDelta reporter_running_time = now - reporter_start_time;
792 900
793 // Don't continue the current queue of reporters if one failed to launch. 901 // Don't continue the current queue of reporters if one failed to launch.
794 if (exit_code == kReporterFailureExitCode) 902 if (exit_code == kReporterFailureExitCode)
795 current_invocations_ = SwReporterQueue(); 903 current_invocations_ = SwReporterQueue();
796 904
797 // As soon as we're not running this queue, schedule the next overall queue 905 // As soon as we're not running this queue, schedule the next overall queue
798 // run after the regular delay. (If there was a failure it's not worth 906 // run after the regular delay. (If there was a failure it's not worth
799 // retrying earlier, risking running too often if it always fails, since 907 // retrying earlier, risking running too often if it always fails, since
800 // not many users fail here.) 908 // not many users fail here.)
801 if (current_invocations_.empty()) { 909 if (current_invocations_.empty()) {
802 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 910 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
803 FROM_HERE, 911 FROM_HERE,
804 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), 912 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)),
805 base::TimeDelta::FromDays(days_between_reporter_runs_)); 913 base::TimeDelta::FromDays(days_between_reporter_runs_));
806 } else { 914 } else {
807 ScheduleNextInvocation(); 915 ScheduleNextInvocation();
808 } 916 }
809 917
810 // If the reporter failed to launch, do not process the results. (The exit 918 // If the reporter failed to launch, do not process the results. (The exit
811 // code itself doesn't need to be logged in this case because 919 // code itself doesn't need to be logged in this case because
812 // SW_REPORTER_FAILED_TO_START is logged in |LaunchAndWaitForExit|.) 920 // SW_REPORTER_FAILED_TO_START is logged in |LaunchAndWaitForExit|.)
813 if (exit_code == kReporterFailureExitCode) 921 if (exit_code == kReporterFailureExitCode)
814 return; 922 return;
815 923
924 auto finished_invocation = sw_reporter_process->invocation();
816 UMAHistogramReporter uma(finished_invocation.suffix); 925 UMAHistogramReporter uma(finished_invocation.suffix);
817 uma.ReportVersion(version); 926 uma.ReportVersion(version);
818 uma.ReportExitCode(exit_code); 927 uma.ReportExitCode(exit_code);
819 uma.ReportEngineErrorCode(); 928 uma.ReportEngineErrorCode();
820 uma.ReportFoundUwS(); 929 uma.ReportFoundUwS();
821 930
822 PrefService* local_state = g_browser_process->local_state(); 931 PrefService* local_state = g_browser_process->local_state();
823 if (local_state) { 932 if (local_state) {
824 if (finished_invocation.BehaviourIsSupported( 933 if (finished_invocation.BehaviourIsSupported(
825 SwReporterInvocation::BEHAVIOUR_LOG_EXIT_CODE_TO_PREFS)) { 934 SwReporterInvocation::BEHAVIOUR_LOG_EXIT_CODE_TO_PREFS)) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 RecordReporterStepHistogram(SW_REPORTER_RAN_DAILY); 997 RecordReporterStepHistogram(SW_REPORTER_RAN_DAILY);
889 } else { 998 } else {
890 days_between_reporter_runs_ = kDaysBetweenSuccessfulSwReporterRuns; 999 days_between_reporter_runs_ = kDaysBetweenSuccessfulSwReporterRuns;
891 } 1000 }
892 const base::Time now = Now(); 1001 const base::Time now = Now();
893 const base::Time last_time_triggered = base::Time::FromInternalValue( 1002 const base::Time last_time_triggered = base::Time::FromInternalValue(
894 local_state->GetInt64(prefs::kSwReporterLastTimeTriggered)); 1003 local_state->GetInt64(prefs::kSwReporterLastTimeTriggered));
895 const base::Time next_trigger( 1004 const base::Time next_trigger(
896 last_time_triggered + 1005 last_time_triggered +
897 base::TimeDelta::FromDays(days_between_reporter_runs_)); 1006 base::TimeDelta::FromDays(days_between_reporter_runs_));
898 if (!pending_invocations_.empty() && 1007 if (kDebugOnlyForceReporterRun ||
899 (next_trigger <= now || 1008 (!pending_invocations_.empty() &&
900 // Also make sure the kSwReporterLastTimeTriggered value is not set in 1009 (next_trigger <= now ||
901 // the future. 1010 // Also make sure the kSwReporterLastTimeTriggered value is not set in
902 last_time_triggered > now)) { 1011 // the future.
1012 last_time_triggered > now))) {
903 const base::Time last_time_sent_logs = base::Time::FromInternalValue( 1013 const base::Time last_time_sent_logs = base::Time::FromInternalValue(
904 local_state->GetInt64(prefs::kSwReporterLastTimeSentReport)); 1014 local_state->GetInt64(prefs::kSwReporterLastTimeSentReport));
905 const base::Time next_time_send_logs = 1015 const base::Time next_time_send_logs =
906 last_time_sent_logs + 1016 last_time_sent_logs +
907 base::TimeDelta::FromDays(kDaysBetweenReporterLogsSent); 1017 base::TimeDelta::FromDays(kDaysBetweenReporterLogsSent);
908 // Send the logs for this whole queue of invocations if the last send is 1018 // Send the logs for this whole queue of invocations if the last send is
909 // in the future or if logs have been sent at least 1019 // in the future or if logs have been sent at least
910 // |kSwReporterLastTimeSentReport| days ago. The former is intended as a 1020 // |kSwReporterLastTimeSentReport| days ago. The former is intended as a
911 // measure for failure recovery, in case the time in local state is 1021 // measure for failure recovery, in case the time in local state is
912 // incorrectly set to the future. 1022 // incorrectly set to the future.
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 return srt_cleaner_key.Open(HKEY_CURRENT_USER, cleaner_key_path.c_str(), 1182 return srt_cleaner_key.Open(HKEY_CURRENT_USER, cleaner_key_path.c_str(),
1073 KEY_QUERY_VALUE) == ERROR_SUCCESS && 1183 KEY_QUERY_VALUE) == ERROR_SUCCESS &&
1074 srt_cleaner_key.GetValueCount() > 0; 1184 srt_cleaner_key.GetValueCount() > 0;
1075 } 1185 }
1076 1186
1077 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { 1187 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) {
1078 g_testing_delegate_ = delegate; 1188 g_testing_delegate_ = delegate;
1079 } 1189 }
1080 1190
1081 } // namespace safe_browsing 1191 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698