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 #ifndef CHROME_BROWSER_SAFE_BROWSING_SRT_FETCHER_WIN_H_ | 5 #ifndef CHROME_BROWSER_SAFE_BROWSING_SRT_FETCHER_WIN_H_ |
6 #define CHROME_BROWSER_SAFE_BROWSING_SRT_FETCHER_WIN_H_ | 6 #define CHROME_BROWSER_SAFE_BROWSING_SRT_FETCHER_WIN_H_ |
7 | 7 |
8 #include <limits.h> | 8 #include <limits.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <queue> | 11 #include <queue> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/feature_list.h" | 15 #include "base/feature_list.h" |
16 #include "base/process/launch.h" | 16 #include "base/process/launch.h" |
17 #include "base/process/process.h" | 17 #include "base/process/process.h" |
18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "components/chrome_cleaner/public/interfaces/chrome_prompt.mojom.h" |
19 | 20 |
20 namespace base { | 21 namespace base { |
21 class FilePath; | 22 class FilePath; |
22 class TaskRunner; | 23 class TaskRunner; |
23 class Version; | 24 class Version; |
24 } | 25 } |
25 | 26 |
26 class Browser; | 27 class Browser; |
27 | 28 |
28 namespace safe_browsing { | 29 namespace safe_browsing { |
29 | 30 |
| 31 class ChromePromptImpl; |
| 32 |
30 // A special exit code identifying a failure to run the reporter. | 33 // A special exit code identifying a failure to run the reporter. |
31 const int kReporterFailureExitCode = INT_MAX; | 34 const int kReporterNotLaunchedExitCode = INT_MAX; |
32 | 35 |
33 // The number of days to wait before triggering another reporter run. | 36 // The number of days to wait before triggering another reporter run. |
34 const int kDaysBetweenSuccessfulSwReporterRuns = 7; | 37 const int kDaysBetweenSuccessfulSwReporterRuns = 7; |
35 const int kDaysBetweenSwReporterRunsForPendingPrompt = 1; | 38 const int kDaysBetweenSwReporterRunsForPendingPrompt = 1; |
36 // The number of days to wait before sending out reporter logs. | 39 // The number of days to wait before sending out reporter logs. |
37 const int kDaysBetweenReporterLogsSent = 7; | 40 const int kDaysBetweenReporterLogsSent = 7; |
38 | 41 |
39 // When enabled, moves all user interaction with the Software Reporter and the | 42 // When enabled, moves all user interaction with the Software Reporter and the |
40 // Chrome Cleanup tool to Chrome. | 43 // Chrome Cleanup tool to Chrome. |
41 extern const base::Feature kInBrowserCleanerUIFeature; | 44 extern const base::Feature kInBrowserCleanerUIFeature; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // recent Reporter run terminated with an exit code indicating the presence of | 99 // recent Reporter run terminated with an exit code indicating the presence of |
97 // UwS. | 100 // UwS. |
98 bool ReporterFoundUws(); | 101 bool ReporterFoundUws(); |
99 | 102 |
100 // Returns true iff a valid registry key for the SRT Cleaner exists, and that | 103 // Returns true iff a valid registry key for the SRT Cleaner exists, and that |
101 // key is nonempty. | 104 // key is nonempty. |
102 // TODO(tmartino): Consider changing to check whether the user has recently | 105 // TODO(tmartino): Consider changing to check whether the user has recently |
103 // run the cleaner, rather than checking if they've run it at all. | 106 // run the cleaner, rather than checking if they've run it at all. |
104 bool UserHasRunCleaner(); | 107 bool UserHasRunCleaner(); |
105 | 108 |
106 // Mocks and callbacks for the unit tests. | 109 // A delegate used by tests to implement test doubles (e.g., stubs, fakes, or |
| 110 // mocks). |
107 class SwReporterTestingDelegate { | 111 class SwReporterTestingDelegate { |
108 public: | 112 public: |
109 virtual ~SwReporterTestingDelegate() {} | 113 virtual ~SwReporterTestingDelegate() {} |
110 | 114 |
111 // Test mock for launching the reporter. | 115 // Invoked by tests in places of base::LaunchProcess. |
| 116 // See chrome_cleaner::mojom::ChromePromptRequest(). |
112 virtual base::Process LaunchReporter( | 117 virtual base::Process LaunchReporter( |
113 const SwReporterInvocation& invocation, | 118 const SwReporterInvocation& invocation, |
114 const base::LaunchOptions& launch_options) = 0; | 119 const base::LaunchOptions& launch_options) = 0; |
115 | 120 |
116 // Test mock for showing the prompt. | 121 // Invoked by tests in place of the actual prompting logic. |
| 122 // See MaybeFetchSRT(). |
117 virtual void TriggerPrompt(Browser* browser, | 123 virtual void TriggerPrompt(Browser* browser, |
118 const std::string& reporter_version) = 0; | 124 const std::string& reporter_version) = 0; |
119 | 125 |
120 // Returns the test's idea of the current time. | 126 // Invoked by tests to override the current time. |
| 127 // See Now() in srt_fetcher_win.cc. |
121 virtual base::Time Now() const = 0; | 128 virtual base::Time Now() const = 0; |
122 | 129 |
123 // A task runner used to spawn the reporter process (which blocks). | 130 // A task runner used to spawn the reporter process (which blocks). |
| 131 // See ReporterRunner::ScheduleNextInvocation(). |
124 virtual base::TaskRunner* BlockingTaskRunner() const = 0; | 132 virtual base::TaskRunner* BlockingTaskRunner() const = 0; |
| 133 |
| 134 // Returns a ChromePromptImpl object that keeps track of specific |
| 135 // actions during tests. Replaces the object returned by |
| 136 // SwReporterProcess::CreateChromePromptImpl(). |
| 137 // See SwReporterProcess::LaunchConnectedReporterProcess(). |
| 138 virtual std::unique_ptr<ChromePromptImpl> CreateChromePromptImpl( |
| 139 chrome_cleaner::mojom::ChromePromptRequest request) = 0; |
| 140 |
| 141 // Connection closed callback defined by tests in place of the default |
| 142 // error handler. See SRTFetcherTest::CreateChromePromptImpl(). |
| 143 virtual void OnConnectionClosed() = 0; |
| 144 |
| 145 // Bad message handler callback defined by tests in place of the default |
| 146 // error handler. See SwReporterProcess::LaunchConnectedReporterProcess(). |
| 147 virtual void OnConnectionError(const std::string& message) = 0; |
125 }; | 148 }; |
126 | 149 |
127 // Set a delegate for testing. The implementation will not take ownership of | 150 // Set a delegate for testing. The implementation will not take ownership of |
128 // |delegate| - it must remain valid until this function is called again to | 151 // |delegate| - it must remain valid until this function is called again to |
129 // reset the delegate. If |delegate| is nullptr, any previous delegate is | 152 // reset the delegate. If |delegate| is nullptr, any previous delegate is |
130 // cleared. | 153 // cleared. |
131 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate); | 154 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate); |
132 | 155 |
133 void DisplaySRTPromptForTesting(const base::FilePath& download_path); | 156 void DisplaySRTPromptForTesting(const base::FilePath& download_path); |
134 | 157 |
135 } // namespace safe_browsing | 158 } // namespace safe_browsing |
136 | 159 |
137 #endif // CHROME_BROWSER_SAFE_BROWSING_SRT_FETCHER_WIN_H_ | 160 #endif // CHROME_BROWSER_SAFE_BROWSING_SRT_FETCHER_WIN_H_ |
OLD | NEW |