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

Side by Side Diff: chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_runner_win.h

Issue 2890023005: Chrome Cleaner UI: reporter no longer uses mojo. (Closed)
Patch Set: Nits Created 3 years, 7 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
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_SAFE_BROWSING_CHROME_CLEANER_CHROME_CLEANER_RUNNER_WIN_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_CHROME_CLEANER_CHROME_CLEANER_RUNNER_WIN_H_
7
8 #include <limits>
9 #include <memory>
10 #include <set>
11 #include <string>
12
13 #include "base/callback.h"
14 #include "base/command_line.h"
15 #include "base/files/file_path.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/process/launch.h"
18 #include "base/process/process.h"
19 #include "base/sequenced_task_runner.h"
20 #include "chrome/browser/safe_browsing/chrome_cleaner/reporter_runner_win.h"
21 #include "chrome/browser/safe_browsing/chrome_cleaner/srt_chrome_prompt_impl.h"
22 #include "components/chrome_cleaner/public/interfaces/chrome_prompt.mojom.h"
23
24 namespace safe_browsing {
25
26 // Class responsible for launching the cleaner process and waiting for its
27 // completion when the InBrowserCleanerUI feature is enabled. This object is
28 // also responsible for starting the ChromePromptImpl object on the IO thread
29 // and controlling its lifetime.
30 //
31 // Expected lifecycle of a ChromeCleanerRunner:
32 //
33 // - Instances are created via the static
34 // RunChromeCleanerAndReplyWithExitCode() function. Instances will not be
35 // destroyed before the Chrome Cleaner process has terminated _and_ a
36 // Mojo connection-closed callback has been received. Destruction can happen
37 // on any thread.
38 // - The private LaunchAndWaitForExitOnBackgroundThread() function launches the
39 // Chrome Cleaner process, creates a ChromePromptImpl object on the IO thread
40 // and waits for the Cleaner process to terminate. The static
41 // RunChromeCleanerAndReplyWithExitCode() function takes care of calling that
42 // function correctly on a sequence with the correct traits.
43 // - All callbacks registered with an instance are posted to run on the
44 // provided |task_runner|
45 // - The ChromePromptImpl object is destroyed on the IO thread after a
46 // connection-closed has been received from Mojo. The runner instance will
47 // not be destroyed before the ChromePromptImpl object has been released.
48 class ChromeCleanerRunner
49 : public base::RefCountedThreadSafe<ChromeCleanerRunner> {
50 public:
51 enum class ChromeMetricsStatus {
52 kEnabled,
53 kDisabled,
54 };
55
56 enum class CleanerLogsStatus {
57 kUploadEnabled,
58 kUploadDisabled,
59 };
60
61 struct LaunchStatus {
62 // If false, indicates that either the Chrome Cleaner process handle
63 // returned by base::LaunchProcess() was invalid or that something went
64 // wrong while waiting for the process to exit.
65 bool process_ok;
66 // The exit code from the Chrome Cleaner process. Should not be used if
67 // |process_ok| is false.
68 int exit_code;
69 };
70
71 using ProcessDoneCallback = base::OnceCallback<void(LaunchStatus)>;
72
73 // Executes the Chrome Cleaner in the background, initializes the Mojo IPC
74 // between Chrome and the Chrome Cleaner process, and forwards Mojo callbacks
75 // via the callbacks that are passed to it.
76 //
77 // All callbacks are posted to provided |task_runner|.
78 //
79 // More details:
80 //
81 // This function will pass command line flags to the Chrome Cleaner executable
82 // as appropriate based on the flags in |reporter_invocation| and the
83 // |metrics_status| and |cleaner_logs_status| parameters. The Cleaner process
84 // will communicate with Chrome via a Mojo IPC interface and any IPC requests
85 // or notifications are passed to the caller via the |on_prompt_user| and
86 // |on_connection_closed| callbacks. Finally, when the Chrome Cleaner process
87 // terminates, a LaunchStatus is passed along to |on_process_done|.
88 //
89 // The details of the mojo interface are documented in
90 // "components/chrome_cleaner/public/interfaces/chrome_prompt.mojom.h".
91 static void RunChromeCleanerAndReplyWithExitCode(
92 const base::FilePath& cleaner_executable_path,
93 const SwReporterInvocation& reporter_invocation,
94 ChromeMetricsStatus metrics_status,
95 CleanerLogsStatus cleaner_logs_status,
96 ChromePromptImpl::OnPromptUser on_prompt_user,
97 base::OnceClosure on_connection_closed,
98 ChromeCleanerRunner::ProcessDoneCallback on_process_done,
99 scoped_refptr<base::SequencedTaskRunner> task_runner);
100
101 private:
102 friend class base::RefCountedThreadSafe<ChromeCleanerRunner>;
103
104 ~ChromeCleanerRunner();
105
106 ChromeCleanerRunner(const base::FilePath& cleaner_executable_path,
107 const SwReporterInvocation& reporter_invocation,
108 ChromeMetricsStatus metrics_status,
109 CleanerLogsStatus cleaner_logs_status,
110 ChromePromptImpl::OnPromptUser on_prompt_user,
111 base::OnceClosure on_connection_closed,
112 ChromeCleanerRunner::ProcessDoneCallback on_process_done,
113 scoped_refptr<base::SequencedTaskRunner> task_runner);
114
115 LaunchStatus LaunchAndWaitForExitOnBackgroundThread();
116
117 void CreateChromePromptImpl(
118 chrome_cleaner::mojom::ChromePromptRequest chrome_prompt_request);
119
120 // Callbacks received from the Mojo interface.
121 void OnPromptUser(std::unique_ptr<std::set<base::FilePath>> files_to_delete,
122 chrome_cleaner::mojom::ChromePrompt::PromptUserCallback
123 prompt_user_callback);
124 void OnConnectionClosed();
125 void OnProcessDone(LaunchStatus launch_status);
126
127 scoped_refptr<base::SequencedTaskRunner> task_runner_;
128
129 base::CommandLine cleaner_command_line_;
130 ChromePromptImpl::OnPromptUser on_prompt_user_;
131 base::OnceClosure on_connection_closed_;
132 ProcessDoneCallback on_process_done_;
133
134 std::unique_ptr<ChromePromptImpl> chrome_prompt_impl_;
135 };
136
137 // A delegate class used to override launching of the Cleaner proccess for
138 // tests.
139 class ChromeCleanerRunnerTestDelegate {
140 public:
141 virtual ~ChromeCleanerRunnerTestDelegate() = default;
142
143 // Called instead of base::LaunchProcess() during testing.
144 virtual base::Process LaunchTestProcess(
145 const base::CommandLine& command_line,
146 const base::LaunchOptions& launch_options) = 0;
147 };
148
149 void SetChromeCleanerRunnerTestDelegateForTesting(
150 ChromeCleanerRunnerTestDelegate* test_delegate);
151
152 } // namespace safe_browsing
153
154 #endif // CHROME_BROWSER_SAFE_BROWSING_CHROME_CLEANER_CHROME_CLEANER_RUNNER_WIN _H_
OLDNEW
« no previous file with comments | « chrome/browser/BUILD.gn ('k') | chrome/browser/safe_browsing/chrome_cleaner/chrome_cleaner_runner_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698