Chromium Code Reviews| 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..52d401d5ecf1f37403302fe11cb02a187c7b7067 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,33 @@ void BackgroundContentsService::OnExtensionUninstalled( |
| void BackgroundContentsService::RestartForceInstalledExtensionOnCrash( |
| const Extension* extension, |
| Profile* profile) { |
| + int restart_delay = restart_delay_in_ms_; |
| + |
| + // If the extension was a component extension, use exponential backoff when |
| + // attempting to reload. |
| + if (extensions::Manifest::IsComponentLocation(extension->location())) { |
| + ExtensionBackoffEntryMap::const_iterator it = |
| + backoff_map_.find(extension->id()); |
| + |
| + // Create a BackoffEntry if this is the first time we try to reload this |
| + // particular extension. |
| + if (it == backoff_map_.end()) { |
| + std::unique_ptr<net::BackoffEntry> backoff_entry( |
| + new net::BackoffEntry(&kExtensionReloadBackoffPolicy)); |
| + backoff_map_.insert( |
|
Wez
2016/09/01 21:47:58
You're inserting a new entry into backoff_map_ her
apacible
2016/09/02 00:20:32
Good catch. I'll address this in a follow up CL.
|
| + std::pair<extensions::ExtensionId, |
| + std::unique_ptr<net::BackoffEntry>>( |
| + extension->id(), std::move(backoff_entry))); |
| + } |
| + |
| + net::BackoffEntry* entry = backoff_map_[extension->id()].get(); |
| + entry->InformOfRequest(false); |
| + restart_delay = entry->GetTimeUntilRelease().InMilliseconds(); |
|
Wez
2016/09/01 21:47:58
When do we re-set the backoff for an extension, if
apacible
2016/09/02 00:20:32
We currently do not reset the backoff within the s
|
| + } |
| + |
| 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. |