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

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

Issue 23618014: This defers starting background extension page RenderViews (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
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 "chrome/browser/extensions/extension_host.h" 5 #include "chrome/browser/extensions/extension_host.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/singleton.h" 10 #include "base/memory/singleton.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 static ProcessCreationQueue* GetInstance() { 77 static ProcessCreationQueue* GetInstance() {
78 return Singleton<ProcessCreationQueue>::get(); 78 return Singleton<ProcessCreationQueue>::get();
79 } 79 }
80 80
81 // Add a host to the queue for RenderView creation. 81 // Add a host to the queue for RenderView creation.
82 void CreateSoon(ExtensionHost* host) { 82 void CreateSoon(ExtensionHost* host) {
83 queue_.push_back(host); 83 queue_.push_back(host);
84 PostTask(); 84 PostTask();
85 } 85 }
86 86
87 void DeferCreation(ExtensionHost* host) {
88 deferred_queue_.push_back(host);
89 }
90
91 void CreateDeferredRenderViews() {
92 queue_.splice(queue_.end(), deferred_queue_);
93 PostTask();
94 }
95
87 // Remove a host from the queue (in case it's being deleted). 96 // Remove a host from the queue (in case it's being deleted).
88 void Remove(ExtensionHost* host) { 97 void Remove(ExtensionHost* host) {
89 Queue::iterator it = std::find(queue_.begin(), queue_.end(), host); 98 Queue::iterator it = std::find(queue_.begin(), queue_.end(), host);
90 if (it != queue_.end()) 99 if (it != queue_.end())
91 queue_.erase(it); 100 queue_.erase(it);
101 it = std::find(deferred_queue_.begin(), deferred_queue_.end(), host);
102 if (it != deferred_queue_.end())
103 deferred_queue_.erase(it);
92 } 104 }
93 105
94 private: 106 private:
95 friend class Singleton<ProcessCreationQueue>; 107 friend class Singleton<ProcessCreationQueue>;
96 friend struct DefaultSingletonTraits<ProcessCreationQueue>; 108 friend struct DefaultSingletonTraits<ProcessCreationQueue>;
97 ProcessCreationQueue() 109 ProcessCreationQueue()
98 : pending_create_(false), 110 : pending_create_(false),
99 ptr_factory_(this) {} 111 ptr_factory_(this) {}
100 112
101 // Queue up a delayed task to process the next ExtensionHost in the queue. 113 // Queue up a delayed task to process the next ExtensionHost in the queue.
(...skipping 14 matching lines...) Expand all
116 128
117 queue_.front()->CreateRenderViewNow(); 129 queue_.front()->CreateRenderViewNow();
118 queue_.pop_front(); 130 queue_.pop_front();
119 131
120 if (!queue_.empty()) 132 if (!queue_.empty())
121 PostTask(); 133 PostTask();
122 } 134 }
123 135
124 typedef std::list<ExtensionHost*> Queue; 136 typedef std::list<ExtensionHost*> Queue;
125 Queue queue_; 137 Queue queue_;
138 Queue deferred_queue_;
126 bool pending_create_; 139 bool pending_create_;
127 base::WeakPtrFactory<ProcessCreationQueue> ptr_factory_; 140 base::WeakPtrFactory<ProcessCreationQueue> ptr_factory_;
128 }; 141 };
129 142
130 //////////////// 143 ////////////////
131 // ExtensionHost 144 // ExtensionHost
132 145
133 ExtensionHost::ExtensionHost(const Extension* extension, 146 ExtensionHost::ExtensionHost(const Extension* extension,
134 SiteInstance* site_instance, 147 SiteInstance* site_instance,
135 const GURL& url, 148 const GURL& url,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 237 }
225 238
226 bool ExtensionHost::IsRenderViewLive() const { 239 bool ExtensionHost::IsRenderViewLive() const {
227 return render_view_host()->IsRenderViewLive(); 240 return render_view_host()->IsRenderViewLive();
228 } 241 }
229 242
230 void ExtensionHost::CreateRenderViewSoon() { 243 void ExtensionHost::CreateRenderViewSoon() {
231 if ((render_process_host() && render_process_host()->HasConnection())) { 244 if ((render_process_host() && render_process_host()->HasConnection())) {
232 // If the process is already started, go ahead and initialize the RenderView 245 // If the process is already started, go ahead and initialize the RenderView
233 // synchronously. The process creation is the real meaty part that we want 246 // synchronously. The process creation is the real meaty part that we want
247 // to rate limit.
248 CreateRenderViewNow();
249 } else {
250 ProcessCreationQueue::GetInstance()->CreateSoon(this);
251 }
252 }
253
254 void ExtensionHost::CreateRenderViewDeferred() {
255 if ((render_process_host() && render_process_host()->HasConnection())) {
256 // If the process is already started, go ahead and initialize the RenderView
257 // synchronously. The process creation is the real meaty part that we want
234 // to defer. 258 // to defer.
235 CreateRenderViewNow(); 259 CreateRenderViewNow();
236 } else { 260 } else {
237 ProcessCreationQueue::GetInstance()->CreateSoon(this); 261 ProcessCreationQueue::GetInstance()->DeferCreation(this);
238 } 262 }
239 } 263 }
240 264
265 // static
266 void ExtensionHost::CreateDeferredRenderViews() {
267 ProcessCreationQueue::GetInstance()->CreateDeferredRenderViews();
268 }
269
241 void ExtensionHost::CreateRenderViewNow() { 270 void ExtensionHost::CreateRenderViewNow() {
242 LoadInitialURL(); 271 LoadInitialURL();
243 if (is_background_page()) { 272 if (is_background_page()) {
244 DCHECK(IsRenderViewLive()); 273 DCHECK(IsRenderViewLive());
245 ExtensionSystem::Get(profile_)->extension_service()-> 274 ExtensionSystem::Get(profile_)->extension_service()->
246 DidCreateRenderViewForBackgroundPage(this); 275 DidCreateRenderViewForBackgroundPage(this);
247 } 276 }
248 } 277 }
249 278
250 WindowController* ExtensionHost::GetExtensionWindowController() const { 279 WindowController* ExtensionHost::GetExtensionWindowController() const {
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 698
670 void ExtensionHost::RequestMediaAccessPermission( 699 void ExtensionHost::RequestMediaAccessPermission(
671 content::WebContents* web_contents, 700 content::WebContents* web_contents,
672 const content::MediaStreamRequest& request, 701 const content::MediaStreamRequest& request,
673 const content::MediaResponseCallback& callback) { 702 const content::MediaResponseCallback& callback) {
674 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( 703 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest(
675 web_contents, request, callback, extension()); 704 web_contents, request, callback, extension());
676 } 705 }
677 706
678 } // namespace extensions 707 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698