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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/message_loop.h" | |
9 #include "base/time.h" | |
8 #include "chrome/browser/extensions/extension_event_router.h" | 10 #include "chrome/browser/extensions/extension_event_router.h" |
9 #include "chrome/browser/extensions/extension_process_manager.h" | 11 #include "chrome/browser/extensions/extension_process_manager.h" |
10 #include "chrome/browser/extensions/extension_host.h" | 12 #include "chrome/browser/extensions/extension_host.h" |
11 #include "chrome/browser/extensions/extension_info_map.h" | 13 #include "chrome/browser/extensions/extension_info_map.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/extensions/extension_system.h" | 15 #include "chrome/browser/extensions/extension_system.h" |
14 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/browser_window.h" | 18 #include "chrome/browser/ui/browser_window.h" |
17 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 // | 120 // |
119 | 121 |
120 // static | 122 // static |
121 ExtensionProcessManager* ExtensionProcessManager::Create(Profile* profile) { | 123 ExtensionProcessManager* ExtensionProcessManager::Create(Profile* profile) { |
122 return (profile->IsOffTheRecord()) ? | 124 return (profile->IsOffTheRecord()) ? |
123 new IncognitoExtensionProcessManager(profile) : | 125 new IncognitoExtensionProcessManager(profile) : |
124 new ExtensionProcessManager(profile); | 126 new ExtensionProcessManager(profile); |
125 } | 127 } |
126 | 128 |
127 ExtensionProcessManager::ExtensionProcessManager(Profile* profile) | 129 ExtensionProcessManager::ExtensionProcessManager(Profile* profile) |
128 : site_instance_(SiteInstance::Create(profile)) { | 130 : site_instance_(SiteInstance::Create(profile)), |
131 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
129 Profile* original_profile = profile->GetOriginalProfile(); | 132 Profile* original_profile = profile->GetOriginalProfile(); |
130 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 133 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
131 content::Source<Profile>(original_profile)); | 134 content::Source<Profile>(original_profile)); |
132 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 135 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
133 content::Source<Profile>(original_profile)); | 136 content::Source<Profile>(original_profile)); |
134 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 137 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
135 content::Source<Profile>(original_profile)); | 138 content::Source<Profile>(original_profile)); |
136 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 139 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
137 content::Source<Profile>(profile)); | 140 content::Source<Profile>(profile)); |
138 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 141 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 return count; | 410 return count; |
408 } | 411 } |
409 | 412 |
410 int ExtensionProcessManager::DecrementLazyKeepaliveCount( | 413 int ExtensionProcessManager::DecrementLazyKeepaliveCount( |
411 const Extension* extension) { | 414 const Extension* extension) { |
412 if (!extension->has_lazy_background_page()) | 415 if (!extension->has_lazy_background_page()) |
413 return 0; | 416 return 0; |
414 | 417 |
415 int& count = background_page_data_[extension->id()].lazy_keepalive_count; | 418 int& count = background_page_data_[extension->id()].lazy_keepalive_count; |
416 DCHECK_GT(count, 0); | 419 DCHECK_GT(count, 0); |
417 if (--count == 0) | 420 if (--count == 0) { |
418 OnLazyBackgroundPageIdle(extension->id()); | 421 VLOG(1) << "delaying post for " << extension->id(); |
422 MessageLoop::current()->PostDelayedTask( | |
423 FROM_HERE, | |
424 base::Bind(&ExtensionProcessManager::OnLazyBackgroundPageIdle, | |
425 weak_ptr_factory_.GetWeakPtr(), extension->id(), | |
426 ++background_page_data_[extension->id()].close_sequence_id), | |
427 base::TimeDelta::FromSeconds(10)); | |
Yoyo Zhou
2012/04/30 21:34:09
I'm not sure if this should be a constant defined
Aaron Boodman
2012/04/30 21:47:13
Let's do a command-line flag so that we can experi
Matt Perry
2012/04/30 21:58:45
I think we should have 2 timeouts, like I describe
Yoyo Zhou
2012/05/01 22:15:13
This is the first one then. As for the second case
| |
428 } | |
419 | 429 |
420 return count; | 430 return count; |
421 } | 431 } |
422 | 432 |
423 void ExtensionProcessManager::OnLazyBackgroundPageIdle( | 433 void ExtensionProcessManager::OnLazyBackgroundPageIdle( |
424 const std::string& extension_id) { | 434 const std::string& extension_id, int close_sequence_id) { |
435 VLOG(1) << "onlazybgpidle " << extension_id; | |
425 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); | 436 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); |
426 if (host && !background_page_data_[extension_id].is_closing) { | 437 if (host && !background_page_data_[extension_id].is_closing) { |
Matt Perry
2012/04/30 21:58:45
We should check whether close_sequence_id has chan
Yoyo Zhou
2012/05/01 22:15:13
True.
| |
427 // Tell the renderer we are about to close. This is a simple ping that the | 438 // Tell the renderer we are about to close. This is a simple ping that the |
428 // renderer will respond to. The purpose is to control sequencing: if the | 439 // renderer will respond to. The purpose is to control sequencing: if the |
429 // extension remains idle until the renderer responds with an ACK, then we | 440 // extension remains idle until the renderer responds with an ACK, then we |
430 // know that the extension process is ready to shut down. | 441 // know that the extension process is ready to shut down. |
431 host->render_view_host()->Send(new ExtensionMsg_ShouldUnload( | 442 host->render_view_host()->Send(new ExtensionMsg_ShouldUnload( |
432 extension_id, ++background_page_data_[extension_id].close_sequence_id)); | 443 extension_id, close_sequence_id)); |
433 } | 444 } |
434 } | 445 } |
435 | 446 |
436 void ExtensionProcessManager::OnLazyBackgroundPageActive( | 447 void ExtensionProcessManager::OnLazyBackgroundPageActive( |
437 const std::string& extension_id) { | 448 const std::string& extension_id) { |
438 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); | 449 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); |
439 if (host && !background_page_data_[extension_id].is_closing) { | 450 if (host && !background_page_data_[extension_id].is_closing) { |
440 // Cancel the current close sequence by changing the close_sequence_id, | 451 // Cancel the current close sequence by changing the close_sequence_id, |
441 // which causes us to ignore the next ShouldUnloadAck. | 452 // which causes us to ignore the next ShouldUnloadAck. |
442 ++background_page_data_[extension_id].close_sequence_id; | 453 ++background_page_data_[extension_id].close_sequence_id; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
703 if (service && service->is_ready()) | 714 if (service && service->is_ready()) |
704 CreateBackgroundHostsForProfileStartup(this, service->extensions()); | 715 CreateBackgroundHostsForProfileStartup(this, service->extensions()); |
705 } | 716 } |
706 break; | 717 break; |
707 } | 718 } |
708 default: | 719 default: |
709 ExtensionProcessManager::Observe(type, source, details); | 720 ExtensionProcessManager::Observe(type, source, details); |
710 break; | 721 break; |
711 } | 722 } |
712 } | 723 } |
OLD | NEW |