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 27 matching lines...) Expand all Loading... | |
38 #include "chrome/browser/safe_browsing/srt_chrome_prompt_impl.h" | 38 #include "chrome/browser/safe_browsing/srt_chrome_prompt_impl.h" |
39 #include "chrome/browser/safe_browsing/srt_client_info_win.h" | 39 #include "chrome/browser/safe_browsing/srt_client_info_win.h" |
40 #include "chrome/browser/safe_browsing/srt_global_error_win.h" | 40 #include "chrome/browser/safe_browsing/srt_global_error_win.h" |
41 #include "chrome/browser/ui/browser_finder.h" | 41 #include "chrome/browser/ui/browser_finder.h" |
42 #include "chrome/browser/ui/browser_list.h" | 42 #include "chrome/browser/ui/browser_list.h" |
43 #include "chrome/browser/ui/browser_list_observer.h" | 43 #include "chrome/browser/ui/browser_list_observer.h" |
44 #include "chrome/browser/ui/global_error/global_error_service.h" | 44 #include "chrome/browser/ui/global_error/global_error_service.h" |
45 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 45 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
46 #include "chrome/common/pref_names.h" | 46 #include "chrome/common/pref_names.h" |
47 #include "components/chrome_cleaner/public/constants/constants.h" | 47 #include "components/chrome_cleaner/public/constants/constants.h" |
48 #include "components/chrome_cleaner/public/interfaces/chrome_prompt.mojom.h" | 48 #include "components/chrome_cleaner/public/interfaces/chrome_prompt.mojom.h" |
grt (UTC plus 2)
2017/04/26 08:46:46
remove this now that it's included by the .h
ftirelo
2017/04/26 14:14:16
Done.
| |
49 #include "components/component_updater/pref_names.h" | 49 #include "components/component_updater/pref_names.h" |
50 #include "components/data_use_measurement/core/data_use_user_data.h" | 50 #include "components/data_use_measurement/core/data_use_user_data.h" |
51 #include "components/prefs/pref_service.h" | 51 #include "components/prefs/pref_service.h" |
52 #include "components/variations/net/variations_http_headers.h" | 52 #include "components/variations/net/variations_http_headers.h" |
53 #include "components/version_info/version_info.h" | 53 #include "components/version_info/version_info.h" |
54 #include "content/public/browser/browser_thread.h" | 54 #include "content/public/browser/browser_thread.h" |
55 #include "mojo/edk/embedder/connection_params.h" | 55 #include "mojo/edk/embedder/connection_params.h" |
56 #include "mojo/edk/embedder/pending_process_connection.h" | 56 #include "mojo/edk/embedder/pending_process_connection.h" |
57 #include "mojo/edk/embedder/platform_channel_pair.h" | 57 #include "mojo/edk/embedder/platform_channel_pair.h" |
58 #include "mojo/public/cpp/system/message_pipe.h" | 58 #include "mojo/public/cpp/system/message_pipe.h" |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
538 if (error->GetBubbleView()) { | 538 if (error->GetBubbleView()) { |
539 show_bubble = false; | 539 show_bubble = false; |
540 break; | 540 break; |
541 } | 541 } |
542 } | 542 } |
543 } | 543 } |
544 if (show_bubble) | 544 if (show_bubble) |
545 global_error->ShowBubbleView(browser); | 545 global_error->ShowBubbleView(browser); |
546 } | 546 } |
547 | 547 |
548 // Handles the case when the remote end has been closed, by performing the | |
549 // necessary cleanups if the prompt dialog is being shown to the user. | |
550 void OnConnectionClosed() { | |
551 // Placeholder. This should handle cases when the reporter process is | |
552 // disconnected (e.g. due to a crash) and the prompt dialog is being shown | |
553 // to the user. | |
554 } | |
555 | |
556 // Handles the case when a mojo::ReportBadMessage has been explicitly reported. | |
557 void OnConnectionError(const std::string& message) { | |
558 // Placeholder. This should handle cases when the reporter process sends | |
559 // a bad message and the prompt dialog is being shown to the user. | |
560 } | |
561 | |
548 // Class responsible for launching the reporter process and waiting for its | 562 // Class responsible for launching the reporter process and waiting for its |
549 // completion. If feature InBrowserCleanerUI is enabled, this object will also | 563 // completion. If feature InBrowserCleanerUI is enabled, this object will also |
550 // be responsible for starting the ChromePromptImpl object on the IO thread and | 564 // be responsible for starting the ChromePromptImpl object on the IO thread and |
551 // controlling its lifetime. | 565 // controlling its lifetime. |
552 // | 566 // |
553 // Expected lifecycle of a SwReporterProcess: | 567 // Expected lifecycle of a SwReporterProcess: |
554 // - created on the UI thread before the reporter process launch is posted | 568 // - created on the UI thread before the reporter process launch is posted |
555 // (method ScheduleNextInvocation); | 569 // (method ScheduleNextInvocation); |
556 // - deleted on the UI thread once ReporterDone() finishes (the method is | 570 // - deleted on the UI thread once ReporterDone() finishes (the method is |
557 // called after the reporter process exits). | 571 // called after the reporter process exits). |
(...skipping 26 matching lines...) Expand all Loading... | |
584 | 598 |
585 private: | 599 private: |
586 friend class base::RefCountedThreadSafe<SwReporterProcess>; | 600 friend class base::RefCountedThreadSafe<SwReporterProcess>; |
587 ~SwReporterProcess() = default; | 601 ~SwReporterProcess() = default; |
588 | 602 |
589 // Starts a new IPC service implementing the ChromePrompt interface and | 603 // Starts a new IPC service implementing the ChromePrompt interface and |
590 // launches a new reporter process that can connect to the IPC. | 604 // launches a new reporter process that can connect to the IPC. |
591 base::Process LaunchConnectedReporterProcess(); | 605 base::Process LaunchConnectedReporterProcess(); |
592 | 606 |
593 // Starts a new instance of ChromePromptImpl to receive requests from the | 607 // Starts a new instance of ChromePromptImpl to receive requests from the |
594 // reporter. Must be run on the IO thread. | 608 // reporter and establishes the mojo connection to it. |
609 // Must be run on the IO thread. | |
595 void CreateChromePromptImpl( | 610 void CreateChromePromptImpl( |
596 chrome_cleaner::mojom::ChromePromptRequest chrome_prompt_request); | 611 chrome_cleaner::mojom::ChromePromptRequest chrome_prompt_request); |
597 | 612 |
598 // Releases the instance of ChromePromptImpl. Must be run on the IO thread. | 613 // Releases the instance of ChromePromptImpl. Must be run on the IO thread. |
599 void ReleaseChromePromptImpl(); | 614 void ReleaseChromePromptImpl(); |
600 | 615 |
601 // Launches a new process with the command line in the invocation and | 616 // Launches a new process with the command line in the invocation and |
602 // provided launch options. Uses g_testing_delegate_ if not null. | 617 // provided launch options. Uses g_testing_delegate_ if not null. |
603 base::Process LaunchReporterProcess( | 618 base::Process LaunchReporterProcess( |
604 const SwReporterInvocation& invocation, | 619 const SwReporterInvocation& invocation, |
605 const base::LaunchOptions& launch_options); | 620 const base::LaunchOptions& launch_options); |
606 | 621 |
607 // The invocation for the current reporter process. | 622 // The invocation for the current reporter process. |
608 SwReporterInvocation invocation_; | 623 SwReporterInvocation invocation_; |
609 | 624 |
610 // Implementation of the ChromePrompt service to be used by the current | 625 // Implementation of the ChromePrompt service to be used by the current |
611 // reporter process. Can only be accessed on the IO thread. | 626 // reporter process. Can only be accessed on the IO thread. |
612 std::unique_ptr<ChromePromptImpl> chrome_prompt_impl_; | 627 std::unique_ptr<ChromePromptImpl> chrome_prompt_impl_; |
613 }; | 628 }; |
614 | 629 |
615 int SwReporterProcess::LaunchAndWaitForExitOnBackgroundThread() { | 630 int SwReporterProcess::LaunchAndWaitForExitOnBackgroundThread() { |
616 base::Process reporter_process = | 631 base::Process reporter_process = |
617 base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature) | 632 base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature) |
618 ? LaunchConnectedReporterProcess() | 633 ? LaunchConnectedReporterProcess() |
619 : LaunchReporterProcess(invocation_, base::LaunchOptions()); | 634 : LaunchReporterProcess(invocation_, base::LaunchOptions()); |
620 | 635 |
621 // 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 |
622 // 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. |
623 int exit_code = kReporterFailureExitCode; | 638 int exit_code = kReporterNotLaunchedExitCode; |
624 UMAHistogramReporter uma(invocation_.suffix); | 639 UMAHistogramReporter uma(invocation_.suffix); |
625 if (reporter_process.IsValid()) { | 640 if (reporter_process.IsValid()) { |
626 uma.RecordReporterStep(SW_REPORTER_START_EXECUTION); | 641 uma.RecordReporterStep(SW_REPORTER_START_EXECUTION); |
627 bool success = reporter_process.WaitForExit(&exit_code); | 642 bool success = reporter_process.WaitForExit(&exit_code); |
628 DCHECK(success); | 643 DCHECK(success); |
629 } else { | 644 } else { |
630 uma.RecordReporterStep(SW_REPORTER_FAILED_TO_START); | 645 uma.RecordReporterStep(SW_REPORTER_FAILED_TO_START); |
631 } | 646 } |
632 return exit_code; | 647 return exit_code; |
633 } | 648 } |
(...skipping 27 matching lines...) Expand all Loading... | |
661 &handles_to_inherit); | 676 &handles_to_inherit); |
662 | 677 |
663 base::LaunchOptions launch_options; | 678 base::LaunchOptions launch_options; |
664 launch_options.handles_to_inherit = &handles_to_inherit; | 679 launch_options.handles_to_inherit = &handles_to_inherit; |
665 base::Process reporter_process = | 680 base::Process reporter_process = |
666 LaunchReporterProcess(invocation_, launch_options); | 681 LaunchReporterProcess(invocation_, launch_options); |
667 | 682 |
668 if (!reporter_process.IsValid()) | 683 if (!reporter_process.IsValid()) |
669 return reporter_process; | 684 return reporter_process; |
670 | 685 |
671 pending_process_connection.Connect( | |
672 reporter_process.Handle(), | |
673 mojo::edk::ConnectionParams(channel.PassServerHandle())); | |
674 | |
675 chrome_cleaner::mojom::ChromePromptRequest chrome_prompt_request; | 686 chrome_cleaner::mojom::ChromePromptRequest chrome_prompt_request; |
676 chrome_prompt_request.Bind(std::move(mojo_pipe)); | 687 chrome_prompt_request.Bind(std::move(mojo_pipe)); |
677 | 688 |
678 // ChromePromptImpl tasks will need to run on the IO thread. There is no | 689 // 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 | 690 // need to synchronize its creation, since the client end will wait for this |
680 // initialization to be done before sending requests. | 691 // initialization to be done before sending requests. |
681 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO) | 692 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO) |
682 ->PostTask(FROM_HERE, | 693 ->PostTask(FROM_HERE, |
683 base::BindOnce(&SwReporterProcess::CreateChromePromptImpl, | 694 base::BindOnce(&SwReporterProcess::CreateChromePromptImpl, |
684 base::RetainedRef(this), | 695 base::RetainedRef(this), |
685 std::move(chrome_prompt_request))); | 696 std::move(chrome_prompt_request))); |
686 | 697 |
698 mojo::edk::ProcessErrorCallback on_connection_error = | |
699 g_testing_delegate_ | |
700 ? base::Bind(&SwReporterTestingDelegate::OnConnectionError, | |
701 base::Unretained(g_testing_delegate_)) | |
702 : base::Bind(&OnConnectionError); | |
703 pending_process_connection.Connect( | |
704 reporter_process.Handle(), | |
705 mojo::edk::ConnectionParams(channel.PassServerHandle()), | |
706 on_connection_error); | |
707 | |
687 return reporter_process; | 708 return reporter_process; |
688 } | 709 } |
689 | 710 |
690 base::Process SwReporterProcess::LaunchReporterProcess( | 711 base::Process SwReporterProcess::LaunchReporterProcess( |
691 const SwReporterInvocation& invocation, | 712 const SwReporterInvocation& invocation, |
692 const base::LaunchOptions& launch_options) { | 713 const base::LaunchOptions& launch_options) { |
693 return g_testing_delegate_ | 714 return g_testing_delegate_ |
694 ? g_testing_delegate_->LaunchReporter(invocation, launch_options) | 715 ? g_testing_delegate_->LaunchReporter(invocation, launch_options) |
695 : base::LaunchProcess(invocation.command_line, launch_options); | 716 : base::LaunchProcess(invocation.command_line, launch_options); |
696 } | 717 } |
697 | 718 |
698 void SwReporterProcess::CreateChromePromptImpl( | 719 void SwReporterProcess::CreateChromePromptImpl( |
699 chrome_cleaner::mojom::ChromePromptRequest chrome_prompt_request) { | 720 chrome_cleaner::mojom::ChromePromptRequest chrome_prompt_request) { |
700 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 721 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
701 DCHECK(base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature)); | 722 DCHECK(base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature)); |
702 | 723 |
703 chrome_prompt_impl_ = | 724 chrome_prompt_impl_ = |
704 base::MakeUnique<ChromePromptImpl>(std::move(chrome_prompt_request)); | 725 g_testing_delegate_ |
726 ? g_testing_delegate_->CreateChromePromptImpl( | |
727 std::move(chrome_prompt_request)) | |
728 : base::MakeUnique<ChromePromptImpl>(std::move(chrome_prompt_request), | |
729 base::Bind(&OnConnectionClosed)); | |
705 } | 730 } |
706 | 731 |
707 void SwReporterProcess::ReleaseChromePromptImpl() { | 732 void SwReporterProcess::ReleaseChromePromptImpl() { |
708 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 733 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
709 DCHECK(base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature)); | 734 DCHECK(base::FeatureList::IsEnabled(kInBrowserCleanerUIFeature)); |
710 | 735 |
711 chrome_prompt_impl_.release(); | 736 chrome_prompt_impl_.release(); |
712 } | 737 } |
713 | 738 |
714 } // namespace | 739 } // namespace |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
927 scoped_refptr<SwReporterProcess> sw_reporter_process, | 952 scoped_refptr<SwReporterProcess> sw_reporter_process, |
928 int exit_code) { | 953 int exit_code) { |
929 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 954 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
930 | 955 |
931 sw_reporter_process->OnReporterDone(); | 956 sw_reporter_process->OnReporterDone(); |
932 | 957 |
933 base::Time now = Now(); | 958 base::Time now = Now(); |
934 base::TimeDelta reporter_running_time = now - reporter_start_time; | 959 base::TimeDelta reporter_running_time = now - reporter_start_time; |
935 | 960 |
936 // Don't continue the current queue of reporters if one failed to launch. | 961 // Don't continue the current queue of reporters if one failed to launch. |
937 if (exit_code == kReporterFailureExitCode) | 962 if (exit_code == kReporterNotLaunchedExitCode) |
938 current_invocations_ = SwReporterQueue(); | 963 current_invocations_ = SwReporterQueue(); |
939 | 964 |
940 // As soon as we're not running this queue, schedule the next overall queue | 965 // 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 | 966 // 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 | 967 // retrying earlier, risking running too often if it always fails, since |
943 // not many users fail here.) | 968 // not many users fail here.) |
944 if (current_invocations_.empty()) { | 969 if (current_invocations_.empty()) { |
945 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 970 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
946 FROM_HERE, | 971 FROM_HERE, |
947 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), | 972 base::Bind(&ReporterRunner::TryToRun, base::Unretained(this)), |
948 base::TimeDelta::FromDays(days_between_reporter_runs_)); | 973 base::TimeDelta::FromDays(days_between_reporter_runs_)); |
949 } else { | 974 } else { |
950 ScheduleNextInvocation(); | 975 ScheduleNextInvocation(); |
951 } | 976 } |
952 | 977 |
953 // If the reporter failed to launch, do not process the results. (The exit | 978 // 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 | 979 // code itself doesn't need to be logged in this case because |
955 // SW_REPORTER_FAILED_TO_START is logged in | 980 // SW_REPORTER_FAILED_TO_START is logged in |
956 // |LaunchAndWaitForExitOnBackgroundThread|.) | 981 // |LaunchAndWaitForExitOnBackgroundThread|.) |
957 if (exit_code == kReporterFailureExitCode) | 982 if (exit_code == kReporterNotLaunchedExitCode) |
958 return; | 983 return; |
959 | 984 |
960 const auto& finished_invocation = sw_reporter_process->invocation(); | 985 const auto& finished_invocation = sw_reporter_process->invocation(); |
961 UMAHistogramReporter uma(finished_invocation.suffix); | 986 UMAHistogramReporter uma(finished_invocation.suffix); |
962 uma.ReportVersion(version); | 987 uma.ReportVersion(version); |
963 uma.ReportExitCode(exit_code); | 988 uma.ReportExitCode(exit_code); |
964 uma.ReportEngineErrorCode(); | 989 uma.ReportEngineErrorCode(); |
965 uma.ReportFoundUwS(); | 990 uma.ReportFoundUwS(); |
966 | 991 |
967 PrefService* local_state = g_browser_process->local_state(); | 992 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(), | 1246 return srt_cleaner_key.Open(HKEY_CURRENT_USER, cleaner_key_path.c_str(), |
1222 KEY_QUERY_VALUE) == ERROR_SUCCESS && | 1247 KEY_QUERY_VALUE) == ERROR_SUCCESS && |
1223 srt_cleaner_key.GetValueCount() > 0; | 1248 srt_cleaner_key.GetValueCount() > 0; |
1224 } | 1249 } |
1225 | 1250 |
1226 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { | 1251 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate) { |
1227 g_testing_delegate_ = delegate; | 1252 g_testing_delegate_ = delegate; |
1228 } | 1253 } |
1229 | 1254 |
1230 } // namespace safe_browsing | 1255 } // namespace safe_browsing |
OLD | NEW |