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