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