Clean up srt_fetcher_win.cc |
|||||||
Issue description
In a recent code review we identified a lot of cleanups that should be made to srt_fetcher_win.cc:
1.
It creates RegKey's with KEY_ALL_ACCESS. The common pattern is to read the value of the key, report it through UMA, and then delete the value. They only need KEY_QUERY_VALUE and KEY_SET_VALUE access for his.
Also, the constructor used will create the key if it doesn't already exist. To avoid that, construct an empty RegKey and then use Open. First, though, check to make sure we don't depend on this behaviour (for instance maybe we rely on the key existing with a default value).
2.
UMAHistogramReporter has a lot of methods that are always called together in the same order from ReporterDone. These could all be merged into a ReportResults function.
3.
TryToRun starts with:
if (!version_.IsValid() || !local_state) {
DCHECK(first_run_);
return;
}
Which looks bogus. Even on first run, version should be valid. And we should return if local_state is unavailable (because there's no way to check the last run time) but this has nothing to do with first_run.
4.
ScheduleInvocations checks if the invocations parameter matches pending_invocations_, and returns early if so. This is useless complexity, because the only thing that happens after is that invocations is assigned to pending_invocations_ so that it will be used next time TryToRun is called. So if they already match, overwriting pending_invocations_ doesn't change the state anyway.
(Also, version_ should use the same pattern as pending_invocations_ - have pending_version_ and current_version_. Right now version_ is copied into a bound parameter of ReporterDone, which is why overwriting it in ScheduleInvocations won't have any effect on the currently executing reporter. But it would be clearer to handle version and invocations in the same way.)
5.
The use of both blocking_task_runner and main_thread_task_runner is really confusing. main_thread_task_runner is the UI thread in the main app. The only reason it's used instead of posting to the UI thread directly is so that it can be overridden in the unit tests. But I'm pretty sure the only things that need to run on the UI thread are ReporterRunner::ScheduleInvocations and MaybeFetchSRT (which isn't called from the unit test). So I would use a single task_runner for the blocking LaunchAndWaitForExit method, and have Run dispatch the first TryToRun call to that task_runner. Then ReporterDone would explicitly dispatch MaybeFetchSRT to the UI thread and call TryToRun again on the same task_runner. Then the unit test only needs to override one task runner.
6.
The file is called srt_fetcher_win.cc, but most of the code in it deals with running the software reporter and recording the results. Fetching the SRT and showing the prompt is only one of the things which happens based on the reporter results. UMAHistogramReporter, ReporterRunner, SwReporterInvocation and RunSwReporters should really move to their own file.
,
Sep 13 2016
,
Sep 16 2016
,
Dec 20 2016
While doing this, we should add more unit testing of histogram reporting. We can use base/test/histogram_tester.h for this.
,
Feb 24 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/171b102f8145fffe0cb58f72d8f78e20598f3ba1 commit 171b102f8145fffe0cb58f72d8f78e20598f3ba1 Author: joenotcharles <joenotcharles@chromium.org> Date: Fri Feb 24 21:13:13 2017 Update SRTFetcher browser test to use TestMockTimeTaskRunner. This allows us to simplify the interface by eliminating main_thread_task_runner and moving blocking_task_runner to SwReporterTestingDelegate with the rest of the test overrides. The browser test now knows much less about the internal implementation of ReporterRunner, too. BUG= 641081 CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.win:win10_chromium_x64_rel_ng Review-Url: https://codereview.chromium.org/2700233002 Cr-Commit-Position: refs/heads/master@{#452917} [modify] https://crrev.com/171b102f8145fffe0cb58f72d8f78e20598f3ba1/chrome/browser/component_updater/sw_reporter_installer_win.cc [modify] https://crrev.com/171b102f8145fffe0cb58f72d8f78e20598f3ba1/chrome/browser/safe_browsing/srt_fetcher_browsertest_win.cc [modify] https://crrev.com/171b102f8145fffe0cb58f72d8f78e20598f3ba1/chrome/browser/safe_browsing/srt_fetcher_win.cc [modify] https://crrev.com/171b102f8145fffe0cb58f72d8f78e20598f3ba1/chrome/browser/safe_browsing/srt_fetcher_win.h
,
Apr 21 2017
,
Apr 12 2018
,
Apr 13 2018
,
Jul 23
Split the RegKey issue into https://bugs.chromium.org/p/chromium/issues/detail?id=866462
,
Jul 23
The other issues have either been fixed or obsoleted by other code refactoring. |
|||||||
►
Sign in to add a comment |
|||||||
Comment 1 by joenotcharles@chromium.org
, Sep 13 2016