OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/safe_browsing/srt_fetcher_win.h" | 5 #include "chrome/browser/safe_browsing/srt_fetcher_win.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
584 | 584 |
585 private: | 585 private: |
586 friend class base::RefCountedThreadSafe<SwReporterProcess>; | 586 friend class base::RefCountedThreadSafe<SwReporterProcess>; |
587 ~SwReporterProcess() = default; | 587 ~SwReporterProcess() = default; |
588 | 588 |
589 // Starts a new IPC service implementing the ChromePrompt interface and | 589 // Starts a new IPC service implementing the ChromePrompt interface and |
590 // launches a new reporter process that can connect to the IPC. | 590 // launches a new reporter process that can connect to the IPC. |
591 base::Process LaunchConnectedReporterProcess(); | 591 base::Process LaunchConnectedReporterProcess(); |
592 | 592 |
593 // Starts a new instance of ChromePromptImpl to receive requests from the | 593 // Starts a new instance of ChromePromptImpl to receive requests from the |
594 // reporter. Must be run on the IO thread. | 594 // reporter. Must be run on the IO thread. |
grt (UTC plus 2)
2017/04/21 11:10:58
"...reporter and establishes the mojo connection t
ftirelo
2017/04/24 15:47:46
Done.
| |
595 void CreateChromePromptImpl( | 595 void CreateChromePromptImpl( |
596 base::ProcessHandle process, | |
597 mojo::edk::ConnectionParams connection_params, | |
598 std::unique_ptr<mojo::edk::PendingProcessConnection> | |
599 pending_process_connection, | |
596 chrome_cleaner::mojom::ChromePromptRequest chrome_prompt_request); | 600 chrome_cleaner::mojom::ChromePromptRequest chrome_prompt_request); |
597 | 601 |
598 // Releases the instance of ChromePromptImpl. Must be run on the IO thread. | 602 // Releases the instance of ChromePromptImpl. Must be run on the IO thread. |
599 void ReleaseChromePromptImpl(); | 603 void ReleaseChromePromptImpl(); |
600 | 604 |
601 // Launches a new process with the command line in the invocation and | 605 // Launches a new process with the command line in the invocation and |
602 // provided launch options. Uses g_testing_delegate_ if not null. | 606 // provided launch options. Uses g_testing_delegate_ if not null. |
603 base::Process LaunchReporterProcess( | 607 base::Process LaunchReporterProcess( |
604 const SwReporterInvocation& invocation, | 608 const SwReporterInvocation& invocation, |
605 const base::LaunchOptions& launch_options); | 609 const base::LaunchOptions& launch_options); |
606 | 610 |
607 // The invocation for the current reporter process. | 611 // The invocation for the current reporter process. |
608 SwReporterInvocation invocation_; | 612 SwReporterInvocation invocation_; |
609 | 613 |
610 // Implementation of the ChromePrompt service to be used by the current | 614 // Implementation of the ChromePrompt service to be used by the current |
611 // reporter process. Can only be accessed on the IO thread. | 615 // reporter process. Can only be accessed on the IO thread. |
612 std::unique_ptr<ChromePromptImpl> chrome_prompt_impl_; | 616 std::unique_ptr<ChromePromptImpl> chrome_prompt_impl_; |
613 }; | 617 }; |
614 | 618 |
615 int SwReporterProcess::LaunchAndWaitForExitOnBackgroundThread() { | 619 int SwReporterProcess::LaunchAndWaitForExitOnBackgroundThread() { |
616 base::Process reporter_process = | 620 base::Process reporter_process = |
617 base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature) | 621 base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature) |
618 ? LaunchConnectedReporterProcess() | 622 ? LaunchConnectedReporterProcess() |
619 : LaunchReporterProcess(invocation_, base::LaunchOptions()); | 623 : LaunchReporterProcess(invocation_, base::LaunchOptions()); |
620 | 624 |
621 // 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 |
622 // 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. |
623 int exit_code = kReporterFailureExitCode; | 627 int exit_code = kReporterNotLaunchedExitCode; |
624 UMAHistogramReporter uma(invocation_.suffix); | 628 UMAHistogramReporter uma(invocation_.suffix); |
625 if (reporter_process.IsValid()) { | 629 if (reporter_process.IsValid()) { |
626 uma.RecordReporterStep(SW_REPORTER_START_EXECUTION); | 630 uma.RecordReporterStep(SW_REPORTER_START_EXECUTION); |
627 bool success = reporter_process.WaitForExit(&exit_code); | 631 bool success = reporter_process.WaitForExit(&exit_code); |
628 DCHECK(success); | 632 DCHECK(success); |
629 } else { | 633 } else { |
630 uma.RecordReporterStep(SW_REPORTER_FAILED_TO_START); | 634 uma.RecordReporterStep(SW_REPORTER_FAILED_TO_START); |
631 } | 635 } |
632 return exit_code; | 636 return exit_code; |
633 } | 637 } |
634 | 638 |
635 void SwReporterProcess::OnReporterDone() { | 639 void SwReporterProcess::OnReporterDone() { |
636 if (base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature)) { | 640 if (base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature)) { |
637 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO) | 641 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO) |
638 ->PostTask(FROM_HERE, | 642 ->PostTask(FROM_HERE, |
639 base::Bind(&SwReporterProcess::ReleaseChromePromptImpl, | 643 base::Bind(&SwReporterProcess::ReleaseChromePromptImpl, |
640 base::RetainedRef(this))); | 644 base::RetainedRef(this))); |
641 } | 645 } |
642 } | 646 } |
643 | 647 |
644 base::Process SwReporterProcess::LaunchConnectedReporterProcess() { | 648 base::Process SwReporterProcess::LaunchConnectedReporterProcess() { |
645 DCHECK(base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature)); | 649 DCHECK(base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature)); |
646 | 650 |
647 mojo::edk::PendingProcessConnection pending_process_connection; | 651 std::unique_ptr<mojo::edk::PendingProcessConnection> |
652 pending_process_connection = | |
653 base::MakeUnique<mojo::edk::PendingProcessConnection>(); | |
648 std::string mojo_pipe_token; | 654 std::string mojo_pipe_token; |
649 mojo::ScopedMessagePipeHandle mojo_pipe = | 655 mojo::ScopedMessagePipeHandle mojo_pipe = |
650 pending_process_connection.CreateMessagePipe(&mojo_pipe_token); | 656 pending_process_connection->CreateMessagePipe(&mojo_pipe_token); |
651 invocation_.command_line.AppendSwitchASCII( | 657 invocation_.command_line.AppendSwitchASCII( |
652 chrome_cleaner::kChromeMojoPipeTokenSwitch, mojo_pipe_token); | 658 chrome_cleaner::kChromeMojoPipeTokenSwitch, mojo_pipe_token); |
653 invocation_.command_line.AppendSwitchASCII( | 659 invocation_.command_line.AppendSwitchASCII( |
654 chrome_cleaner::kExecutionModeSwitch, | 660 chrome_cleaner::kExecutionModeSwitch, |
655 base::IntToString( | 661 base::IntToString( |
656 static_cast<int>(chrome_cleaner::ExecutionMode::kScanning))); | 662 static_cast<int>(chrome_cleaner::ExecutionMode::kScanning))); |
657 | 663 |
658 mojo::edk::PlatformChannelPair channel; | 664 mojo::edk::PlatformChannelPair channel; |
659 base::HandlesToInheritVector handles_to_inherit; | 665 base::HandlesToInheritVector handles_to_inherit; |
660 channel.PrepareToPassClientHandleToChildProcess(&invocation_.command_line, | 666 channel.PrepareToPassClientHandleToChildProcess(&invocation_.command_line, |
661 &handles_to_inherit); | 667 &handles_to_inherit); |
662 | 668 |
663 base::LaunchOptions launch_options; | 669 base::LaunchOptions launch_options; |
664 launch_options.handles_to_inherit = &handles_to_inherit; | 670 launch_options.handles_to_inherit = &handles_to_inherit; |
665 base::Process reporter_process = | 671 base::Process reporter_process = |
666 LaunchReporterProcess(invocation_, launch_options); | 672 LaunchReporterProcess(invocation_, launch_options); |
667 | 673 |
668 if (!reporter_process.IsValid()) | 674 if (!reporter_process.IsValid()) |
669 return reporter_process; | 675 return reporter_process; |
670 | 676 |
671 pending_process_connection.Connect( | |
672 reporter_process.Handle(), | |
673 mojo::edk::ConnectionParams(channel.PassServerHandle())); | |
674 | |
675 chrome_cleaner::mojom::ChromePromptRequest chrome_prompt_request; | 677 chrome_cleaner::mojom::ChromePromptRequest chrome_prompt_request; |
676 chrome_prompt_request.Bind(std::move(mojo_pipe)); | 678 chrome_prompt_request.Bind(std::move(mojo_pipe)); |
677 | 679 |
678 // ChromePromptImpl tasks will need to run on the IO thread. There is no | 680 // ChromePromptImpl tasks will need to run on the IO thread. There is no |
679 // need to synchronize its creation, since the client end will wait for this | 681 // need to synchronize its creation, since the client end will wait for this |
680 // initialization to be done before sending requests. | 682 // initialization to be done before sending requests. |
683 base::OnceClosure f = base::BindOnce( | |
grt (UTC plus 2)
2017/04/21 11:10:59
why introduce a local for this? if you really thin
ftirelo
2017/04/24 15:47:46
Left-over from a previous test; after it passed, I
| |
684 &SwReporterProcess::CreateChromePromptImpl, base::RetainedRef(this), | |
685 reporter_process.Handle(), | |
grt (UTC plus 2)
2017/04/21 11:10:58
please document why it's safe to pass the naked ha
ftirelo
2017/04/24 15:47:46
Obsolete.
| |
686 mojo::edk::ConnectionParams(channel.PassServerHandle()), | |
687 std::move(pending_process_connection), std::move(chrome_prompt_request)); | |
681 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO) | 688 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO) |
682 ->PostTask(FROM_HERE, | 689 ->PostTask(FROM_HERE, std::move(f)); |
683 base::BindOnce(&SwReporterProcess::CreateChromePromptImpl, | |
684 base::RetainedRef(this), | |
685 std::move(chrome_prompt_request))); | |
686 | 690 |
687 return reporter_process; | 691 return reporter_process; |
688 } | 692 } |
689 | 693 |
690 base::Process SwReporterProcess::LaunchReporterProcess( | 694 base::Process SwReporterProcess::LaunchReporterProcess( |
691 const SwReporterInvocation& invocation, | 695 const SwReporterInvocation& invocation, |
692 const base::LaunchOptions& launch_options) { | 696 const base::LaunchOptions& launch_options) { |
693 return g_testing_delegate_ | 697 return g_testing_delegate_ |
694 ? g_testing_delegate_->LaunchReporter(invocation, launch_options) | 698 ? g_testing_delegate_->LaunchReporter(invocation, launch_options) |
695 : base::LaunchProcess(invocation.command_line, launch_options); | 699 : base::LaunchProcess(invocation.command_line, launch_options); |
696 } | 700 } |
697 | 701 |
698 void SwReporterProcess::CreateChromePromptImpl( | 702 void SwReporterProcess::CreateChromePromptImpl( |
703 base::ProcessHandle process, | |
704 mojo::edk::ConnectionParams connection_params, | |
705 std::unique_ptr<mojo::edk::PendingProcessConnection> | |
706 pending_process_connection, | |
699 chrome_cleaner::mojom::ChromePromptRequest chrome_prompt_request) { | 707 chrome_cleaner::mojom::ChromePromptRequest chrome_prompt_request) { |
700 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 708 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
701 DCHECK(base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature)); | 709 DCHECK(base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature)); |
702 | 710 |
703 chrome_prompt_impl_ = | 711 chrome_prompt_impl_ = |
704 base::MakeUnique<ChromePromptImpl>(std::move(chrome_prompt_request)); | 712 base::MakeUnique<ChromePromptImpl>(std::move(chrome_prompt_request)); |
grt (UTC plus 2)
2017/04/21 11:10:58
perhaps this could call a function on the testing
ftirelo
2017/04/24 15:47:46
Done.
| |
713 | |
714 pending_process_connection->Connect( | |
715 process, std::move(connection_params), | |
716 base::Bind(&ChromePromptImpl::OnConnectionError, | |
717 base::Unretained(chrome_prompt_impl_.get()))); | |
grt (UTC plus 2)
2017/04/21 11:10:58
please document why this Unretained is safe. is it
ftirelo
2017/04/24 15:47:46
Obsolete.
| |
705 } | 718 } |
706 | 719 |
707 void SwReporterProcess::ReleaseChromePromptImpl() { | 720 void SwReporterProcess::ReleaseChromePromptImpl() { |
708 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 721 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
709 DCHECK(base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature)); | 722 DCHECK(base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature)); |
710 | 723 |
711 chrome_prompt_impl_.release(); | 724 chrome_prompt_impl_.release(); |
712 } | 725 } |
713 | 726 |
714 } // namespace | 727 } // namespace |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
927 scoped_refptr<SwReporterProcess> sw_reporter_process, | 940 scoped_refptr<SwReporterProcess> sw_reporter_process, |
928 int exit_code) { | 941 int exit_code) { |
929 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 942 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
930 | 943 |
931 sw_reporter_process->OnReporterDone(); | 944 sw_reporter_process->OnReporterDone(); |
932 | 945 |
933 base::Time now = Now(); | 946 base::Time now = Now(); |
934 base::TimeDelta reporter_running_time = now - reporter_start_time; | 947 base::TimeDelta reporter_running_time = now - reporter_start_time; |
935 | 948 |
936 // Don't continue the current queue of reporters if one failed to launch. | 949 // Don't continue the current queue of reporters if one failed to launch. |
937 if (exit_code == kReporterFailureExitCode) | 950 if (exit_code == kReporterNotLaunchedExitCode) |
938 current_invocations_ = SwReporterQueue(); | 951 current_invocations_ = SwReporterQueue(); |
939 | 952 |
940 // As soon as we're not running this queue, schedule the next overall queue | 953 // As soon as we're not running this queue, schedule the next overall queue |
941 // run after the regular delay. (If there was a failure it's not worth | 954 // run after the regular delay. (If there was a failure it's not worth |
942 // retrying earlier, risking running too often if it always fails, since | 955 // retrying earlier, risking running too often if it always fails, since |
943 // not many users fail here.) | 956 // not many users fail here.) |
944 if (current_invocations_.empty()) { | 957 if (current_invocations_.empty()) { |
945 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 958 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
946 FROM_HERE, | 959 FROM_HERE, |
947 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), | 960 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), |
948 base::TimeDelta::FromDays(days_between_reporter_runs_)); | 961 base::TimeDelta::FromDays(days_between_reporter_runs_)); |
949 } else { | 962 } else { |
950 ScheduleNextInvocation(); | 963 ScheduleNextInvocation(); |
951 } | 964 } |
952 | 965 |
953 // If the reporter failed to launch, do not process the results. (The exit | 966 // If the reporter failed to launch, do not process the results. (The exit |
954 // code itself doesn't need to be logged in this case because | 967 // code itself doesn't need to be logged in this case because |
955 // SW_REPORTER_FAILED_TO_START is logged in | 968 // SW_REPORTER_FAILED_TO_START is logged in |
956 // |LaunchAndWaitForExitOnBackgroundThread|.) | 969 // |LaunchAndWaitForExitOnBackgroundThread|.) |
957 if (exit_code == kReporterFailureExitCode) | 970 if (exit_code == kReporterNotLaunchedExitCode) |
958 return; | 971 return; |
959 | 972 |
960 const auto& finished_invocation = sw_reporter_process->invocation(); | 973 const auto& finished_invocation = sw_reporter_process->invocation(); |
961 UMAHistogramReporter uma(finished_invocation.suffix); | 974 UMAHistogramReporter uma(finished_invocation.suffix); |
962 uma.ReportVersion(version); | 975 uma.ReportVersion(version); |
963 uma.ReportExitCode(exit_code); | 976 uma.ReportExitCode(exit_code); |
964 uma.ReportEngineErrorCode(); | 977 uma.ReportEngineErrorCode(); |
965 uma.ReportFoundUwS(); | 978 uma.ReportFoundUwS(); |
966 | 979 |
967 PrefService* local_state = g_browser_process->local_state(); | 980 PrefService* local_state = g_browser_process->local_state(); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1221 return srt_cleaner_key.Open(HKEY_CURRENT_USER, cleaner_key_path.c_str(), | 1234 return srt_cleaner_key.Open(HKEY_CURRENT_USER, cleaner_key_path.c_str(), |
1222 KEY_QUERY_VALUE) == ERROR_SUCCESS && | 1235 KEY_QUERY_VALUE) == ERROR_SUCCESS && |
1223 srt_cleaner_key.GetValueCount() > 0; | 1236 srt_cleaner_key.GetValueCount() > 0; |
1224 } | 1237 } |
1225 | 1238 |
1226 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { | 1239 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { |
1227 g_testing_delegate_ = delegate; | 1240 g_testing_delegate_ = delegate; |
1228 } | 1241 } |
1229 | 1242 |
1230 } // namespace safe_browsing | 1243 } // namespace safe_browsing |
OLD | NEW |