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

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: delegate + rename 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
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" 7 #include "base/lazy_instance.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 using content::BrowserContext; 44 using content::BrowserContext;
45 using content::OpenURLParams; 45 using content::OpenURLParams;
46 using content::RenderProcessHost; 46 using content::RenderProcessHost;
47 using content::RenderViewHost; 47 using content::RenderViewHost;
48 using content::SiteInstance; 48 using content::SiteInstance;
49 using content::WebContents; 49 using content::WebContents;
50 50
51 namespace extensions { 51 namespace extensions {
52 52
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, 53 ExtensionHost::ExtensionHost(const Extension* extension,
65 SiteInstance* site_instance, 54 SiteInstance* site_instance,
66 const GURL& url, 55 const GURL& url,
67 ViewType host_type) 56 ViewType host_type)
68 : delegate_(ExtensionsBrowserClient::Get()->CreateExtensionHostDelegate()), 57 : delegate_(ExtensionsBrowserClient::Get()->CreateExtensionHostDelegate()),
69 extension_(extension), 58 extension_(extension),
70 extension_id_(extension->id()), 59 extension_id_(extension->id()),
71 browser_context_(site_instance->GetBrowserContext()), 60 browser_context_(site_instance->GetBrowserContext()),
72 render_view_host_(nullptr), 61 render_view_host_(nullptr),
73 did_stop_loading_(false), 62 did_stop_loading_(false),
(...skipping 29 matching lines...) Expand all
103 load_start_.get()) { 92 load_start_.get()) {
104 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime2", 93 UMA_HISTOGRAM_LONG_TIMES("Extensions.EventPageActiveTime2",
105 load_start_->Elapsed()); 94 load_start_->Elapsed());
106 } 95 }
107 content::NotificationService::current()->Notify( 96 content::NotificationService::current()->Notify(
108 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED, 97 extensions::NOTIFICATION_EXTENSION_HOST_DESTROYED,
109 content::Source<BrowserContext>(browser_context_), 98 content::Source<BrowserContext>(browser_context_),
110 content::Details<ExtensionHost>(this)); 99 content::Details<ExtensionHost>(this));
111 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_, 100 FOR_EACH_OBSERVER(ExtensionHostObserver, observer_list_,
112 OnExtensionHostDestroyed(this)); 101 OnExtensionHostDestroyed(this));
113 g_queue_wrapper.Get().queue->Remove(this); 102 delegate_->GetExtensionHostQueue()->Remove(this);
114 // Immediately stop observing |host_contents_| because its destruction events 103 // Immediately stop observing |host_contents_| because its destruction events
115 // (like DidStopLoading, it turns out) can call back into ExtensionHost 104 // (like DidStopLoading, it turns out) can call back into ExtensionHost
116 // re-entrantly, when anything declared after |host_contents_| has already 105 // re-entrantly, when anything declared after |host_contents_| has already
117 // been destroyed. 106 // been destroyed.
118 content::WebContentsObserver::Observe(nullptr); 107 content::WebContentsObserver::Observe(nullptr);
119 } 108 }
120 109
121 content::RenderProcessHost* ExtensionHost::render_process_host() const { 110 content::RenderProcessHost* ExtensionHost::render_process_host() const {
122 return render_view_host()->GetProcess(); 111 return render_view_host()->GetProcess();
123 } 112 }
124 113
125 RenderViewHost* ExtensionHost::render_view_host() const { 114 RenderViewHost* ExtensionHost::render_view_host() const {
126 // TODO(mpcomplete): This can be null. How do we handle that? 115 // TODO(mpcomplete): This can be null. How do we handle that?
127 return render_view_host_; 116 return render_view_host_;
128 } 117 }
129 118
130 bool ExtensionHost::IsRenderViewLive() const { 119 bool ExtensionHost::IsRenderViewLive() const {
131 return render_view_host()->IsRenderViewLive(); 120 return render_view_host()->IsRenderViewLive();
132 } 121 }
133 122
134 void ExtensionHost::CreateRenderViewSoon() { 123 void ExtensionHost::CreateRenderViewSoon() {
135 if (render_process_host() && render_process_host()->HasConnection()) { 124 if (render_process_host() && render_process_host()->HasConnection()) {
136 // If the process is already started, go ahead and initialize the RenderView 125 // 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 126 // synchronously. The process creation is the real meaty part that we want
138 // to defer. 127 // to defer.
139 CreateRenderViewNow(); 128 CreateRenderViewNow();
140 } else { 129 } else {
141 g_queue_wrapper.Get().queue->Add(this); 130 delegate_->GetExtensionHostQueue()->Add(this);
142 } 131 }
143 } 132 }
144 133
145 void ExtensionHost::CreateRenderViewNow() { 134 void ExtensionHost::CreateRenderViewNow() {
146 LoadInitialURL(); 135 LoadInitialURL();
147 if (IsBackgroundPage()) { 136 if (IsBackgroundPage()) {
148 DCHECK(IsRenderViewLive()); 137 DCHECK(IsRenderViewLive());
149 if (extension_) { 138 if (extension_) {
150 std::string group_name = base::FieldTrialList::FindFullName( 139 std::string group_name = base::FieldTrialList::FindFullName(
151 "ThrottleExtensionBackgroundPages"); 140 "ThrottleExtensionBackgroundPages");
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 return delegate_->CheckMediaAccessPermission( 421 return delegate_->CheckMediaAccessPermission(
433 web_contents, security_origin, type, extension()); 422 web_contents, security_origin, type, extension());
434 } 423 }
435 424
436 bool ExtensionHost::IsNeverVisible(content::WebContents* web_contents) { 425 bool ExtensionHost::IsNeverVisible(content::WebContents* web_contents) {
437 ViewType view_type = extensions::GetViewType(web_contents); 426 ViewType view_type = extensions::GetViewType(web_contents);
438 return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE; 427 return view_type == extensions::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE;
439 } 428 }
440 429
441 } // namespace extensions 430 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698