Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 if (!extension) | 437 if (!extension) |
| 426 break; | 438 break; |
| 427 | 439 |
| 428 const bool force_installed = | 440 const bool force_installed = |
| 429 extensions::Manifest::IsComponentLocation(extension->location()) || | 441 extensions::Manifest::IsComponentLocation(extension->location()) || |
| 430 extensions::Manifest::IsPolicyLocation(extension->location()); | 442 extensions::Manifest::IsPolicyLocation(extension->location()); |
| 431 if (!force_installed) { | 443 if (!force_installed) { |
| 432 ShowBalloon(extension, profile); | 444 ShowBalloon(extension, profile); |
| 433 } else { | 445 } else { |
| 434 // Restart the extension. | 446 // Restart the extension. |
| 435 RestartForceInstalledExtensionOnCrash(extension, profile); | 447 RestartForceInstalledExtensionOnCrash(extension, profile); |
|
Devlin
2016/08/29 20:22:04
I'm not an OWNER here, but since I'm on the review
apacible
2016/08/29 23:26:34
Acknowledged. Makes sense; I'll wait for atwilson@
Andrew T Wilson (Slow)
2016/08/30 08:24:57
I want to make sure we only do the backoff logic f
apacible
2016/08/30 23:54:15
Agree with both comments -- I made some changes to
| |
| 436 } | 448 } |
| 437 break; | 449 break; |
| 438 } | 450 } |
| 439 | 451 |
| 440 default: | 452 default: |
| 441 NOTREACHED(); | 453 NOTREACHED(); |
| 442 break; | 454 break; |
| 443 } | 455 } |
| 444 } | 456 } |
| 445 | 457 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 net::BackoffEntry* backoff_entry; | |
| 546 | |
| 547 // Create a BackoffEntry if this is the first time we try to reload this | |
| 548 // particular extension. | |
| 549 if (it == backoff_map_.end()) { | |
| 550 backoff_entry = new net::BackoffEntry(&kExtensionReloadBackoffPolicy); | |
|
Andrew T Wilson (Slow)
2016/08/30 08:24:57
I think these BackoffEntry() items leak on shutdow
apacible
2016/08/30 23:54:15
Done. Used get() to return a pointer to the Backof
| |
| 551 backoff_map_.insert( | |
| 552 std::pair<extensions::ExtensionId, net::BackoffEntry*>( | |
| 553 extension->id(), backoff_entry)); | |
| 554 } else { | |
| 555 backoff_entry = it->second; | |
| 556 } | |
| 557 | |
| 558 backoff_entry->InformOfRequest(false); | |
| 559 restart_delay = backoff_entry->GetTimeUntilRelease().InMilliseconds(); | |
| 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 Loading... | |
| 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 } |
| OLD | NEW |