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/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "chrome/browser/extensions/api/runtime/runtime_api.h" | 14 #include "chrome/browser/extensions/api/runtime/runtime_api.h" |
15 #include "chrome/browser/extensions/extension_host.h" | 15 #include "chrome/browser/extensions/extension_host.h" |
16 #include "chrome/browser/extensions/extension_info_map.h" | 16 #include "chrome/browser/extensions/extension_info_map.h" |
17 #include "chrome/browser/extensions/extension_process_manager.h" | 17 #include "chrome/browser/extensions/extension_process_manager.h" |
18 #include "chrome/browser/extensions/extension_service.h" | 18 #include "chrome/browser/extensions/extension_service.h" |
19 #include "chrome/browser/extensions/extension_system.h" | 19 #include "chrome/browser/extensions/extension_system.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
22 #include "chrome/browser/ui/browser_finder.h" | 22 #include "chrome/browser/ui/browser_finder.h" |
23 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
24 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 24 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
25 #include "chrome/browser/view_type_utils.h" | 25 #include "chrome/browser/view_type_utils.h" |
26 #include "chrome/common/chrome_notification_types.h" | 26 #include "chrome/common/chrome_notification_types.h" |
27 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
| 28 #include "chrome/common/extensions/background_info.h" |
28 #include "chrome/common/extensions/extension.h" | 29 #include "chrome/common/extensions/extension.h" |
29 #include "chrome/common/extensions/extension_messages.h" | 30 #include "chrome/common/extensions/extension_messages.h" |
| 31 #include "chrome/common/extensions/manifest_handler.h" |
30 #include "chrome/common/extensions/manifest_url_handler.h" | 32 #include "chrome/common/extensions/manifest_url_handler.h" |
31 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
32 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
34 #include "content/public/browser/render_process_host.h" | 36 #include "content/public/browser/render_process_host.h" |
35 #include "content/public/browser/render_view_host.h" | 37 #include "content/public/browser/render_view_host.h" |
36 #include "content/public/browser/site_instance.h" | 38 #include "content/public/browser/site_instance.h" |
37 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
38 #include "content/public/browser/web_contents_delegate.h" | 40 #include "content/public/browser/web_contents_delegate.h" |
39 #include "content/public/common/renderer_preferences.h" | 41 #include "content/public/common/renderer_preferences.h" |
40 | 42 |
41 #if defined(OS_MACOSX) | 43 #if defined(OS_MACOSX) |
42 #include "chrome/browser/extensions/extension_host_mac.h" | 44 #include "chrome/browser/extensions/extension_host_mac.h" |
43 #endif | 45 #endif |
44 | 46 |
45 using content::BrowserThread; | 47 using content::BrowserThread; |
46 using content::OpenURLParams; | 48 using content::OpenURLParams; |
47 using content::Referrer; | 49 using content::Referrer; |
48 using content::RenderViewHost; | 50 using content::RenderViewHost; |
49 using content::SiteInstance; | 51 using content::SiteInstance; |
50 using content::WebContents; | 52 using content::WebContents; |
| 53 using extensions::BackgroundInfo; |
| 54 using extensions::BackgroundManifestHandler; |
51 using extensions::Extension; | 55 using extensions::Extension; |
52 using extensions::ExtensionHost; | 56 using extensions::ExtensionHost; |
53 | 57 |
54 namespace { | 58 namespace { |
55 | 59 |
56 std::string GetExtensionID(RenderViewHost* render_view_host) { | 60 std::string GetExtensionID(RenderViewHost* render_view_host) { |
57 // This works for both apps and extensions because the site has been | 61 // This works for both apps and extensions because the site has been |
58 // normalized to the extension URL for apps. | 62 // normalized to the extension URL for apps. |
59 if (!render_view_host->GetSiteInstance()) | 63 if (!render_view_host->GetSiteInstance()) |
60 return ""; | 64 return ""; |
(...skipping 24 matching lines...) Expand all Loading... |
85 const content::NotificationDetails& details) OVERRIDE; | 89 const content::NotificationDetails& details) OVERRIDE; |
86 | 90 |
87 // Returns true if the extension is allowed to run in incognito mode. | 91 // Returns true if the extension is allowed to run in incognito mode. |
88 bool IsIncognitoEnabled(const Extension* extension); | 92 bool IsIncognitoEnabled(const Extension* extension); |
89 | 93 |
90 ExtensionProcessManager* original_manager_; | 94 ExtensionProcessManager* original_manager_; |
91 }; | 95 }; |
92 | 96 |
93 static void CreateBackgroundHostForExtensionLoad( | 97 static void CreateBackgroundHostForExtensionLoad( |
94 ExtensionProcessManager* manager, const Extension* extension) { | 98 ExtensionProcessManager* manager, const Extension* extension) { |
95 if (extension->has_persistent_background_page()) | 99 if (BackgroundInfo::HasPersistentBackgroundPage(extension)) |
96 manager->CreateBackgroundHost(extension, extension->GetBackgroundURL()); | 100 manager->CreateBackgroundHost(extension, |
| 101 BackgroundInfo::GetBackgroundURL(extension)); |
97 } | 102 } |
98 | 103 |
99 static void CreateBackgroundHostsForProfileStartup( | 104 static void CreateBackgroundHostsForProfileStartup( |
100 Profile* profile, | 105 Profile* profile, |
101 ExtensionProcessManager* manager, | 106 ExtensionProcessManager* manager, |
102 const ExtensionSet* extensions) { | 107 const ExtensionSet* extensions) { |
103 for (ExtensionSet::const_iterator extension = extensions->begin(); | 108 for (ExtensionSet::const_iterator extension = extensions->begin(); |
104 extension != extensions->end(); ++extension) { | 109 extension != extensions->end(); ++extension) { |
105 CreateBackgroundHostForExtensionLoad(manager, *extension); | 110 CreateBackgroundHostForExtensionLoad(manager, *extension); |
106 | 111 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 switches::kEventPageIdleTime), &idle_time_sec)) { | 183 switches::kEventPageIdleTime), &idle_time_sec)) { |
179 event_page_idle_time_ = base::TimeDelta::FromSeconds(idle_time_sec); | 184 event_page_idle_time_ = base::TimeDelta::FromSeconds(idle_time_sec); |
180 } | 185 } |
181 event_page_suspending_time_ = base::TimeDelta::FromSeconds(5); | 186 event_page_suspending_time_ = base::TimeDelta::FromSeconds(5); |
182 unsigned suspending_time_sec = 0; | 187 unsigned suspending_time_sec = 0; |
183 if (base::StringToUint(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 188 if (base::StringToUint(CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
184 switches::kEventPageSuspendingTime), &suspending_time_sec)) { | 189 switches::kEventPageSuspendingTime), &suspending_time_sec)) { |
185 event_page_suspending_time_ = base::TimeDelta::FromSeconds( | 190 event_page_suspending_time_ = base::TimeDelta::FromSeconds( |
186 suspending_time_sec); | 191 suspending_time_sec); |
187 } | 192 } |
| 193 |
| 194 (new BackgroundManifestHandler())->Register(); |
188 } | 195 } |
189 | 196 |
190 ExtensionProcessManager::~ExtensionProcessManager() { | 197 ExtensionProcessManager::~ExtensionProcessManager() { |
191 CloseBackgroundHosts(); | 198 CloseBackgroundHosts(); |
192 DCHECK(background_hosts_.empty()); | 199 DCHECK(background_hosts_.empty()); |
193 } | 200 } |
194 | 201 |
195 const ExtensionProcessManager::ViewSet | 202 const ExtensionProcessManager::ViewSet |
196 ExtensionProcessManager::GetAllViews() const { | 203 ExtensionProcessManager::GetAllViews() const { |
197 ViewSet result; | 204 ViewSet result; |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 return site_instance_->GetRelatedSiteInstance(url); | 427 return site_instance_->GetRelatedSiteInstance(url); |
421 } | 428 } |
422 | 429 |
423 bool ExtensionProcessManager::IsBackgroundHostClosing( | 430 bool ExtensionProcessManager::IsBackgroundHostClosing( |
424 const std::string& extension_id) { | 431 const std::string& extension_id) { |
425 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); | 432 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); |
426 return (host && background_page_data_[extension_id].is_closing); | 433 return (host && background_page_data_[extension_id].is_closing); |
427 } | 434 } |
428 | 435 |
429 int ExtensionProcessManager::GetLazyKeepaliveCount(const Extension* extension) { | 436 int ExtensionProcessManager::GetLazyKeepaliveCount(const Extension* extension) { |
430 if (!extension->has_lazy_background_page()) | 437 if (!BackgroundInfo::HasLazyBackgroundPage(extension)) |
431 return 0; | 438 return 0; |
432 | 439 |
433 return background_page_data_[extension->id()].lazy_keepalive_count; | 440 return background_page_data_[extension->id()].lazy_keepalive_count; |
434 } | 441 } |
435 | 442 |
436 int ExtensionProcessManager::IncrementLazyKeepaliveCount( | 443 int ExtensionProcessManager::IncrementLazyKeepaliveCount( |
437 const Extension* extension) { | 444 const Extension* extension) { |
438 if (!extension->has_lazy_background_page()) | 445 if (!BackgroundInfo::HasLazyBackgroundPage(extension)) |
439 return 0; | 446 return 0; |
440 | 447 |
441 int& count = background_page_data_[extension->id()].lazy_keepalive_count; | 448 int& count = background_page_data_[extension->id()].lazy_keepalive_count; |
442 if (++count == 1) | 449 if (++count == 1) |
443 OnLazyBackgroundPageActive(extension->id()); | 450 OnLazyBackgroundPageActive(extension->id()); |
444 | 451 |
445 return count; | 452 return count; |
446 } | 453 } |
447 | 454 |
448 int ExtensionProcessManager::DecrementLazyKeepaliveCount( | 455 int ExtensionProcessManager::DecrementLazyKeepaliveCount( |
449 const Extension* extension) { | 456 const Extension* extension) { |
450 if (!extension->has_lazy_background_page()) | 457 if (!BackgroundInfo::HasLazyBackgroundPage(extension)) |
451 return 0; | 458 return 0; |
452 | 459 |
453 int& count = background_page_data_[extension->id()].lazy_keepalive_count; | 460 int& count = background_page_data_[extension->id()].lazy_keepalive_count; |
454 DCHECK_GT(count, 0); | 461 DCHECK_GT(count, 0); |
455 if (--count == 0) { | 462 if (--count == 0) { |
456 MessageLoop::current()->PostDelayedTask( | 463 MessageLoop::current()->PostDelayedTask( |
457 FROM_HERE, | 464 FROM_HERE, |
458 base::Bind(&ExtensionProcessManager::OnLazyBackgroundPageIdle, | 465 base::Bind(&ExtensionProcessManager::OnLazyBackgroundPageIdle, |
459 weak_ptr_factory_.GetWeakPtr(), extension->id(), | 466 weak_ptr_factory_.GetWeakPtr(), extension->id(), |
460 ++background_page_data_[extension->id()].close_sequence_id), | 467 ++background_page_data_[extension->id()].close_sequence_id), |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 Profile* ExtensionProcessManager::GetProfile() const { | 720 Profile* ExtensionProcessManager::GetProfile() const { |
714 return Profile::FromBrowserContext(site_instance_->GetBrowserContext()); | 721 return Profile::FromBrowserContext(site_instance_->GetBrowserContext()); |
715 } | 722 } |
716 | 723 |
717 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, | 724 void ExtensionProcessManager::OnExtensionHostCreated(ExtensionHost* host, |
718 bool is_background) { | 725 bool is_background) { |
719 DCHECK_EQ(site_instance_->GetBrowserContext(), host->profile()); | 726 DCHECK_EQ(site_instance_->GetBrowserContext(), host->profile()); |
720 if (is_background) { | 727 if (is_background) { |
721 background_hosts_.insert(host); | 728 background_hosts_.insert(host); |
722 | 729 |
723 if (host->extension()->has_lazy_background_page()) { | 730 if (BackgroundInfo::HasLazyBackgroundPage(host->extension())) { |
724 linked_ptr<PerfTimer> since_suspended( | 731 linked_ptr<PerfTimer> since_suspended( |
725 background_page_data_[host->extension()->id()]. | 732 background_page_data_[host->extension()->id()]. |
726 since_suspended.release()); | 733 since_suspended.release()); |
727 if (since_suspended.get()) { | 734 if (since_suspended.get()) { |
728 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageIdleTime", | 735 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageIdleTime", |
729 since_suspended->Elapsed()); | 736 since_suspended->Elapsed()); |
730 } | 737 } |
731 } | 738 } |
732 } | 739 } |
733 } | 740 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 CreateBackgroundHostsForProfileStartup(GetProfile(), | 863 CreateBackgroundHostsForProfileStartup(GetProfile(), |
857 this, service->extensions()); | 864 this, service->extensions()); |
858 } | 865 } |
859 break; | 866 break; |
860 } | 867 } |
861 default: | 868 default: |
862 ExtensionProcessManager::Observe(type, source, details); | 869 ExtensionProcessManager::Observe(type, source, details); |
863 break; | 870 break; |
864 } | 871 } |
865 } | 872 } |
OLD | NEW |