Chromium Code Reviews| 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..7be845cb0c66c9a7b51871a763ad747031a02fea 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,7 +247,8 @@ 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)); |
| // Register the existing component for updates. |
| @@ -272,10 +282,21 @@ 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 and the user is opted-in to UMA. |
| + const base::Time last_time_triggered = base::Time::FromInternalValue( |
| + prefs->GetInt64(prefs::kSwReporterLastTimeTriggered)); |
| + if ((base::Time::Now() - last_time_triggered).InDays() >= |
| + kDaysBetweenSwReporterRuns && |
| + ChromeMetricsServiceAccessor::IsMetricsReportingEnabled()) { |
|
MAD
2014/08/21 15:12:25
I would move the check for metrics outward so that
csharp
2014/08/21 17:13:59
I moved this check to the top of the function and
|
| + ExecuteSwReporter(cus, prefs); |
| + } |
| } |
| void RegisterPrefsForSwReporter(PrefRegistrySimple* registry) { |
| registry->RegisterIntegerPref(prefs::kSwReporterExecuteTryCount, 0); |
| + registry->RegisterInt64Pref(prefs::kSwReporterLastTimeTriggered, 0); |
| } |
| } // namespace component_updater |