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

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: First round of reviews 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 in 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 in the UI thread before the reporter process launch is posted
grt (UTC plus 2) 2017/03/31 11:32:33 nit: "on" a thread rather than "in" (prepositions,
ftirelo 2017/03/31 16:37:37 Done :-) (I'm afraid that now I don't know how to
578 // (method ScheduleNextInvocation);
579 // - deleted in 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 the reporter process is
Joe Mason 2017/03/31 08:06:23 Looks like there are some missing words in this se
ftirelo 2017/03/31 16:37:37 Done.
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 in
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 delete the instance of ChromePromptImpl in the IO thread.
605 void ReleaseChromePromptImpl();
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 in the IO thread.
616 void CreateChromePromptImpl(mojo::ScopedMessagePipeHandle my_pipe);
617
618 // The invocation for the current reporter process.
619 SwReporterInvocation invocation_;
620
621 // Implementation of the ChromePrompt service to be used by the current
622 // reporter process.
grt (UTC plus 2) 2017/03/31 11:32:33 please document that this member may only be acces
ftirelo 2017/03/31 16:37:37 Done.
623 std::unique_ptr<ChromePromptImpl> chrome_prompt_impl_;
624 };
625
626 int SwReporterProcess::LaunchAndWaitForExitOnBackgroundThread() {
561 if (g_testing_delegate_) 627 if (g_testing_delegate_)
562 return g_testing_delegate_->LaunchReporter(invocation); 628 return g_testing_delegate_->LaunchReporter(invocation_);
629
563 base::Process reporter_process = 630 base::Process reporter_process =
564 base::LaunchProcess(invocation.command_line, base::LaunchOptions()); 631 base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature)
632 ? LaunchConnectedReporterProcess()
633 : base::LaunchProcess(invocation_.command_line,
634 base::LaunchOptions());
635
565 // This exit code is used to identify that a reporter run didn't happen, so 636 // 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. 637 // the result should be ignored and a rerun scheduled for the usual delay.
567 int exit_code = kReporterFailureExitCode; 638 int exit_code = kReporterFailureExitCode;
568 UMAHistogramReporter uma(invocation.suffix); 639 UMAHistogramReporter uma(invocation_.suffix);
569 if (reporter_process.IsValid()) { 640 if (reporter_process.IsValid()) {
570 uma.RecordReporterStep(SW_REPORTER_START_EXECUTION); 641 uma.RecordReporterStep(SW_REPORTER_START_EXECUTION);
571 bool success = reporter_process.WaitForExit(&exit_code); 642 bool success = reporter_process.WaitForExit(&exit_code);
572 DCHECK(success); 643 DCHECK(success);
573 } else { 644 } else {
574 uma.RecordReporterStep(SW_REPORTER_FAILED_TO_START); 645 uma.RecordReporterStep(SW_REPORTER_FAILED_TO_START);
575 } 646 }
576 return exit_code; 647 return exit_code;
577 } 648 }
578 649
650 base::Process SwReporterProcess::LaunchConnectedReporterProcess() {
651 DCHECK(base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature));
652
653 mojo::edk::PendingProcessConnection pending_process_connection;
654 std::string mojo_pipe_token;
655 mojo::ScopedMessagePipeHandle mojo_pipe =
656 pending_process_connection.CreateMessagePipe(&mojo_pipe_token);
657 invocation_.command_line.AppendSwitchASCII(kChromeMojoPipeTokenSwitch,
658 mojo_pipe_token);
659
660 mojo::edk::PlatformChannelPair channel;
661 base::HandlesToInheritVector handles_to_inherit;
662 channel.PrepareToPassClientHandleToChildProcess(&invocation_.command_line,
663 &handles_to_inherit);
664
665 base::LaunchOptions launch_options;
666 launch_options.handles_to_inherit = &handles_to_inherit;
667 base::Process reporter_process =
668 base::LaunchProcess(invocation_.command_line, launch_options);
669
670 if (!reporter_process.IsValid())
671 return reporter_process;
672
673 pending_process_connection.Connect(
674 reporter_process.Handle(),
675 mojo::edk::ConnectionParams(channel.PassServerHandle()));
676
677 // ChromePromptImpl tasks will need to run in the IO thread. There is no
678 // need to synchronize its creation, since the client end will wait for this
679 // initialization to be done before sending requests.
680 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)
681 ->PostTask(FROM_HERE,
682 base::Bind(&SwReporterProcess::CreateChromePromptImpl, this,
683 base::Passed(&mojo_pipe)));
684
685 return reporter_process;
686 }
687
688 void SwReporterProcess::CreateChromePromptImpl(
689 mojo::ScopedMessagePipeHandle mojo_pipe) {
690 DCHECK_CURRENTLY_ON(BrowserThread::IO);
691
692 chrome_cleaner::mojom::ChromePromptRequest chrome_prompt_request;
693 chrome_prompt_request.Bind(std::move(mojo_pipe));
694 chrome_prompt_impl_ =
695 base::MakeUnique<ChromePromptImpl>(std::move(chrome_prompt_request));
696 }
697
698 void SwReporterProcess::ReleaseChromePromptImpl() {
grt (UTC plus 2) 2017/03/31 11:32:33 nit: method definitions should be in the same orde
ftirelo 2017/03/31 16:37:37 It's private now, so keeping it here since it was
699 DCHECK_CURRENTLY_ON(BrowserThread::IO);
700 DCHECK(base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature));
701
702 chrome_prompt_impl_.release();
703 }
704
579 } // namespace 705 } // namespace
580 706
581 void DisplaySRTPromptForTesting(const base::FilePath& download_path) { 707 void DisplaySRTPromptForTesting(const base::FilePath& download_path) {
582 DisplaySRTPrompt(download_path); 708 DisplaySRTPrompt(download_path);
583 } 709 }
584 710
585 // Class that will attempt to download the SRT, showing the SRT notification 711 // Class that will attempt to download the SRT, showing the SRT notification
586 // bubble when the download operation is complete. Instances of SRTFetcher own 712 // bubble when the download operation is complete. Instances of SRTFetcher own
587 // themselves, they will self-delete on completion of the network request when 713 // themselves, they will self-delete on completion of the network request when
588 // OnURLFetchComplete is called. 714 // OnURLFetchComplete is called.
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 void ScheduleNextInvocation() { 890 void ScheduleNextInvocation() {
765 DCHECK(!current_invocations_.empty()); 891 DCHECK(!current_invocations_.empty());
766 auto next_invocation = current_invocations_.front(); 892 auto next_invocation = current_invocations_.front();
767 current_invocations_.pop(); 893 current_invocations_.pop();
768 894
769 AppendInvocationSpecificSwitches(&next_invocation); 895 AppendInvocationSpecificSwitches(&next_invocation);
770 896
771 base::TaskRunner* task_runner = 897 base::TaskRunner* task_runner =
772 g_testing_delegate_ ? g_testing_delegate_->BlockingTaskRunner() 898 g_testing_delegate_ ? g_testing_delegate_->BlockingTaskRunner()
773 : blocking_task_runner_.get(); 899 : blocking_task_runner_.get();
774 base::PostTaskAndReplyWithResult( 900 scoped_refptr<SwReporterProcess> sw_reporter_process =
grt (UTC plus 2) 2017/03/31 11:32:33 nit: this can become "auto sw_reporter_process" si
ftirelo 2017/03/31 16:37:37 Done.
775 task_runner, FROM_HERE, 901 make_scoped_refptr(new SwReporterProcess(next_invocation));
776 base::Bind(&LaunchAndWaitForExit, next_invocation), 902 auto launch_and_wait =
903 base::Bind(&SwReporterProcess::LaunchAndWaitForExitOnBackgroundThread,
904 sw_reporter_process);
905 auto reporter_done =
777 base::Bind(&ReporterRunner::ReporterDone, base::Unretained(this), Now(), 906 base::Bind(&ReporterRunner::ReporterDone, base::Unretained(this), Now(),
778 version_, next_invocation)); 907 version_, std::move(sw_reporter_process));
908 base::PostTaskAndReplyWithResult(task_runner, FROM_HERE,
909 std::move(launch_and_wait),
910 std::move(reporter_done));
779 } 911 }
780 912
781 // This method is called on the UI thread when an invocation of the reporter 913 // 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 914 // has completed. This is run as a task posted from an interruptible worker
783 // thread so should be resilient to unexpected shutdown. 915 // thread so should be resilient to unexpected shutdown.
784 void ReporterDone(const base::Time& reporter_start_time, 916 void ReporterDone(const base::Time& reporter_start_time,
785 const base::Version& version, 917 const base::Version& version,
786 const SwReporterInvocation& finished_invocation, 918 scoped_refptr<SwReporterProcess> sw_reporter_process,
787 int exit_code) { 919 int exit_code) {
788 DCHECK_CURRENTLY_ON(BrowserThread::UI); 920 DCHECK_CURRENTLY_ON(BrowserThread::UI);
789 921
922 if (base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature)) {
grt (UTC plus 2) 2017/03/31 11:32:33 nit: putting this conditional out here seems to be
ftirelo 2017/03/31 16:37:37 Done.
923 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)
924 ->PostTask(FROM_HERE,
925 base::Bind(&SwReporterProcess::ReleaseChromePromptImpl,
926 sw_reporter_process));
927 }
928
790 base::Time now = Now(); 929 base::Time now = Now();
791 base::TimeDelta reporter_running_time = now - reporter_start_time; 930 base::TimeDelta reporter_running_time = now - reporter_start_time;
792 931
793 // Don't continue the current queue of reporters if one failed to launch. 932 // Don't continue the current queue of reporters if one failed to launch.
794 if (exit_code == kReporterFailureExitCode) 933 if (exit_code == kReporterFailureExitCode)
795 current_invocations_ = SwReporterQueue(); 934 current_invocations_ = SwReporterQueue();
796 935
797 // As soon as we're not running this queue, schedule the next overall queue 936 // 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 937 // 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 938 // retrying earlier, risking running too often if it always fails, since
800 // not many users fail here.) 939 // not many users fail here.)
801 if (current_invocations_.empty()) { 940 if (current_invocations_.empty()) {
802 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 941 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
803 FROM_HERE, 942 FROM_HERE,
804 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), 943 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)),
805 base::TimeDelta::FromDays(days_between_reporter_runs_)); 944 base::TimeDelta::FromDays(days_between_reporter_runs_));
806 } else { 945 } else {
807 ScheduleNextInvocation(); 946 ScheduleNextInvocation();
808 } 947 }
809 948
810 // If the reporter failed to launch, do not process the results. (The exit 949 // 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 950 // code itself doesn't need to be logged in this case because
812 // SW_REPORTER_FAILED_TO_START is logged in |LaunchAndWaitForExit|.) 951 // SW_REPORTER_FAILED_TO_START is logged in
952 // |LaunchAndWaitForExitOnBackgroundThread|.)
813 if (exit_code == kReporterFailureExitCode) 953 if (exit_code == kReporterFailureExitCode)
814 return; 954 return;
815 955
956 auto finished_invocation = sw_reporter_process->invocation();
816 UMAHistogramReporter uma(finished_invocation.suffix); 957 UMAHistogramReporter uma(finished_invocation.suffix);
817 uma.ReportVersion(version); 958 uma.ReportVersion(version);
818 uma.ReportExitCode(exit_code); 959 uma.ReportExitCode(exit_code);
819 uma.ReportEngineErrorCode(); 960 uma.ReportEngineErrorCode();
820 uma.ReportFoundUwS(); 961 uma.ReportFoundUwS();
821 962
822 PrefService* local_state = g_browser_process->local_state(); 963 PrefService* local_state = g_browser_process->local_state();
823 if (local_state) { 964 if (local_state) {
824 if (finished_invocation.BehaviourIsSupported( 965 if (finished_invocation.BehaviourIsSupported(
825 SwReporterInvocation::BEHAVIOUR_LOG_EXIT_CODE_TO_PREFS)) { 966 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); 1029 RecordReporterStepHistogram(SW_REPORTER_RAN_DAILY);
889 } else { 1030 } else {
890 days_between_reporter_runs_ = kDaysBetweenSuccessfulSwReporterRuns; 1031 days_between_reporter_runs_ = kDaysBetweenSuccessfulSwReporterRuns;
891 } 1032 }
892 const base::Time now = Now(); 1033 const base::Time now = Now();
893 const base::Time last_time_triggered = base::Time::FromInternalValue( 1034 const base::Time last_time_triggered = base::Time::FromInternalValue(
894 local_state->GetInt64(prefs::kSwReporterLastTimeTriggered)); 1035 local_state->GetInt64(prefs::kSwReporterLastTimeTriggered));
895 const base::Time next_trigger( 1036 const base::Time next_trigger(
896 last_time_triggered + 1037 last_time_triggered +
897 base::TimeDelta::FromDays(days_between_reporter_runs_)); 1038 base::TimeDelta::FromDays(days_between_reporter_runs_));
898 if (!pending_invocations_.empty() && 1039 if (kDebugOnlyForceReporterRun ||
899 (next_trigger <= now || 1040 (!pending_invocations_.empty() &&
900 // Also make sure the kSwReporterLastTimeTriggered value is not set in 1041 (next_trigger <= now ||
901 // the future. 1042 // Also make sure the kSwReporterLastTimeTriggered value is not set in
902 last_time_triggered > now)) { 1043 // the future.
1044 last_time_triggered > now))) {
903 const base::Time last_time_sent_logs = base::Time::FromInternalValue( 1045 const base::Time last_time_sent_logs = base::Time::FromInternalValue(
904 local_state->GetInt64(prefs::kSwReporterLastTimeSentReport)); 1046 local_state->GetInt64(prefs::kSwReporterLastTimeSentReport));
905 const base::Time next_time_send_logs = 1047 const base::Time next_time_send_logs =
906 last_time_sent_logs + 1048 last_time_sent_logs +
907 base::TimeDelta::FromDays(kDaysBetweenReporterLogsSent); 1049 base::TimeDelta::FromDays(kDaysBetweenReporterLogsSent);
908 // Send the logs for this whole queue of invocations if the last send is 1050 // 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 1051 // in the future or if logs have been sent at least
910 // |kSwReporterLastTimeSentReport| days ago. The former is intended as a 1052 // |kSwReporterLastTimeSentReport| days ago. The former is intended as a
911 // measure for failure recovery, in case the time in local state is 1053 // measure for failure recovery, in case the time in local state is
912 // incorrectly set to the future. 1054 // 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. 1128 // The queue of invocations that are currently running.
987 SwReporterQueue current_invocations_; 1129 SwReporterQueue current_invocations_;
988 1130
989 // The invocations to run next time the SwReporter is run. 1131 // The invocations to run next time the SwReporter is run.
990 SwReporterQueue pending_invocations_; 1132 SwReporterQueue pending_invocations_;
991 1133
992 base::Version version_; 1134 base::Version version_;
993 1135
994 scoped_refptr<base::TaskRunner> blocking_task_runner_ = 1136 scoped_refptr<base::TaskRunner> blocking_task_runner_ =
995 base::CreateTaskRunnerWithTraits( 1137 base::CreateTaskRunnerWithTraits(
996 // LaunchAndWaitForExit() creates (MayBlock()) and joins 1138 // LaunchAndWaitForExitOnBackgroundThread() creates (MayBlock()) and
997 // (WithBaseSyncPrimitives()) a process. 1139 // joins (WithBaseSyncPrimitives()) a process.
998 base::TaskTraits() 1140 base::TaskTraits()
999 .WithShutdownBehavior( 1141 .WithShutdownBehavior(
1000 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN) 1142 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN)
1001 .WithPriority(base::TaskPriority::BACKGROUND) 1143 .WithPriority(base::TaskPriority::BACKGROUND)
1002 .MayBlock() 1144 .MayBlock()
1003 .WithBaseSyncPrimitives()); 1145 .WithBaseSyncPrimitives());
1004 1146
1005 // This value is used to identify how long to wait before starting a new run 1147 // 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 1148 // 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 1149 // 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(), 1214 return srt_cleaner_key.Open(HKEY_CURRENT_USER, cleaner_key_path.c_str(),
1073 KEY_QUERY_VALUE) == ERROR_SUCCESS && 1215 KEY_QUERY_VALUE) == ERROR_SUCCESS &&
1074 srt_cleaner_key.GetValueCount() > 0; 1216 srt_cleaner_key.GetValueCount() > 0;
1075 } 1217 }
1076 1218
1077 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { 1219 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) {
1078 g_testing_delegate_ = delegate; 1220 g_testing_delegate_ = delegate;
1079 } 1221 }
1080 1222
1081 } // namespace safe_browsing 1223 } // 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