1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SAFE_BROWSING_SRT_FETCHER_WIN_H_
#define CHROME_BROWSER_SAFE_BROWSING_SRT_FETCHER_WIN_H_
#include <limits.h>
#include <stdint.h>
#include <queue>
#include <string>
#include "base/callback_forward.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/memory/ref_counted.h"
#include "base/version.h"
namespace base {
class FilePath;
class TaskRunner;
}
class Browser;
namespace safe_browsing {
// SRT registry keys and value names.
extern const wchar_t kSoftwareRemovalToolRegistryKey[];
extern const wchar_t kEndTimeValueName[];
extern const wchar_t kStartTimeValueName[];
// Reporter exit codes.
const int kSwReporterCleanupNeeded = 0;
const int kSwReporterNothingFound = 2;
const int kSwReporterPostRebootCleanupNeeded = 4;
const int kSwReporterDelayedPostRebootCleanupNeeded = 15;
// A special exit code identifying a failure to run the reporter.
const int kReporterFailureExitCode = INT_MAX;
// The number of days to wait before triggering another reporter run.
const int kDaysBetweenSuccessfulSwReporterRuns = 7;
const int kDaysBetweenSwReporterRunsForPendingPrompt = 1;
// The number of days to wait before sending out reporter logs.
const int kDaysBetweenReporterLogsSent = 7;
// Parameters used to invoke the sw_reporter component.
struct SwReporterInvocation {
base::CommandLine command_line;
// Experimental versions of the reporter will write metrics to registry keys
// ending in |suffix|. Those metrics should be copied to UMA histograms also
// ending in |suffix|. For the canonical version, |suffix| will be empty.
std::string suffix;
// Flags to control behaviours the Software Reporter should support by
// default. These flags are set in the Reporter installer, and experimental
// versions of the reporter will turn on the behaviours that are not yet
// supported.
using Behaviours = uint32_t;
enum : Behaviours {
BEHAVIOUR_LOG_TO_RAPPOR = 0x1,
BEHAVIOUR_LOG_EXIT_CODE_TO_PREFS = 0x2,
BEHAVIOUR_TRIGGER_PROMPT = 0x4,
BEHAVIOUR_ALLOW_SEND_REPORTER_LOGS = 0x8,
};
Behaviours supported_behaviours = 0;
// Whether logs upload was enabled in this invocation.
bool logs_upload_enabled = false;
SwReporterInvocation();
static SwReporterInvocation FromFilePath(const base::FilePath& exe_path);
static SwReporterInvocation FromCommandLine(
const base::CommandLine& command_line);
bool operator==(const SwReporterInvocation& other) const;
bool BehaviourIsSupported(Behaviours intended_behaviour) const;
};
using SwReporterQueue = std::queue<SwReporterInvocation>;
// Tries to run the sw_reporter component, and then schedule the next try. If
// called multiple times, then multiple sequences of trying to run will happen,
// yet only one SwReporterQueue will actually run per specified period (either
// |kDaysBetweenSuccessfulSwReporterRuns| or
// |kDaysBetweenSwReporterRunsForPendingPrompt|).
//
// Each "run" of the sw_reporter component may aggregate the results of several
// executions of the tool with different command lines. |invocations| is the
// queue of SwReporters to execute as a single "run". When a new try is
// scheduled the entire queue is executed.
//
// |version| is the version of the tool that will run. The task runners are
// provided to allow tests to provide their own.
void RunSwReporters(const SwReporterQueue& invocations,
const base::Version& version,
scoped_refptr<base::TaskRunner> main_thread_task_runner,
scoped_refptr<base::TaskRunner> blocking_task_runner);
// Returns true iff Local State is successfully accessed and indicates the most
// recent Reporter run terminated with an exit code indicating the presence of
// UwS.
bool ReporterFoundUws();
// Returns true iff a valid registry key for the SRT Cleaner exists, and that
// key is nonempty.
// TODO(tmartino): Consider changing to check whether the user has recently
// run the cleaner, rather than checking if they've run it at all.
bool UserHasRunCleaner();
// Mocks and callbacks for the unit tests.
class SwReporterTestingDelegate {
public:
virtual ~SwReporterTestingDelegate() {}
// Test mock for launching the reporter.
virtual int LaunchReporter(const SwReporterInvocation& invocation) = 0;
// Test mock for showing the prompt.
virtual void TriggerPrompt(Browser* browser,
const std::string& reporter_version) = 0;
// Callback to let the tests know the reporter is ready to launch.
virtual void NotifyLaunchReady() = 0;
// Callback to let the tests know the reporter has finished running.
virtual void NotifyReporterDone() = 0;
};
// Set a delegate for testing. The implementation will not take ownership of
// |delegate| - it must remain valid until this function is called again to
// reset the delegate. If |delegate| is nullptr, any previous delegate is
// cleared.
void SetSwReporterTestingDelegate(SwReporterTestingDelegate* delegate);
} // namespace safe_browsing
#endif // CHROME_BROWSER_SAFE_BROWSING_SRT_FETCHER_WIN_H_
|