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