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