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/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "chrome/browser/extensions/api/runtime/runtime_api.h" |
13 #include "chrome/browser/extensions/extension_process_manager.h" | 14 #include "chrome/browser/extensions/extension_process_manager.h" |
14 #include "chrome/browser/extensions/extension_host.h" | 15 #include "chrome/browser/extensions/extension_host.h" |
15 #include "chrome/browser/extensions/extension_info_map.h" | 16 #include "chrome/browser/extensions/extension_info_map.h" |
16 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
17 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_finder.h" | 21 #include "chrome/browser/ui/browser_finder.h" |
21 #include "chrome/browser/ui/browser_tabstrip.h" | 22 #include "chrome/browser/ui/browser_tabstrip.h" |
22 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 const content::NotificationDetails& details); | 83 const content::NotificationDetails& details); |
83 | 84 |
84 // Returns true if the extension is allowed to run in incognito mode. | 85 // Returns true if the extension is allowed to run in incognito mode. |
85 bool IsIncognitoEnabled(const Extension* extension); | 86 bool IsIncognitoEnabled(const Extension* extension); |
86 | 87 |
87 ExtensionProcessManager* original_manager_; | 88 ExtensionProcessManager* original_manager_; |
88 }; | 89 }; |
89 | 90 |
90 static void CreateBackgroundHostForExtensionLoad( | 91 static void CreateBackgroundHostForExtensionLoad( |
91 ExtensionProcessManager* manager, const Extension* extension) { | 92 ExtensionProcessManager* manager, const Extension* extension) { |
92 if (extension->has_persistent_background_page()) { | 93 if (extension->has_persistent_background_page()) |
93 manager->CreateBackgroundHost(extension, extension->GetBackgroundURL()); | 94 manager->CreateBackgroundHost(extension, extension->GetBackgroundURL()); |
| 95 } |
| 96 |
| 97 static void CreateBackgroundHostsForProfileStartup( |
| 98 Profile* profile, |
| 99 ExtensionProcessManager* manager, |
| 100 const ExtensionSet* extensions) { |
| 101 for (ExtensionSet::const_iterator extension = extensions->begin(); |
| 102 extension != extensions->end(); ++extension) { |
| 103 CreateBackgroundHostForExtensionLoad(manager, *extension); |
| 104 |
| 105 extensions::RuntimeEventRouter::DispatchOnStartupEvent( |
| 106 profile, (*extension)->id()); |
94 } | 107 } |
95 } | 108 } |
96 | 109 |
97 static void CreateBackgroundHostsForProfileStartup( | |
98 ExtensionProcessManager* manager, const ExtensionSet* extensions) { | |
99 for (ExtensionSet::const_iterator extension = extensions->begin(); | |
100 extension != extensions->end(); ++extension) { | |
101 CreateBackgroundHostForExtensionLoad(manager, *extension); | |
102 } | |
103 } | |
104 | |
105 } // namespace | 110 } // namespace |
106 | 111 |
107 struct ExtensionProcessManager::BackgroundPageData { | 112 struct ExtensionProcessManager::BackgroundPageData { |
108 // The count of things keeping the lazy background page alive. | 113 // The count of things keeping the lazy background page alive. |
109 int lazy_keepalive_count; | 114 int lazy_keepalive_count; |
110 | 115 |
111 // This is used with the ShouldUnload message, to ensure that the extension | 116 // This is used with the ShouldUnload message, to ensure that the extension |
112 // remained idle between sending the message and receiving the ack. | 117 // remained idle between sending the message and receiving the ack. |
113 int close_sequence_id; | 118 int close_sequence_id; |
114 | 119 |
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 DecrementLazyKeepaliveCount(extension); | 555 DecrementLazyKeepaliveCount(extension); |
551 } | 556 } |
552 } | 557 } |
553 | 558 |
554 void ExtensionProcessManager::Observe( | 559 void ExtensionProcessManager::Observe( |
555 int type, | 560 int type, |
556 const content::NotificationSource& source, | 561 const content::NotificationSource& source, |
557 const content::NotificationDetails& details) { | 562 const content::NotificationDetails& details) { |
558 switch (type) { | 563 switch (type) { |
559 case chrome::NOTIFICATION_EXTENSIONS_READY: { | 564 case chrome::NOTIFICATION_EXTENSIONS_READY: { |
560 CreateBackgroundHostsForProfileStartup(this, | 565 Profile* profile = content::Source<Profile>(source).ptr(); |
561 content::Source<Profile>(source).ptr()-> | 566 CreateBackgroundHostsForProfileStartup(profile, this, |
562 GetExtensionService()->extensions()); | 567 profile->GetExtensionService()->extensions()); |
563 break; | 568 break; |
564 } | 569 } |
565 | 570 |
566 case chrome::NOTIFICATION_EXTENSION_LOADED: { | 571 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
567 ExtensionService* service = | 572 Profile* profile = content::Source<Profile>(source).ptr(); |
568 content::Source<Profile>(source).ptr()->GetExtensionService(); | 573 ExtensionService* service = profile->GetExtensionService(); |
569 if (service->is_ready()) { | 574 if (service->is_ready()) { |
570 const Extension* extension = | 575 const Extension* extension = |
571 content::Details<const Extension>(details).ptr(); | 576 content::Details<const Extension>(details).ptr(); |
572 ::CreateBackgroundHostForExtensionLoad(this, extension); | 577 CreateBackgroundHostForExtensionLoad(this, extension); |
573 } | 578 } |
574 break; | 579 break; |
575 } | 580 } |
576 | 581 |
577 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 582 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
578 const Extension* extension = | 583 const Extension* extension = |
579 content::Details<extensions::UnloadedExtensionInfo>( | 584 content::Details<extensions::UnloadedExtensionInfo>( |
580 details)->extension; | 585 details)->extension; |
581 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); | 586 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); |
582 iter != background_hosts_.end(); ++iter) { | 587 iter != background_hosts_.end(); ++iter) { |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 // We want to spawn our background hosts as soon as the user opens an | 803 // We want to spawn our background hosts as soon as the user opens an |
799 // incognito window. Watch for new browsers and create the hosts if | 804 // incognito window. Watch for new browsers and create the hosts if |
800 // it matches our profile. | 805 // it matches our profile. |
801 Browser* browser = content::Source<Browser>(source).ptr(); | 806 Browser* browser = content::Source<Browser>(source).ptr(); |
802 if (browser->profile() == site_instance_->GetBrowserContext()) { | 807 if (browser->profile() == site_instance_->GetBrowserContext()) { |
803 // On Chrome OS, a login screen is implemented as a browser. | 808 // On Chrome OS, a login screen is implemented as a browser. |
804 // This browser has no extension service. In this case, | 809 // This browser has no extension service. In this case, |
805 // service will be NULL. | 810 // service will be NULL. |
806 ExtensionService* service = GetProfile()->GetExtensionService(); | 811 ExtensionService* service = GetProfile()->GetExtensionService(); |
807 if (service && service->is_ready()) | 812 if (service && service->is_ready()) |
808 CreateBackgroundHostsForProfileStartup(this, service->extensions()); | 813 CreateBackgroundHostsForProfileStartup(GetProfile(), |
| 814 this, service->extensions()); |
809 } | 815 } |
810 break; | 816 break; |
811 } | 817 } |
812 default: | 818 default: |
813 ExtensionProcessManager::Observe(type, source, details); | 819 ExtensionProcessManager::Observe(type, source, details); |
814 break; | 820 break; |
815 } | 821 } |
816 } | 822 } |
OLD | NEW |