Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1892)

Unified Diff: chrome/browser/background/background_contents_service.cc

Issue 2281323002: Use exponential backoff for component extension reloads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/background/background_contents_service.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/background/background_contents_service.cc
diff --git a/chrome/browser/background/background_contents_service.cc b/chrome/browser/background/background_contents_service.cc
index 47a69eda6b586272eeffb8ca4a0479b31537ea22..95175e6462bd03276b949126c0e2c7f479d59dcc 100644
--- a/chrome/browser/background/background_contents_service.cc
+++ b/chrome/browser/background/background_contents_service.cc
@@ -263,6 +263,18 @@ void ReloadExtension(const std::string& extension_id, Profile* profile) {
const char kUrlKey[] = "url";
const char kFrameNameKey[] = "name";
+// Defines the backoff policy used for attempting to reload extensions.
+const net::BackoffEntry::Policy kExtensionReloadBackoffPolicy = {
+ 0, // Initial errors to ignore before applying backoff.
+ 3000, // Initial delay: 3 seconds.
+ 2, // Multiply factor.
+ 0.1, // Fuzzing percentage.
+ -1, // Maximum backoff time: -1 for no maximum.
+ -1, // Entry lifetime: -1 to never discard.
+ false, // Whether to always use initial delay. No-op as there are
+ // no initial errors to ignore.
+};
+
int BackgroundContentsService::restart_delay_in_ms_ = 3000; // 3 seconds.
BackgroundContentsService::BackgroundContentsService(
@@ -523,9 +535,34 @@ void BackgroundContentsService::OnExtensionUninstalled(
void BackgroundContentsService::RestartForceInstalledExtensionOnCrash(
const Extension* extension,
Profile* profile) {
+ int restart_delay = restart_delay_in_ms_;
+
+ // If the extension was a non-policy installed, component extension, use
Andrew T Wilson (Slow) 2016/08/29 07:53:47 I'm not convinced this is the right approach (addi
apacible 2016/08/29 16:40:11 Component extensions are loaded automatically (and
+ // exponential backoff when attempting to reload.
+ if (extensions::Manifest::IsComponentLocation(extension->location()) &&
+ !extensions::Manifest::IsPolicyLocation(extension->location())) {
Andrew T Wilson (Slow) 2016/08/29 07:53:47 I don't understand this - what extensions are *bot
apacible 2016/08/29 16:40:11 Good catch, it's just one or the other (as extensi
+ ExtensionBackoffEntryMap::const_iterator it =
+ backoff_map_.find(extension->id());
+ net::BackoffEntry* backoff_entry;
+
+ // Create a BackoffEntry if this is the first time we try to reload this
+ // particular extension.
+ if (it == backoff_map_.end()) {
+ backoff_entry = new net::BackoffEntry(&kExtensionReloadBackoffPolicy);
+ backoff_map_.insert(
+ std::pair<extensions::ExtensionId, net::BackoffEntry*>(
+ extension->id(), backoff_entry));
+ } else {
+ backoff_entry = it->second;
+ }
+
+ backoff_entry->InformOfRequest(false);
+ restart_delay = backoff_entry->GetTimeUntilRelease().InMilliseconds();
+ }
+
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, base::Bind(&ReloadExtension, extension->id(), profile),
- base::TimeDelta::FromMilliseconds(restart_delay_in_ms_));
+ base::TimeDelta::FromMilliseconds(restart_delay));
}
// Loads all background contents whose urls have been stored in prefs.
« no previous file with comments | « chrome/browser/background/background_contents_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698