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

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: 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 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
541 // exponential backoff when attempting to reload.
542 if (extensions::Manifest::IsComponentLocation(extension->location()) &&
543 !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
544 ExtensionBackoffEntryMap::const_iterator it =
545 backoff_map_.find(extension->id());
546 net::BackoffEntry* backoff_entry;
547
548 // Create a BackoffEntry if this is the first time we try to reload this
549 // particular extension.
550 if (it == backoff_map_.end()) {
551 backoff_entry = new net::BackoffEntry(&kExtensionReloadBackoffPolicy);
552 backoff_map_.insert(
553 std::pair<extensions::ExtensionId, net::BackoffEntry*>(
554 extension->id(), backoff_entry));
555 } else {
556 backoff_entry = it->second;
557 }
558
559 backoff_entry->InformOfRequest(false);
560 restart_delay = backoff_entry->GetTimeUntilRelease().InMilliseconds();
561 }
562
526 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 563 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
527 FROM_HERE, base::Bind(&ReloadExtension, extension->id(), profile), 564 FROM_HERE, base::Bind(&ReloadExtension, extension->id(), profile),
528 base::TimeDelta::FromMilliseconds(restart_delay_in_ms_)); 565 base::TimeDelta::FromMilliseconds(restart_delay));
529 } 566 }
530 567
531 // Loads all background contents whose urls have been stored in prefs. 568 // Loads all background contents whose urls have been stored in prefs.
532 void BackgroundContentsService::LoadBackgroundContentsFromPrefs( 569 void BackgroundContentsService::LoadBackgroundContentsFromPrefs(
533 Profile* profile) { 570 Profile* profile) {
534 if (!prefs_) 571 if (!prefs_)
535 return; 572 return;
536 const base::DictionaryValue* contents = 573 const base::DictionaryValue* contents =
537 prefs_->GetDictionary(prefs::kRegisteredBackgroundContents); 574 prefs_->GetDictionary(prefs::kRegisteredBackgroundContents);
538 if (!contents) 575 if (!contents)
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 const gfx::Rect& initial_rect, 824 const gfx::Rect& initial_rect,
788 bool user_gesture, 825 bool user_gesture,
789 bool* was_blocked) { 826 bool* was_blocked) {
790 Browser* browser = chrome::FindLastActiveWithProfile( 827 Browser* browser = chrome::FindLastActiveWithProfile(
791 Profile::FromBrowserContext(new_contents->GetBrowserContext())); 828 Profile::FromBrowserContext(new_contents->GetBrowserContext()));
792 if (browser) { 829 if (browser) {
793 chrome::AddWebContents(browser, NULL, new_contents, disposition, 830 chrome::AddWebContents(browser, NULL, new_contents, disposition,
794 initial_rect, user_gesture, was_blocked); 831 initial_rect, user_gesture, was_blocked);
795 } 832 }
796 } 833 }
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