Chromium Code Reviews| Index: chrome/browser/extensions/chrome_content_verifier_delegate.cc |
| diff --git a/chrome/browser/extensions/chrome_content_verifier_delegate.cc b/chrome/browser/extensions/chrome_content_verifier_delegate.cc |
| index d6ea2c6af5de5f0ca117ef299d4580447feb2da4..9acc93869a0240ff19feccc86b1f1569eff4d14a 100644 |
| --- a/chrome/browser/extensions/chrome_content_verifier_delegate.cc |
| +++ b/chrome/browser/extensions/chrome_content_verifier_delegate.cc |
| @@ -11,10 +11,12 @@ |
| #include "base/base_switches.h" |
| #include "base/command_line.h" |
| -#include "base/syslog_logging.h" |
| +#include "base/lazy_instance.h" |
| #include "base/metrics/field_trial.h" |
| #include "base/metrics/histogram_macros.h" |
| #include "base/strings/string_util.h" |
| +#include "base/syslog_logging.h" |
| +#include "base/threading/thread_task_runner_handle.h" |
| #include "base/version.h" |
| #include "build/build_config.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| @@ -30,6 +32,7 @@ |
| #include "extensions/common/extensions_client.h" |
| #include "extensions/common/manifest.h" |
| #include "extensions/common/manifest_url_handlers.h" |
| +#include "net/base/backoff_entry.h" |
| #include "net/base/escape.h" |
| #if defined(OS_CHROMEOS) |
| @@ -41,6 +44,33 @@ namespace { |
| const char kContentVerificationExperimentName[] = |
| "ExtensionContentVerification"; |
| +const net::BackoffEntry::Policy kPolicyReinstallBackoffPolicy = { |
| + // num_errors_to_ignore |
| + 1, |
| + |
| + // initial_delay_ms (note that we set 'always_use_initial_delay' to false |
| + // below) |
| + 100, |
| + |
| + // multiply_factor |
| + 2, |
| + |
| + // jitter_factor |
| + 0.1, |
| + |
| + // maximum_backoff_ms (30 minutes) |
| + 1000 * 60 * 30, |
| + |
| + // entry_lifetime_ms (6 hours) |
| + 1000 * 60 * 60 * 6, |
| + |
| + // always_use_initial_delay |
| + false, |
| +}; |
| + |
| +base::LazyInstance<base::Callback<void(base::TimeDelta delay)>> |
|
Devlin
2016/11/29 22:31:24
Any need for this to a be a lazy instance rather t
asargent_no_longer_on_chrome
2016/11/30 00:11:48
I think I did it this way out of habit because we
|
| + g_reinstall_action_for_test = LAZY_INSTANCE_INITIALIZER; |
| + |
| } // namespace |
| namespace extensions { |
| @@ -186,7 +216,27 @@ void ChromeContentVerifierDelegate::VerifyFailed( |
| << extension->path().value(); |
| pending_manager->ExpectPolicyReinstallForCorruption(extension_id); |
| service->DisableExtension(extension_id, Extension::DISABLE_CORRUPTED); |
| - service->CheckForExternalUpdates(); |
| + |
| + net::BackoffEntry* backoff_entry = nullptr; |
| + auto iter = policy_reinstall_backoff_.find(extension_id); |
| + if (iter != policy_reinstall_backoff_.end()) { |
| + backoff_entry = iter->second.get(); |
| + } else { |
| + policy_reinstall_backoff_[extension_id] = |
| + base::MakeUnique<net::BackoffEntry>(&kPolicyReinstallBackoffPolicy); |
| + backoff_entry = policy_reinstall_backoff_[extension_id].get(); |
|
Devlin
2016/11/29 22:31:24
nit: you could avoid a double look-up with either:
asargent_no_longer_on_chrome
2016/11/30 00:11:48
Done.
|
| + } |
| + backoff_entry->InformOfRequest(false); |
| + |
| + base::TimeDelta reinstall_delay = backoff_entry->GetTimeUntilRelease(); |
| + if (!g_reinstall_action_for_test.Get().is_null()) { |
| + g_reinstall_action_for_test.Get().Run(reinstall_delay); |
| + } else { |
| + base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| + FROM_HERE, base::Bind(&ExtensionService::CheckForExternalUpdates, |
| + service->AsWeakPtr()), |
| + reinstall_delay); |
| + } |
| return; |
| } |
| DLOG(WARNING) << "Disabling extension " << extension_id << " ('" |
| @@ -205,5 +255,10 @@ void ChromeContentVerifierDelegate::VerifyFailed( |
| } |
| } |
| +// static |
| +void ChromeContentVerifierDelegate::set_policy_reinstall_action_for_test( |
| + base::Callback<void(base::TimeDelta delay)> action) { |
| + g_reinstall_action_for_test.Get() = action; |
| +} |
| } // namespace extensions |