Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(592)

Side by Side Diff: extensions/browser/extension_host.cc

Issue 933423003: Make BackgroundContentsService start up BackgroundContents with a delay, as for ExtensionHosts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: edulcni# Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « extensions/browser/extension_host.h ('k') | extensions/browser/extension_host_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/extension_host.h" 5 #include "extensions/browser/extension_host.h"
6 6
7 #include "base/lazy_instance.h"
8 #include "base/logging.h" 7 #include "base/logging.h"
9 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
11 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
13 #include "content/public/browser/browser_context.h" 12 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/content_browser_client.h" 13 #include "content/public/browser/content_browser_client.h"
15 #include "content/public/browser/native_web_keyboard_event.h" 14 #include "content/public/browser/native_web_keyboard_event.h"
16 #include "content/public/browser/notification_service.h" 15 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/notification_source.h" 16 #include "content/public/browser/notification_source.h"
18 #include "content/public/browser/notification_types.h" 17 #include "content/public/browser/notification_types.h"
19 #include "content/public/browser/render_process_host.h" 18 #include "content/public/browser/render_process_host.h"
20 #include "content/public/browser/render_view_host.h" 19 #include "content/public/browser/render_view_host.h"
21 #include "content/public/browser/render_widget_host_view.h" 20 #include "content/public/browser/render_widget_host_view.h"
22 #include "content/public/browser/site_instance.h" 21 #include "content/public/browser/site_instance.h"
23 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
24 #include "extensions/browser/event_router.h" 23 #include "extensions/browser/event_router.h"
25 #include "extensions/browser/extension_error.h" 24 #include "extensions/browser/extension_error.h"
26 #include "extensions/browser/extension_host_delegate.h" 25 #include "extensions/browser/extension_host_delegate.h"
27 #include "extensions/browser/extension_host_observer.h" 26 #include "extensions/browser/extension_host_observer.h"
28 #include "extensions/browser/extension_host_queue.h" 27 #include "extensions/browser/extension_host_queue.h"
29 #include "extensions/browser/extension_system.h" 28 #include "extensions/browser/extension_system.h"
30 #include "extensions/browser/extensions_browser_client.h" 29 #include "extensions/browser/extensions_browser_client.h"
31 #include "extensions/browser/notification_types.h" 30 #include "extensions/browser/notification_types.h"
32 #include "extensions/browser/process_manager.h" 31 #include "extensions/browser/process_manager.h"
33 #include "extensions/browser/runtime_data.h" 32 #include "extensions/browser/runtime_data.h"
34 #include "extensions/browser/serial_extension_host_queue.h"
35 #include "extensions/browser/view_type_utils.h" 33 #include "extensions/browser/view_type_utils.h"
36 #include "extensions/common/extension.h" 34 #include "extensions/common/extension.h"
37 #include "extensions/common/extension_messages.h" 35 #include "extensions/common/extension_messages.h"
38 #include "extensions/common/extension_urls.h" 36 #include "extensions/common/extension_urls.h"
39 #include "extensions/common/feature_switch.h" 37 #include "extensions/common/feature_switch.h"
40 #include "extensions/common/manifest_handlers/background_info.h" 38 #include "extensions/common/manifest_handlers/background_info.h"
41 #include "ui/base/l10n/l10n_util.h" 39 #include "ui/base/l10n/l10n_util.h"
42 #include "ui/base/window_open_disposition.h" 40 #include "ui/base/window_open_disposition.h"
43 41
44 using content::BrowserContext; 42 using content::BrowserContext;
45 using content::OpenURLParams; 43 using content::OpenURLParams;
46 using content::RenderProcessHost; 44 using content::RenderProcessHost;
47 using content::RenderViewHost; 45 using content::RenderViewHost;
48 using content::SiteInstance; 46 using content::SiteInstance;
49 using content::WebContents; 47 using content::WebContents;
50 48
51 namespace extensions { 49 namespace extensions {
52 50
53 namespace {
54
55 // Singleton which wraps our current ExtensionHostQueue implementation.
56 struct QueueWrapper {
57 QueueWrapper() : queue(new SerialExtensionHostQueue()) {}
58 scoped_ptr<ExtensionHostQueue> queue;
59 };
60 base::LazyInstance<QueueWrapper> g_queue_wrapper = LAZY_INSTANCE_INITIALIZER;
61
62 } // namespace
63
64 ExtensionHost::ExtensionHost(const Extension* extension, 51 ExtensionHost::ExtensionHost(const Extension* extension,
65 SiteInstance* site_instance, 52 SiteInstance* site_instance,
66 const GURL& url, 53 const GURL& url,
67 ViewType host_type) 54 ViewType host_type)
68 : delegate_(ExtensionsBrowserClient::Get()->CreateExtensionHostDelegate()), 55 : delegate_(ExtensionsBrowserClient::Get()->CreateExtensionHostDelegate()),
69 extension_(extension), 56 extension_(extension),
70 extension_id_(extension->id()), 57 extension_id_(extension->id()),
71 browser_context_(site_instance->GetBrowserContext()), 58 browser_context_(site_instance->GetBrowserContext()),
72 render_view_host_(nullptr), 59 render_view_host_(nullptr),
73 did_stop_loading_(false), 60 did_stop_loading_(false),
(...skipping 29 matching lines...) Expand all
103 load_start_.get()) { 90 load_start_.get()) {
104 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime2", 91 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime2",
105 load_start_->Elapsed()); 92 load_start_->Elapsed());
106 } 93 }
107 content::NotificationService::current()->Notify( 94 content::NotificationService::current()->Notify(
108 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, 95 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
109 content::Source<BrowserContext>(browser_context_), 96 content::Source<BrowserContext>(browser_context_),
110 content::Details<ExtensionHost>(this)); 97 content::Details<ExtensionHost>(this));
111 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_, 98 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_,
112 OnExtensionHostDestroyed(this)); 99 OnExtensionHostDestroyed(this));
113 g_queue_wrapper.Get().queue->Remove(this); 100 delegate_->GetExtensionHostQueue()->Remove(this);
114 // Immediately stop observing |host_contents_| because its destruction events 101 // Immediately stop observing |host_contents_| because its destruction events
115 // (like DidStopLoading, it turns out) can call back into ExtensionHost 102 // (like DidStopLoading, it turns out) can call back into ExtensionHost
116 // re-entrantly, when anything declared after |host_contents_| has already 103 // re-entrantly, when anything declared after |host_contents_| has already
117 // been destroyed. 104 // been destroyed.
118 content::WebContentsObserver::Observe(nullptr); 105 content::WebContentsObserver::Observe(nullptr);
119 } 106 }
120 107
121 content::RenderProcessHost* ExtensionHost::render_process_host() const { 108 content::RenderProcessHost* ExtensionHost::render_process_host() const {
122 return render_view_host()->GetProcess(); 109 return render_view_host()->GetProcess();
123 } 110 }
124 111
125 RenderViewHost* ExtensionHost::render_view_host() const { 112 RenderViewHost* ExtensionHost::render_view_host() const {
126 // TODO(mpcomplete): This can be null. How do we handle that? 113 // TODO(mpcomplete): This can be null. How do we handle that?
127 return render_view_host_; 114 return render_view_host_;
128 } 115 }
129 116
130 bool ExtensionHost::IsRenderViewLive() const { 117 bool ExtensionHost::IsRenderViewLive() const {
131 return render_view_host()->IsRenderViewLive(); 118 return render_view_host()->IsRenderViewLive();
132 } 119 }
133 120
134 void ExtensionHost::CreateRenderViewSoon() { 121 void ExtensionHost::CreateRenderViewSoon() {
135 if (render_process_host() && render_process_host()->HasConnection()) { 122 if (render_process_host() && render_process_host()->HasConnection()) {
136 // If the process is already started, go ahead and initialize the RenderView 123 // If the process is already started, go ahead and initialize the RenderView
137 // synchronously. The process creation is the real meaty part that we want 124 // synchronously. The process creation is the real meaty part that we want
138 // to defer. 125 // to defer.
139 CreateRenderViewNow(); 126 CreateRenderViewNow();
140 } else { 127 } else {
141 g_queue_wrapper.Get().queue->Add(this); 128 delegate_->GetExtensionHostQueue()->Add(this);
142 } 129 }
143 } 130 }
144 131
145 void ExtensionHost::CreateRenderViewNow() { 132 void ExtensionHost::CreateRenderViewNow() {
146 LoadInitialURL(); 133 LoadInitialURL();
147 if (IsBackgroundPage()) { 134 if (IsBackgroundPage()) {
148 DCHECK(IsRenderViewLive()); 135 DCHECK(IsRenderViewLive());
149 if (extension_) { 136 if (extension_) {
150 std::string group_name = base::FieldTrialList::FindFullName( 137 std::string group_name = base::FieldTrialList::FindFullName(
151 "ThrottleExtensionBackgroundPages"); 138 "ThrottleExtensionBackgroundPages");
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 return delegate_->CheckMediaAccessPermission( 419 return delegate_->CheckMediaAccessPermission(
433 web_contents, security_origin, type, extension()); 420 web_contents, security_origin, type, extension());
434 } 421 }
435 422
436 bool ExtensionHost::IsNeverVisible(content::WebContents* web_contents) { 423 bool ExtensionHost::IsNeverVisible(content::WebContents* web_contents) {
437 ViewType view_type = extensions::GetViewType(web_contents); 424 ViewType view_type = extensions::GetViewType(web_contents);
438 return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; 425 return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE;
439 } 426 }
440 427
441 } // namespace extensions 428 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/extension_host.h ('k') | extensions/browser/extension_host_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698