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

Side by Side Diff: chrome/browser/safe_browsing/srt_fetcher_win.h

Issue 2846333003: Chrome cleaner: move Chrome Cleaner files to their own directory (Closed)
Patch Set: 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 2015 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_SRT_FETCHER_WIN_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_SRT_FETCHER_WIN_H_
7
8 #include <limits.h>
9 #include <stdint.h>
10
11 #include <queue>
12 #include <string>
13
14 #include "base/command_line.h"
15 #include "base/feature_list.h"
16 #include "base/process/launch.h"
17 #include "base/process/process.h"
18 #include "base/time/time.h"
19 #include "components/chrome_cleaner/public/interfaces/chrome_prompt.mojom.h"
20
21 namespace base {
22 class FilePath;
23 class TaskRunner;
24 class Version;
25 }
26
27 class Browser;
28
29 namespace safe_browsing {
30
31 class ChromePromptImpl;
32
33 // A special exit code identifying a failure to run the reporter.
34 const int kReporterNotLaunchedExitCode = INT_MAX;
35
36 // The number of days to wait before triggering another reporter run.
37 const int kDaysBetweenSuccessfulSwReporterRuns = 7;
38 const int kDaysBetweenSwReporterRunsForPendingPrompt = 1;
39 // The number of days to wait before sending out reporter logs.
40 const int kDaysBetweenReporterLogsSent = 7;
41
42 // When enabled, moves all user interaction with the Software Reporter and the
43 // Chrome Cleanup tool to Chrome.
44 extern const base::Feature kInBrowserCleanerUIFeature;
45
46 // Parameters used to invoke the sw_reporter component.
47 struct SwReporterInvocation {
48 base::CommandLine command_line;
49
50 // Experimental versions of the reporter will write metrics to registry keys
51 // ending in |suffix|. Those metrics should be copied to UMA histograms also
52 // ending in |suffix|. For the canonical version, |suffix| will be empty.
53 std::string suffix;
54
55 // Flags to control behaviours the Software Reporter should support by
56 // default. These flags are set in the Reporter installer, and experimental
57 // versions of the reporter will turn on the behaviours that are not yet
58 // supported.
59 using Behaviours = uint32_t;
60 enum : Behaviours {
61 BEHAVIOUR_LOG_EXIT_CODE_TO_PREFS = 0x2,
62 BEHAVIOUR_TRIGGER_PROMPT = 0x4,
63 BEHAVIOUR_ALLOW_SEND_REPORTER_LOGS = 0x8,
64 };
65 Behaviours supported_behaviours = 0;
66
67 // Whether logs upload was enabled in this invocation.
68 bool logs_upload_enabled = false;
69
70 SwReporterInvocation();
71
72 static SwReporterInvocation FromFilePath(const base::FilePath& exe_path);
73 static SwReporterInvocation FromCommandLine(
74 const base::CommandLine& command_line);
75
76 bool operator==(const SwReporterInvocation& other) const;
77
78 bool BehaviourIsSupported(Behaviours intended_behaviour) const;
79 };
80
81 using SwReporterQueue = std::queue<SwReporterInvocation>;
82
83 // Tries to run the sw_reporter component, and then schedule the next try. If
84 // called multiple times, then multiple sequences of trying to run will happen,
85 // yet only one SwReporterQueue will actually run per specified period (either
86 // |kDaysBetweenSuccessfulSwReporterRuns| or
87 // |kDaysBetweenSwReporterRunsForPendingPrompt|).
88 //
89 // Each "run" of the sw_reporter component may aggregate the results of several
90 // executions of the tool with different command lines. |invocations| is the
91 // queue of SwReporters to execute as a single "run". When a new try is
92 // scheduled the entire queue is executed.
93 //
94 // |version| is the version of the tool that will run.
95 void RunSwReporters(const SwReporterQueue& invocations,
96 const base::Version& version);
97
98 // Returns true iff Local State is successfully accessed and indicates the most
99 // recent Reporter run terminated with an exit code indicating the presence of
100 // UwS.
101 bool ReporterFoundUws();
102
103 // Returns true iff a valid registry key for the SRT Cleaner exists, and that
104 // key is nonempty.
105 // TODO(tmartino): Consider changing to check whether the user has recently
106 // run the cleaner, rather than checking if they've run it at all.
107 bool UserHasRunCleaner();
108
109 // A delegate used by tests to implement test doubles (e.g., stubs, fakes, or
110 // mocks).
111 class SwReporterTestingDelegate {
112 public:
113 virtual ~SwReporterTestingDelegate() {}
114
115 // Invoked by tests in places of base::LaunchProcess.
116 // See chrome_cleaner::mojom::ChromePromptRequest().
117 virtual base::Process LaunchReporter(
118 const SwReporterInvocation& invocation,
119 const base::LaunchOptions& launch_options) = 0;
120
121 // Invoked by tests in place of the actual prompting logic.
122 // See MaybeFetchSRT().
123 virtual void TriggerPrompt(Browser* browser,
124 const std::string& reporter_version) = 0;
125
126 // Invoked by tests to override the current time.
127 // See Now() in srt_fetcher_win.cc.
128 virtual base::Time Now() const = 0;
129
130 // A task runner used to spawn the reporter process (which blocks).
131 // See ReporterRunner::ScheduleNextInvocation().
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;
148 };
149
150 // Set a delegate for testing. The implementation will not take ownership of
151 // |delegate| - it must remain valid until this function is called again to
152 // reset the delegate. If |delegate| is nullptr, any previous delegate is
153 // cleared.
154 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate);
155
156 void DisplaySRTPromptForTesting(const base::FilePath& download_path);
157
158 } // namespace safe_browsing
159
160 #endif // CHROME_BROWSER_SAFE_BROWSING_SRT_FETCHER_WIN_H_
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/srt_fetcher_browsertest_win.cc ('k') | chrome/browser/safe_browsing/srt_fetcher_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698