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

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: Fixes compilation error 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
« no previous file with comments | « chrome/browser/safe_browsing/srt_fetcher_win.h ('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 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/src/chrome_cleaner/public/interfaces/chrome_prompt.mo jom.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
68 const wchar_t kCleanerSubKey[] = L"Cleaner"; 74 const wchar_t kCleanerSubKey[] = L"Cleaner";
69 75
70 const wchar_t kEndTimeValueName[] = L"EndTime"; 76 const wchar_t kEndTimeValueName[] = L"EndTime";
71 const wchar_t kStartTimeValueName[] = L"StartTime"; 77 const wchar_t kStartTimeValueName[] = L"StartTime";
72 78
79 const base::Feature kInBrowserCleanerUIFeature{
80 "InBrowserCleanerUI", base::FEATURE_DISABLED_BY_DEFAULT};
81
73 namespace { 82 namespace {
74 83
75 // Used to send UMA information about missing start and end time registry 84 // Used to send UMA information about missing start and end time registry
76 // values for the reporter. Replicated in the histograms.xml file, so the order 85 // values for the reporter. Replicated in the histograms.xml file, so the order
77 // MUST NOT CHANGE. 86 // MUST NOT CHANGE.
78 enum SwReporterRunningTimeRegistryError { 87 enum SwReporterRunningTimeRegistryError {
79 REPORTER_RUNNING_TIME_ERROR_NO_ERROR = 0, 88 REPORTER_RUNNING_TIME_ERROR_NO_ERROR = 0,
80 REPORTER_RUNNING_TIME_ERROR_REGISTRY_KEY_INVALID = 1, 89 REPORTER_RUNNING_TIME_ERROR_REGISTRY_KEY_INVALID = 1,
81 REPORTER_RUNNING_TIME_ERROR_MISSING_START_TIME = 2, 90 REPORTER_RUNNING_TIME_ERROR_MISSING_START_TIME = 2,
82 REPORTER_RUNNING_TIME_ERROR_MISSING_END_TIME = 3, 91 REPORTER_RUNNING_TIME_ERROR_MISSING_END_TIME = 3,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 "SoftwareReporter.LogsUploadResultRegistryError"; 167 "SoftwareReporter.LogsUploadResultRegistryError";
159 const char kExitCodeMetricName[] = "SoftwareReporter.ExitCodeFromRegistry"; 168 const char kExitCodeMetricName[] = "SoftwareReporter.ExitCodeFromRegistry";
160 const char kEngineErrorCodeMetricName[] = "SoftwareReporter.EngineErrorCode"; 169 const char kEngineErrorCodeMetricName[] = "SoftwareReporter.EngineErrorCode";
161 170
162 // The max value for histogram SoftwareReporter.LogsUploadResult, which is used 171 // The max value for histogram SoftwareReporter.LogsUploadResult, which is used
163 // to send UMA information about the result of Software Reporter's attempt to 172 // 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 173 // upload logs, when logs are enabled. This value must be consistent with the
165 // SoftwareReporterLogsUploadResult enum defined in the histograms.xml file. 174 // SoftwareReporterLogsUploadResult enum defined in the histograms.xml file.
166 const int kSwReporterLogsUploadResultMax = 30; 175 const int kSwReporterLogsUploadResultMax = 30;
167 176
177 constexpr char kChromeMojoPipeTokenSwitch[] = "chrome-mojo-pipe-token";
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
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 on the IO thread and
559 // external that could be shut down beforehand. 574 // controlling its lifetime.
560 int LaunchAndWaitForExit(const SwReporterInvocation& invocation) { 575 //
576 // Expected lifecycle of a SwReporterProcess:
577 // - created on the UI thread before the reporter process launch is posted
578 // (method ScheduleNextInvocation);
579 // - deleted on the UI thread once ReporterDone() finishes (the method is
580 // called after the reporter process exits).
581 //
582 // If feature InBrowserCleanerUI feature is enabled, the following tasks will
583 // be posted in sequence to the IO Thread and will retain the SwReporterProcess
584 // object:
585 // - creation of a ChromePromptImpl object right after the reporter process is
586 // launched (that object will be responsible for handling IPC requests from
587 // the reporter process);
588 // - deletion of the ChromePromptImpl object on ReporterDone().
589 // As a consequence, the SwReporterProcess object can outlive ReporterDone()
590 // and will only be deleted after the ChromePromptImpl object is released on
591 // the IO thread.
592 class SwReporterProcess : public base::RefCounted<SwReporterProcess> {
593 public:
594 explicit SwReporterProcess(const SwReporterInvocation& invocation)
595 : invocation_(invocation) {}
596 ~SwReporterProcess() = default;
597
598 // This function is called from a worker thread to launch the SwReporter and
599 // wait for termination to collect its exit code. This task could be
600 // interrupted by a shutdown at any time, so it shouldn't depend on anything
601 // external that could be shut down beforehand.
602 int LaunchAndWaitForExitOnBackgroundThread();
603
604 // Schedules to release the instance of ChromePromptImpl on the IO thread.
605 void OnReporterDone();
606
607 const SwReporterInvocation& invocation() const { return invocation_; }
608
609 private:
610 // Starts a new IPC service implementing the ChromePrompt interface and
611 // launches a new reporter process that can connect to the IPC.
612 base::Process LaunchConnectedReporterProcess();
613
614 // Starts a new instance of ChromePromptImpl to receive requests from the
615 // reporter. Must be run on the IO thread.
616 void CreateChromePromptImpl(mojo::ScopedMessagePipeHandle my_pipe);
617
618 // Releases the instance of ChromePromptImpl. Must be run on the IO thread.
619 void ReleaseChromePromptImpl();
620
621 // The invocation for the current reporter process.
622 SwReporterInvocation invocation_;
623
624 // Implementation of the ChromePrompt service to be used by the current
625 // reporter process. Can only be accessed on the IO thread.
626 std::unique_ptr<ChromePromptImpl> chrome_prompt_impl_;
627 };
628
629 int SwReporterProcess::LaunchAndWaitForExitOnBackgroundThread() {
561 if (g_testing_delegate_) 630 if (g_testing_delegate_)
562 return g_testing_delegate_->LaunchReporter(invocation); 631 return g_testing_delegate_->LaunchReporter(invocation_);
632
563 base::Process reporter_process = 633 base::Process reporter_process =
564 base::LaunchProcess(invocation.command_line, base::LaunchOptions()); 634 base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature)
635 ? LaunchConnectedReporterProcess()
636 : base::LaunchProcess(invocation_.command_line,
637 base::LaunchOptions());
638
565 // This exit code is used to identify that a reporter run didn't happen, so 639 // 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. 640 // the result should be ignored and a rerun scheduled for the usual delay.
567 int exit_code = kReporterFailureExitCode; 641 int exit_code = kReporterFailureExitCode;
568 UMAHistogramReporter uma(invocation.suffix); 642 UMAHistogramReporter uma(invocation_.suffix);
569 if (reporter_process.IsValid()) { 643 if (reporter_process.IsValid()) {
570 uma.RecordReporterStep(SW_REPORTER_START_EXECUTION); 644 uma.RecordReporterStep(SW_REPORTER_START_EXECUTION);
571 bool success = reporter_process.WaitForExit(&exit_code); 645 bool success = reporter_process.WaitForExit(&exit_code);
572 DCHECK(success); 646 DCHECK(success);
573 } else { 647 } else {
574 uma.RecordReporterStep(SW_REPORTER_FAILED_TO_START); 648 uma.RecordReporterStep(SW_REPORTER_FAILED_TO_START);
575 } 649 }
576 return exit_code; 650 return exit_code;
577 } 651 }
578 652
653 void SwReporterProcess::OnReporterDone() {
654 if (base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature)) {
655 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)
656 ->PostTask(FROM_HERE,
657 base::Bind(&SwReporterProcess::ReleaseChromePromptImpl,
658 make_scoped_refptr(this)));
659 }
660 }
661
662 base::Process SwReporterProcess::LaunchConnectedReporterProcess() {
663 DCHECK(base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature));
664
665 mojo::edk::PendingProcessConnection pending_process_connection;
666 std::string mojo_pipe_token;
667 mojo::ScopedMessagePipeHandle mojo_pipe =
668 pending_process_connection.CreateMessagePipe(&mojo_pipe_token);
669 invocation_.command_line.AppendSwitchASCII(kChromeMojoPipeTokenSwitch,
670 mojo_pipe_token);
671
672 mojo::edk::PlatformChannelPair channel;
673 base::HandlesToInheritVector handles_to_inherit;
674 channel.PrepareToPassClientHandleToChildProcess(&invocation_.command_line,
675 &handles_to_inherit);
676
677 base::LaunchOptions launch_options;
678 launch_options.handles_to_inherit = &handles_to_inherit;
679 base::Process reporter_process =
680 base::LaunchProcess(invocation_.command_line, launch_options);
681
682 if (!reporter_process.IsValid())
683 return reporter_process;
684
685 pending_process_connection.Connect(
686 reporter_process.Handle(),
687 mojo::edk::ConnectionParams(channel.PassServerHandle()));
688
689 // ChromePromptImpl tasks will need to run on the IO thread. There is no
690 // need to synchronize its creation, since the client end will wait for this
691 // initialization to be done before sending requests.
692 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)
693 ->PostTask(FROM_HERE,
694 base::Bind(&SwReporterProcess::CreateChromePromptImpl, this,
695 base::Passed(&mojo_pipe)));
696
697 return reporter_process;
698 }
699
700 void SwReporterProcess::CreateChromePromptImpl(
701 mojo::ScopedMessagePipeHandle mojo_pipe) {
702 DCHECK_CURRENTLY_ON(BrowserThread::IO);
703 DCHECK(base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature));
704
705 chrome_cleaner::mojom::ChromePromptRequest chrome_prompt_request;
706 chrome_prompt_request.Bind(std::move(mojo_pipe));
707 chrome_prompt_impl_ =
708 base::MakeUnique<ChromePromptImpl>(std::move(chrome_prompt_request));
709 }
710
711 void SwReporterProcess::ReleaseChromePromptImpl() {
712 DCHECK_CURRENTLY_ON(BrowserThread::IO);
713 DCHECK(base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature));
714
715 chrome_prompt_impl_.release();
716 }
717
579 } // namespace 718 } // namespace
580 719
581 void DisplaySRTPromptForTesting(const base::FilePath& download_path) { 720 void DisplaySRTPromptForTesting(const base::FilePath& download_path) {
582 DisplaySRTPrompt(download_path); 721 DisplaySRTPrompt(download_path);
583 } 722 }
584 723
585 // Class that will attempt to download the SRT, showing the SRT notification 724 // Class that will attempt to download the SRT, showing the SRT notification
586 // bubble when the download operation is complete. Instances of SRTFetcher own 725 // bubble when the download operation is complete. Instances of SRTFetcher own
587 // themselves, they will self-delete on completion of the network request when 726 // themselves, they will self-delete on completion of the network request when
588 // OnURLFetchComplete is called. 727 // OnURLFetchComplete is called.
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 void ScheduleNextInvocation() { 903 void ScheduleNextInvocation() {
765 DCHECK(!current_invocations_.empty()); 904 DCHECK(!current_invocations_.empty());
766 auto next_invocation = current_invocations_.front(); 905 auto next_invocation = current_invocations_.front();
767 current_invocations_.pop(); 906 current_invocations_.pop();
768 907
769 AppendInvocationSpecificSwitches(&next_invocation); 908 AppendInvocationSpecificSwitches(&next_invocation);
770 909
771 base::TaskRunner* task_runner = 910 base::TaskRunner* task_runner =
772 g_testing_delegate_ ? g_testing_delegate_->BlockingTaskRunner() 911 g_testing_delegate_ ? g_testing_delegate_->BlockingTaskRunner()
773 : blocking_task_runner_.get(); 912 : blocking_task_runner_.get();
774 base::PostTaskAndReplyWithResult( 913 auto sw_reporter_process =
775 task_runner, FROM_HERE, 914 make_scoped_refptr(new SwReporterProcess(next_invocation));
776 base::Bind(&LaunchAndWaitForExit, next_invocation), 915 auto launch_and_wait =
916 base::Bind(&SwReporterProcess::LaunchAndWaitForExitOnBackgroundThread,
917 sw_reporter_process);
918 auto reporter_done =
777 base::Bind(&ReporterRunner::ReporterDone, base::Unretained(this), Now(), 919 base::Bind(&ReporterRunner::ReporterDone, base::Unretained(this), Now(),
778 version_, next_invocation)); 920 version_, std::move(sw_reporter_process));
921 base::PostTaskAndReplyWithResult(task_runner, FROM_HERE,
922 std::move(launch_and_wait),
923 std::move(reporter_done));
779 } 924 }
780 925
781 // This method is called on the UI thread when an invocation of the reporter 926 // 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 927 // has completed. This is run as a task posted from an interruptible worker
783 // thread so should be resilient to unexpected shutdown. 928 // thread so should be resilient to unexpected shutdown.
784 void ReporterDone(const base::Time& reporter_start_time, 929 void ReporterDone(const base::Time& reporter_start_time,
785 const base::Version& version, 930 const base::Version& version,
786 const SwReporterInvocation& finished_invocation, 931 scoped_refptr<SwReporterProcess> sw_reporter_process,
787 int exit_code) { 932 int exit_code) {
788 DCHECK_CURRENTLY_ON(BrowserThread::UI); 933 DCHECK_CURRENTLY_ON(BrowserThread::UI);
789 934
935 sw_reporter_process->OnReporterDone();
936
790 base::Time now = Now(); 937 base::Time now = Now();
791 base::TimeDelta reporter_running_time = now - reporter_start_time; 938 base::TimeDelta reporter_running_time = now - reporter_start_time;
792 939
793 // Don't continue the current queue of reporters if one failed to launch. 940 // Don't continue the current queue of reporters if one failed to launch.
794 if (exit_code == kReporterFailureExitCode) 941 if (exit_code == kReporterFailureExitCode)
795 current_invocations_ = SwReporterQueue(); 942 current_invocations_ = SwReporterQueue();
796 943
797 // As soon as we're not running this queue, schedule the next overall queue 944 // 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 945 // 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 946 // retrying earlier, risking running too often if it always fails, since
800 // not many users fail here.) 947 // not many users fail here.)
801 if (current_invocations_.empty()) { 948 if (current_invocations_.empty()) {
802 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 949 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
803 FROM_HERE, 950 FROM_HERE,
804 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), 951 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)),
805 base::TimeDelta::FromDays(days_between_reporter_runs_)); 952 base::TimeDelta::FromDays(days_between_reporter_runs_));
806 } else { 953 } else {
807 ScheduleNextInvocation(); 954 ScheduleNextInvocation();
808 } 955 }
809 956
810 // If the reporter failed to launch, do not process the results. (The exit 957 // 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 958 // code itself doesn't need to be logged in this case because
812 // SW_REPORTER_FAILED_TO_START is logged in |LaunchAndWaitForExit|.) 959 // SW_REPORTER_FAILED_TO_START is logged in
960 // |LaunchAndWaitForExitOnBackgroundThread|.)
813 if (exit_code == kReporterFailureExitCode) 961 if (exit_code == kReporterFailureExitCode)
814 return; 962 return;
815 963
964 auto finished_invocation = sw_reporter_process->invocation();
grt (UTC plus 2) 2017/03/31 21:27:28 nit: "const auto&"
ftirelo 2017/04/06 15:29:25 Done.
816 UMAHistogramReporter uma(finished_invocation.suffix); 965 UMAHistogramReporter uma(finished_invocation.suffix);
817 uma.ReportVersion(version); 966 uma.ReportVersion(version);
818 uma.ReportExitCode(exit_code); 967 uma.ReportExitCode(exit_code);
819 uma.ReportEngineErrorCode(); 968 uma.ReportEngineErrorCode();
820 uma.ReportFoundUwS(); 969 uma.ReportFoundUwS();
821 970
822 PrefService* local_state = g_browser_process->local_state(); 971 PrefService* local_state = g_browser_process->local_state();
823 if (local_state) { 972 if (local_state) {
824 if (finished_invocation.BehaviourIsSupported( 973 if (finished_invocation.BehaviourIsSupported(
825 SwReporterInvocation::BEHAVIOUR_LOG_EXIT_CODE_TO_PREFS)) { 974 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); 1037 RecordReporterStepHistogram(SW_REPORTER_RAN_DAILY);
889 } else { 1038 } else {
890 days_between_reporter_runs_ = kDaysBetweenSuccessfulSwReporterRuns; 1039 days_between_reporter_runs_ = kDaysBetweenSuccessfulSwReporterRuns;
891 } 1040 }
892 const base::Time now = Now(); 1041 const base::Time now = Now();
893 const base::Time last_time_triggered = base::Time::FromInternalValue( 1042 const base::Time last_time_triggered = base::Time::FromInternalValue(
894 local_state->GetInt64(prefs::kSwReporterLastTimeTriggered)); 1043 local_state->GetInt64(prefs::kSwReporterLastTimeTriggered));
895 const base::Time next_trigger( 1044 const base::Time next_trigger(
896 last_time_triggered + 1045 last_time_triggered +
897 base::TimeDelta::FromDays(days_between_reporter_runs_)); 1046 base::TimeDelta::FromDays(days_between_reporter_runs_));
898 if (!pending_invocations_.empty() && 1047 if (kDebugOnlyForceReporterRun ||
899 (next_trigger <= now || 1048 (!pending_invocations_.empty() &&
900 // Also make sure the kSwReporterLastTimeTriggered value is not set in 1049 (next_trigger <= now ||
901 // the future. 1050 // Also make sure the kSwReporterLastTimeTriggered value is not set in
902 last_time_triggered > now)) { 1051 // the future.
1052 last_time_triggered > now))) {
903 const base::Time last_time_sent_logs = base::Time::FromInternalValue( 1053 const base::Time last_time_sent_logs = base::Time::FromInternalValue(
904 local_state->GetInt64(prefs::kSwReporterLastTimeSentReport)); 1054 local_state->GetInt64(prefs::kSwReporterLastTimeSentReport));
905 const base::Time next_time_send_logs = 1055 const base::Time next_time_send_logs =
906 last_time_sent_logs + 1056 last_time_sent_logs +
907 base::TimeDelta::FromDays(kDaysBetweenReporterLogsSent); 1057 base::TimeDelta::FromDays(kDaysBetweenReporterLogsSent);
908 // Send the logs for this whole queue of invocations if the last send is 1058 // 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 1059 // in the future or if logs have been sent at least
910 // |kSwReporterLastTimeSentReport| days ago. The former is intended as a 1060 // |kSwReporterLastTimeSentReport| days ago. The former is intended as a
911 // measure for failure recovery, in case the time in local state is 1061 // measure for failure recovery, in case the time in local state is
912 // incorrectly set to the future. 1062 // incorrectly set to the future.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 // The queue of invocations that are currently running. 1136 // The queue of invocations that are currently running.
987 SwReporterQueue current_invocations_; 1137 SwReporterQueue current_invocations_;
988 1138
989 // The invocations to run next time the SwReporter is run. 1139 // The invocations to run next time the SwReporter is run.
990 SwReporterQueue pending_invocations_; 1140 SwReporterQueue pending_invocations_;
991 1141
992 base::Version version_; 1142 base::Version version_;
993 1143
994 scoped_refptr<base::TaskRunner> blocking_task_runner_ = 1144 scoped_refptr<base::TaskRunner> blocking_task_runner_ =
995 base::CreateTaskRunnerWithTraits( 1145 base::CreateTaskRunnerWithTraits(
996 // LaunchAndWaitForExit() creates (MayBlock()) and joins 1146 // LaunchAndWaitForExitOnBackgroundThread() creates (MayBlock()) and
997 // (WithBaseSyncPrimitives()) a process. 1147 // joins (WithBaseSyncPrimitives()) a process.
998 base::TaskTraits() 1148 base::TaskTraits()
999 .WithShutdownBehavior( 1149 .WithShutdownBehavior(
1000 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) 1150 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
1001 .WithPriority(base::TaskPriority::BACKGROUND) 1151 .WithPriority(base::TaskPriority::BACKGROUND)
1002 .MayBlock() 1152 .MayBlock()
1003 .WithBaseSyncPrimitives()); 1153 .WithBaseSyncPrimitives());
1004 1154
1005 // This value is used to identify how long to wait before starting a new run 1155 // This value is used to identify how long to wait before starting a new run
1006 // of the reporter queue. It's initialized with the default value and may be 1156 // of the reporter queue. It's initialized with the default value and may be
1007 // changed to a different value when a prompt is pending and the reporter 1157 // changed to a different value when a prompt is pending and the reporter
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 return srt_cleaner_key.Open(HKEY_CURRENT_USER, cleaner_key_path.c_str(), 1222 return srt_cleaner_key.Open(HKEY_CURRENT_USER, cleaner_key_path.c_str(),
1073 KEY_QUERY_VALUE) == ERROR_SUCCESS && 1223 KEY_QUERY_VALUE) == ERROR_SUCCESS &&
1074 srt_cleaner_key.GetValueCount() > 0; 1224 srt_cleaner_key.GetValueCount() > 0;
1075 } 1225 }
1076 1226
1077 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { 1227 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) {
1078 g_testing_delegate_ = delegate; 1228 g_testing_delegate_ = delegate;
1079 } 1229 }
1080 1230
1081 } // namespace safe_browsing 1231 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/srt_fetcher_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698