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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 | 287 |
288 // Listen for events to tell us when to load/unload persisted background | 288 // Listen for events to tell us when to load/unload persisted background |
289 // contents. | 289 // contents. |
290 StartObserving(profile); | 290 StartObserving(profile); |
291 } | 291 } |
292 | 292 |
293 BackgroundContentsService::~BackgroundContentsService() { | 293 BackgroundContentsService::~BackgroundContentsService() { |
294 // BackgroundContents should be shutdown before we go away, as otherwise | 294 // BackgroundContents should be shutdown before we go away, as otherwise |
295 // our browser process refcount will be off. | 295 // our browser process refcount will be off. |
296 DCHECK(contents_map_.empty()); | 296 DCHECK(contents_map_.empty()); |
297 | |
298 // Clear any remaining BackoffEntry objects for extensions. This resets the | |
299 // backoff with a change in profile (e.g. when the browser restarts), as | |
300 // |this| is a keyed service. | |
301 backoff_map_.clear(); | |
Wez
2016/09/02 23:54:44
This will just clear the map on browser shutdown,
apacible
2016/09/03 01:14:26
Component extensions are "installed" but are loade
| |
297 } | 302 } |
298 | 303 |
299 // static | 304 // static |
300 void BackgroundContentsService:: | 305 void BackgroundContentsService:: |
301 SetRestartDelayForForceInstalledAppsAndExtensionsForTesting( | 306 SetRestartDelayForForceInstalledAppsAndExtensionsForTesting( |
302 int restart_delay_in_ms) { | 307 int restart_delay_in_ms) { |
303 restart_delay_in_ms_ = restart_delay_in_ms; | 308 restart_delay_in_ms_ = restart_delay_in_ms; |
304 } | 309 } |
305 | 310 |
306 // static | 311 // static |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
471 // Now load the manifest-specified background page. If service isn't | 476 // Now load the manifest-specified background page. If service isn't |
472 // ready, then the background page will be loaded from the | 477 // ready, then the background page will be loaded from the |
473 // EXTENSIONS_READY callback. | 478 // EXTENSIONS_READY callback. |
474 LoadBackgroundContents(profile, | 479 LoadBackgroundContents(profile, |
475 BackgroundInfo::GetBackgroundURL(extension), | 480 BackgroundInfo::GetBackgroundURL(extension), |
476 "background", | 481 "background", |
477 base::UTF8ToUTF16(extension->id())); | 482 base::UTF8ToUTF16(extension->id())); |
478 } | 483 } |
479 } | 484 } |
480 | 485 |
486 // If there is an existing BackoffEntry for the extension, clear it if | |
487 // the component extension stays loaded for 60 seconds. This avoids the | |
488 // situation of effectively disabling an extension for the entire browser | |
489 // session if there was a periodic crash (sometimes caused by another source). | |
490 if (extensions::Manifest::IsComponentLocation(extension->location())) { | |
491 ExtensionBackoffEntryMap::const_iterator it = | |
492 backoff_map_.find(extension->id()); | |
493 if (it != backoff_map_.end()) { | |
494 net::BackoffEntry* entry = backoff_map_[extension->id()].get(); | |
495 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(FROM_HERE, | |
496 base::Bind(&BackgroundContentsService::MaybeClearBackoffEntry, | |
497 base::Unretained(this), extension->id(), entry->failure_count()), | |
Wez
2016/09/02 23:54:44
What happens if you reach here but the BackgroundC
apacible
2016/09/03 01:14:27
Talked offline -- switching to using weak ptr.
| |
498 base::TimeDelta::FromMilliseconds(60000 /* 60 seconds */)); | |
499 } | |
500 } | |
501 | |
481 // Close the crash notification balloon for the app/extension, if any. | 502 // Close the crash notification balloon for the app/extension, if any. |
482 ScheduleCloseBalloon(extension->id(), profile); | 503 ScheduleCloseBalloon(extension->id(), profile); |
483 SendChangeNotification(profile); | 504 SendChangeNotification(profile); |
484 } | 505 } |
485 | 506 |
486 void BackgroundContentsService::OnExtensionUnloaded( | 507 void BackgroundContentsService::OnExtensionUnloaded( |
487 content::BrowserContext* browser_context, | 508 content::BrowserContext* browser_context, |
488 const extensions::Extension* extension, | 509 const extensions::Extension* extension, |
489 extensions::UnloadedExtensionInfo::Reason reason) { | 510 extensions::UnloadedExtensionInfo::Reason reason) { |
490 switch (reason) { | 511 switch (reason) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
597 } | 618 } |
598 } | 619 } |
599 | 620 |
600 void BackgroundContentsService::SendChangeNotification(Profile* profile) { | 621 void BackgroundContentsService::SendChangeNotification(Profile* profile) { |
601 content::NotificationService::current()->Notify( | 622 content::NotificationService::current()->Notify( |
602 chrome::NOTIFICATION_BACKGROUND_CONTENTS_SERVICE_CHANGED, | 623 chrome::NOTIFICATION_BACKGROUND_CONTENTS_SERVICE_CHANGED, |
603 content::Source<Profile>(profile), | 624 content::Source<Profile>(profile), |
604 content::Details<BackgroundContentsService>(this)); | 625 content::Details<BackgroundContentsService>(this)); |
605 } | 626 } |
606 | 627 |
628 void BackgroundContentsService::MaybeClearBackoffEntry( | |
629 const std::string extension_id, | |
630 int expected_failure_count) { | |
631 ExtensionBackoffEntryMap::const_iterator it = | |
632 backoff_map_.find(extension_id); | |
633 if (it == backoff_map_.end()) | |
634 return; | |
635 | |
636 net::BackoffEntry* entry = backoff_map_[extension_id].get(); | |
637 | |
638 // Only remove the BackoffEntry if there has has been no extension failure | |
639 // since loading. | |
Wez
2016/09/02 23:54:43
You mean no additional failure since expected_fail
apacible
2016/09/03 01:14:27
Correct, or more specifically, "no additional fail
| |
640 if (entry->failure_count() == expected_failure_count) | |
641 backoff_map_.erase(it); | |
642 } | |
643 | |
607 void BackgroundContentsService::LoadBackgroundContentsForExtension( | 644 void BackgroundContentsService::LoadBackgroundContentsForExtension( |
608 Profile* profile, | 645 Profile* profile, |
609 const std::string& extension_id) { | 646 const std::string& extension_id) { |
610 // First look if the manifest specifies a background page. | 647 // First look if the manifest specifies a background page. |
611 const Extension* extension = | 648 const Extension* extension = |
612 extensions::ExtensionSystem::Get(profile)->extension_service()-> | 649 extensions::ExtensionSystem::Get(profile)->extension_service()-> |
613 GetExtensionById(extension_id, false); | 650 GetExtensionById(extension_id, false); |
614 DCHECK(!extension || extension->is_hosted_app()); | 651 DCHECK(!extension || extension->is_hosted_app()); |
615 if (extension && BackgroundInfo::HasBackgroundPage(extension)) { | 652 if (extension && BackgroundInfo::HasBackgroundPage(extension)) { |
616 LoadBackgroundContents(profile, | 653 LoadBackgroundContents(profile, |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
823 const gfx::Rect& initial_rect, | 860 const gfx::Rect& initial_rect, |
824 bool user_gesture, | 861 bool user_gesture, |
825 bool* was_blocked) { | 862 bool* was_blocked) { |
826 Browser* browser = chrome::FindLastActiveWithProfile( | 863 Browser* browser = chrome::FindLastActiveWithProfile( |
827 Profile::FromBrowserContext(new_contents->GetBrowserContext())); | 864 Profile::FromBrowserContext(new_contents->GetBrowserContext())); |
828 if (browser) { | 865 if (browser) { |
829 chrome::AddWebContents(browser, NULL, new_contents, disposition, | 866 chrome::AddWebContents(browser, NULL, new_contents, disposition, |
830 initial_rect, user_gesture, was_blocked); | 867 initial_rect, user_gesture, was_blocked); |
831 } | 868 } |
832 } | 869 } |
OLD | NEW |