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

Side by Side 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: Changes per atwilson@'s comments. Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/background/background_contents_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/background/background_contents_service.h" 5 #include "chrome/browser/background/background_contents_service.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "apps/app_load_service.h" 9 #include "apps/app_load_service.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 // 256 //
257 // kRegisteredBackgroundContents: 257 // kRegisteredBackgroundContents:
258 // DictionaryValue { 258 // DictionaryValue {
259 // <appid_1>: { "url": <url1>, "name": <frame_name> }, 259 // <appid_1>: { "url": <url1>, "name": <frame_name> },
260 // <appid_2>: { "url": <url2>, "name": <frame_name> }, 260 // <appid_2>: { "url": <url2>, "name": <frame_name> },
261 // ... etc ... 261 // ... etc ...
262 // } 262 // }
263 const char kUrlKey[] = "url"; 263 const char kUrlKey[] = "url";
264 const char kFrameNameKey[] = "name"; 264 const char kFrameNameKey[] = "name";
265 265
266 // Defines the backoff policy used for attempting to reload extensions.
267 const net::BackoffEntry::Policy kExtensionReloadBackoffPolicy = {
268 0, // Initial errors to ignore before applying backoff.
269 3000, // Initial delay: 3 seconds.
270 2, // Multiply factor.
271 0.1, // Fuzzing percentage.
272 -1, // Maximum backoff time: -1 for no maximum.
273 -1, // Entry lifetime: -1 to never discard.
274 false, // Whether to always use initial delay. No-op as there are
275 // no initial errors to ignore.
276 };
277
266 int BackgroundContentsService::restart_delay_in_ms_ = 3000; // 3 seconds. 278 int BackgroundContentsService::restart_delay_in_ms_ = 3000; // 3 seconds.
267 279
268 BackgroundContentsService::BackgroundContentsService( 280 BackgroundContentsService::BackgroundContentsService(
269 Profile* profile, 281 Profile* profile,
270 const base::CommandLine* command_line) 282 const base::CommandLine* command_line)
271 : prefs_(NULL), extension_registry_observer_(this) { 283 : prefs_(NULL), extension_registry_observer_(this) {
272 // Don't load/store preferences if the parent profile is incognito. 284 // Don't load/store preferences if the parent profile is incognito.
273 if (!profile->IsOffTheRecord()) 285 if (!profile->IsOffTheRecord())
274 prefs_ = profile->GetPrefs(); 286 prefs_ = profile->GetPrefs();
275 287
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 // Make sure the extension-crash balloons are removed when the extension is 528 // Make sure the extension-crash balloons are removed when the extension is
517 // uninstalled/reloaded. We cannot do this from UNLOADED since a crashed 529 // uninstalled/reloaded. We cannot do this from UNLOADED since a crashed
518 // extension is unloaded immediately after the crash, not when user reloads or 530 // extension is unloaded immediately after the crash, not when user reloads or
519 // uninstalls the extension. 531 // uninstalls the extension.
520 ScheduleCloseBalloon(extension->id(), profile); 532 ScheduleCloseBalloon(extension->id(), profile);
521 } 533 }
522 534
523 void BackgroundContentsService::RestartForceInstalledExtensionOnCrash( 535 void BackgroundContentsService::RestartForceInstalledExtensionOnCrash(
524 const Extension* extension, 536 const Extension* extension,
525 Profile* profile) { 537 Profile* profile) {
538 int restart_delay = restart_delay_in_ms_;
539
540 // If the extension was a component extension, use exponential backoff when
541 // attempting to reload.
542 if (extensions::Manifest::IsComponentLocation(extension->location())) {
543 ExtensionBackoffEntryMap::const_iterator it =
544 backoff_map_.find(extension->id());
545
546 // Create a BackoffEntry if this is the first time we try to reload this
547 // particular extension.
548 if (it == backoff_map_.end()) {
549 std::unique_ptr<net::BackoffEntry> backoff_entry(
550 new net::BackoffEntry(&kExtensionReloadBackoffPolicy));
551 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.
552 std::pair<extensions::ExtensionId,
553 std::unique_ptr<net::BackoffEntry>>(
554 extension->id(), std::move(backoff_entry)));
555 }
556
557 net::BackoffEntry* entry = backoff_map_[extension->id()].get();
558 entry->InformOfRequest(false);
559 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
560 }
561
526 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 562 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
527 FROM_HERE, base::Bind(&ReloadExtension, extension->id(), profile), 563 FROM_HERE, base::Bind(&ReloadExtension, extension->id(), profile),
528 base::TimeDelta::FromMilliseconds(restart_delay_in_ms_)); 564 base::TimeDelta::FromMilliseconds(restart_delay));
529 } 565 }
530 566
531 // Loads all background contents whose urls have been stored in prefs. 567 // Loads all background contents whose urls have been stored in prefs.
532 void BackgroundContentsService::LoadBackgroundContentsFromPrefs( 568 void BackgroundContentsService::LoadBackgroundContentsFromPrefs(
533 Profile* profile) { 569 Profile* profile) {
534 if (!prefs_) 570 if (!prefs_)
535 return; 571 return;
536 const base::DictionaryValue* contents = 572 const base::DictionaryValue* contents =
537 prefs_->GetDictionary(prefs::kRegisteredBackgroundContents); 573 prefs_->GetDictionary(prefs::kRegisteredBackgroundContents);
538 if (!contents) 574 if (!contents)
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 const gfx::Rect& initial_rect, 823 const gfx::Rect& initial_rect,
788 bool user_gesture, 824 bool user_gesture,
789 bool* was_blocked) { 825 bool* was_blocked) {
790 Browser* browser = chrome::FindLastActiveWithProfile( 826 Browser* browser = chrome::FindLastActiveWithProfile(
791 Profile::FromBrowserContext(new_contents->GetBrowserContext())); 827 Profile::FromBrowserContext(new_contents->GetBrowserContext()));
792 if (browser) { 828 if (browser) {
793 chrome::AddWebContents(browser, NULL, new_contents, disposition, 829 chrome::AddWebContents(browser, NULL, new_contents, disposition,
794 initial_rect, user_gesture, was_blocked); 830 initial_rect, user_gesture, was_blocked);
795 } 831 }
796 } 832 }
OLDNEW
« 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