| Index: chrome/browser/component_updater/sw_reporter_installer_win.cc
|
| diff --git a/chrome/browser/component_updater/sw_reporter_installer_win.cc b/chrome/browser/component_updater/sw_reporter_installer_win.cc
|
| index f1b914ef6b66f47c79d2c2b58ca4433cab6f50cb..5f8283c7ea8b38f031ce5379c631504714e8c2b7 100644
|
| --- a/chrome/browser/component_updater/sw_reporter_installer_win.cc
|
| +++ b/chrome/browser/component_updater/sw_reporter_installer_win.cc
|
| @@ -23,8 +23,11 @@
|
| #include "base/process/launch.h"
|
| #include "base/task_runner_util.h"
|
| #include "base/threading/worker_pool.h"
|
| +#include "base/time/time.h"
|
| #include "base/win/registry.h"
|
| #include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/metrics/chrome_metrics_service_accessor.h"
|
| +#include "chrome/common/pref_names.h"
|
| #include "components/component_updater/component_updater_paths.h"
|
| #include "components/component_updater/component_updater_service.h"
|
| #include "components/component_updater/component_updater_utils.h"
|
| @@ -54,6 +57,9 @@ enum SwReporterUmaValue {
|
| // The maximum number of times to retry a download on startup.
|
| const int kMaxRetry = 20;
|
|
|
| +// The number of days to wait before triggering another sw reporter run.
|
| +const int kDaysBetweenSwReporterRuns = 7;
|
| +
|
| // CRX hash. The extension id is: gkmgaooipdjhmangpemjhigmamcehddo. The hash was
|
| // generated in Python with something like this:
|
| // hashlib.sha256().update(open("<file>.crx").read()[16:16+294]).digest().
|
| @@ -220,6 +226,9 @@ void ExecuteSwReporter(ComponentUpdateService* cus, PrefService* prefs) {
|
| // execution attempts and start from scratch.
|
| prefs->SetInteger(prefs::kSwReporterExecuteTryCount, kMaxRetry);
|
| ReportUmaStep(SW_REPORTER_EXPLICIT_REQUEST);
|
| + // Record the requested trigger time.
|
| + prefs->SetInt64(prefs::kSwReporterLastTimeTriggered,
|
| + base::Time::Now().ToInternalValue());
|
| const std::vector<std::string> registered_components(cus->GetComponentIDs());
|
| if (std::find(registered_components.begin(),
|
| registered_components.end(),
|
| @@ -238,9 +247,14 @@ void ExecuteSwReporter(ComponentUpdateService* cus, PrefService* prefs) {
|
| // reporter when ComponentReady is called.
|
| }
|
|
|
| -void ExecutePendingSwReporter(ComponentUpdateService* cus, PrefService* prefs) {
|
| +void ExecuteSwReporterIfRequired(ComponentUpdateService* cus,
|
| + PrefService* prefs) {
|
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
|
|
| + // The Sw reporter shouldn't run if the user isn't reporting metrics.
|
| + if (!ChromeMetricsServiceAccessor::IsMetricsReportingEnabled())
|
| + return;
|
| +
|
| // Register the existing component for updates.
|
| base::PostTaskAndReplyWithResult(
|
| BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE),
|
| @@ -272,10 +286,20 @@ void ExecutePendingSwReporter(ComponentUpdateService* cus, PrefService* prefs) {
|
| else
|
| ReportUmaStep(SW_REPORTER_RETRIED_TOO_MANY_TIMES);
|
| }
|
| +
|
| + // Run the reporter if it hasn't been triggered in the last
|
| + // kDaysBetweenSwReporterRuns days.
|
| + const base::Time last_time_triggered = base::Time::FromInternalValue(
|
| + prefs->GetInt64(prefs::kSwReporterLastTimeTriggered));
|
| + if ((base::Time::Now() - last_time_triggered).InDays() >=
|
| + kDaysBetweenSwReporterRuns) {
|
| + ExecuteSwReporter(cus, prefs);
|
| + }
|
| }
|
|
|
| void RegisterPrefsForSwReporter(PrefRegistrySimple* registry) {
|
| registry->RegisterIntegerPref(prefs::kSwReporterExecuteTryCount, 0);
|
| + registry->RegisterInt64Pref(prefs::kSwReporterLastTimeTriggered, 0);
|
| }
|
|
|
| } // namespace component_updater
|
|
|