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