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 | 10 |
| 11 #include <memory> |
| 12 #include <queue> |
10 #include <string> | 13 #include <string> |
11 | 14 |
12 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
13 #include "base/command_line.h" | 16 #include "base/command_line.h" |
14 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
15 #include "base/version.h" | 18 #include "base/version.h" |
16 | 19 |
17 namespace base { | 20 namespace base { |
18 class FilePath; | 21 class FilePath; |
19 class TaskRunner; | 22 class TaskRunner; |
(...skipping 23 matching lines...) Expand all Loading... |
43 | 46 |
44 // Parameters used to invoke the sw_reporter component. | 47 // Parameters used to invoke the sw_reporter component. |
45 struct SwReporterInvocation { | 48 struct SwReporterInvocation { |
46 base::CommandLine command_line; | 49 base::CommandLine command_line; |
47 | 50 |
48 // Experimental versions of the reporter will write metrics to registry keys | 51 // Experimental versions of the reporter will write metrics to registry keys |
49 // ending in |suffix|. Those metrics should be copied to UMA histograms also | 52 // ending in |suffix|. Those metrics should be copied to UMA histograms also |
50 // ending in |suffix|. For the canonical version, |suffix| will be empty. | 53 // ending in |suffix|. For the canonical version, |suffix| will be empty. |
51 std::string suffix; | 54 std::string suffix; |
52 | 55 |
53 // The experimental sw_reporter never triggers the prompt, just reports | 56 // Flags to control optional behaviours. By default all are enabled; |
54 // results through UMA. | 57 // experimental versions of the reporter will turn off the behaviours that |
55 bool is_experimental = false; | 58 // are not yet supported. |
| 59 using Flags = uint32_t; |
| 60 enum : Flags { |
| 61 FLAG_LOG_TO_RAPPOR = 0x1, |
| 62 FLAG_LOG_TO_PREFS = 0x2, |
| 63 FLAG_TRIGGER_PROMPT = 0x4, |
| 64 }; |
| 65 Flags flags = FLAG_LOG_TO_RAPPOR | FLAG_LOG_TO_PREFS | FLAG_TRIGGER_PROMPT; |
56 | 66 |
57 SwReporterInvocation(); | 67 SwReporterInvocation(); |
58 | 68 |
59 static SwReporterInvocation FromFilePath(const base::FilePath& exe_path); | 69 static SwReporterInvocation FromFilePath(const base::FilePath& exe_path); |
60 static SwReporterInvocation FromCommandLine( | 70 static SwReporterInvocation FromCommandLine( |
61 const base::CommandLine& command_line); | 71 const base::CommandLine& command_line); |
62 | 72 |
63 bool operator==(const SwReporterInvocation& other) const; | 73 bool operator==(const SwReporterInvocation& other) const; |
64 }; | 74 }; |
65 | 75 |
| 76 using SwReporterQueue = std::queue<SwReporterInvocation>; |
| 77 |
66 // Tries to run the sw_reporter component, and then schedule the next try. If | 78 // Tries to run the sw_reporter component, and then schedule the next try. If |
67 // called multiple times, then multiple sequences of trying to run will happen, | 79 // called multiple times, then multiple sequences of trying to run will happen, |
68 // yet only one reporter will run per specified period (either | 80 // yet only one SwReporterQueue will actually run per specified period (either |
69 // |kDaysBetweenSuccessfulSwReporterRuns| or | 81 // |kDaysBetweenSuccessfulSwReporterRuns| or |
70 // |kDaysBetweenSwReporterRunsForPendingPrompt|) will actually happen. | 82 // |kDaysBetweenSwReporterRunsForPendingPrompt|). |
71 // |invocation| is the details of the SwReporter to execute, and |version| is | 83 // |
72 // its version. The task runners are provided to allow tests to provide their | 84 // Each "run" of the sw_reporter component may aggregate the results of several |
73 // own. | 85 // executions of the tool with different command lines. |invocations| is the |
74 void RunSwReporter(const SwReporterInvocation& invocation, | 86 // queue of SwReporters to execute as a single "run". When a new try is |
75 const base::Version& version, | 87 // scheduled the entire queue is executed. |
76 scoped_refptr<base::TaskRunner> main_thread_task_runner, | 88 // |
77 scoped_refptr<base::TaskRunner> blocking_task_runner); | 89 // |version| is the version of the tool that will run. The task runners are |
| 90 // provided to allow tests to provide their own. |
| 91 void RunSwReporters(const SwReporterQueue& invocations, |
| 92 const base::Version& version, |
| 93 scoped_refptr<base::TaskRunner> main_thread_task_runner, |
| 94 scoped_refptr<base::TaskRunner> blocking_task_runner); |
78 | 95 |
79 // Returns true iff Local State is successfully accessed and indicates the most | 96 // Returns true iff Local State is successfully accessed and indicates the most |
80 // recent Reporter run terminated with an exit code indicating the presence of | 97 // recent Reporter run terminated with an exit code indicating the presence of |
81 // UwS. | 98 // UwS. |
82 bool ReporterFoundUws(); | 99 bool ReporterFoundUws(); |
83 | 100 |
84 // Returns true iff a valid registry key for the SRT Cleaner exists, and that | 101 // Returns true iff a valid registry key for the SRT Cleaner exists, and that |
85 // key is nonempty. | 102 // key is nonempty. |
86 // TODO(tmartino): Consider changing to check whether the user has recently | 103 // TODO(tmartino): Consider changing to check whether the user has recently |
87 // run the cleaner, rather than checking if they've run it at all. | 104 // run the cleaner, rather than checking if they've run it at all. |
(...skipping 20 matching lines...) Expand all Loading... |
108 | 125 |
109 // Set a delegate for testing. The implementation will not take ownership of | 126 // Set a delegate for testing. The implementation will not take ownership of |
110 // |delegate| - it must remain valid until this function is called again to | 127 // |delegate| - it must remain valid until this function is called again to |
111 // reset the delegate. If |delegate| is nullptr, any previous delegate is | 128 // reset the delegate. If |delegate| is nullptr, any previous delegate is |
112 // cleared. | 129 // cleared. |
113 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate); | 130 void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate); |
114 | 131 |
115 } // namespace safe_browsing | 132 } // namespace safe_browsing |
116 | 133 |
117 #endif // CHROME_BROWSER_SAFE_BROWSING_SRT_FETCHER_WIN_H_ | 134 #endif // CHROME_BROWSER_SAFE_BROWSING_SRT_FETCHER_WIN_H_ |
OLD | NEW |