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

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

Issue 243007: Retry r27137. Create renderers for ExtensionHosts one at a time to avoid blocking the UI. (Closed)
Patch Set: fix linux crash Created 11 years, 2 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 (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 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>
8
7 #include "app/resource_bundle.h" 9 #include "app/resource_bundle.h"
10 #include "base/message_loop.h"
11 #include "base/singleton.h"
8 #include "base/string_util.h" 12 #include "base/string_util.h"
9 #include "chrome/browser/browser.h" 13 #include "chrome/browser/browser.h"
10 #include "chrome/browser/browser_list.h" 14 #include "chrome/browser/browser_list.h"
11 #include "chrome/browser/browser_theme_provider.h" 15 #include "chrome/browser/browser_theme_provider.h"
12 #include "chrome/browser/debugger/devtools_manager.h" 16 #include "chrome/browser/debugger/devtools_manager.h"
13 #include "chrome/browser/dom_ui/dom_ui_factory.h" 17 #include "chrome/browser/dom_ui/dom_ui_factory.h"
14 #include "chrome/browser/extensions/extension_message_service.h" 18 #include "chrome/browser/extensions/extension_message_service.h"
15 #include "chrome/browser/extensions/extension_tabs_module.h" 19 #include "chrome/browser/extensions/extension_tabs_module.h"
16 #include "chrome/browser/profile.h" 20 #include "chrome/browser/profile.h"
17 #include "chrome/browser/renderer_host/render_view_host.h" 21 #include "chrome/browser/renderer_host/render_view_host.h"
(...skipping 15 matching lines...) Expand all
33 #include "webkit/glue/context_menu.h" 37 #include "webkit/glue/context_menu.h"
34 38
35 using WebKit::WebDragOperation; 39 using WebKit::WebDragOperation;
36 using WebKit::WebDragOperationsMask; 40 using WebKit::WebDragOperationsMask;
37 41
38 // static 42 // static
39 bool ExtensionHost::enable_dom_automation_ = false; 43 bool ExtensionHost::enable_dom_automation_ = false;
40 44
41 static const char* kToolstripTextColorSubstitution = "$TEXT_COLOR$"; 45 static const char* kToolstripTextColorSubstitution = "$TEXT_COLOR$";
42 46
47 // Helper class that rate-limits the creation of renderer processes for
48 // ExtensionHosts, to avoid blocking the UI.
49 class ExtensionHost::ProcessCreationQueue {
50 public:
51 static ProcessCreationQueue* get() {
52 return Singleton<ProcessCreationQueue>::get();
53 }
54
55 // Add a host to the queue for RenderView creation.
56 void CreateSoon(ExtensionHost* host) {
57 queue_.push_back(host);
58 PostTask();
59 }
60
61 // Remove a host from the queue (in case it's being deleted).
62 void Remove(ExtensionHost* host) {
63 Queue::iterator it = std::find(queue_.begin(), queue_.end(), host);
64 if (it != queue_.end())
65 queue_.erase(it);
66 }
67
68 private:
69 friend class Singleton<ProcessCreationQueue>;
70 friend struct DefaultSingletonTraits<ProcessCreationQueue>;
71 ProcessCreationQueue()
72 : pending_create_(false),
73 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { }
74
75 // Queue up a delayed task to process the next ExtensionHost in the queue.
76 void PostTask() {
77 if (!pending_create_) {
78 MessageLoop::current()->PostTask(FROM_HERE,
79 method_factory_.NewRunnableMethod(
80 &ProcessCreationQueue::ProcessOneHost));
81 pending_create_ = true;
82 }
83 }
84
85 // Create the RenderView for the next host in the queue.
86 void ProcessOneHost() {
87 pending_create_ = false;
88 if (queue_.empty())
89 return; // can happen on shutdown
90
91 queue_.front()->CreateRenderViewNow();
92 queue_.pop_front();
93
94 if (!queue_.empty())
95 PostTask();
96 }
97
98 typedef std::list<ExtensionHost*> Queue;
99 Queue queue_;
100 bool pending_create_;
101 ScopedRunnableMethodFactory<ProcessCreationQueue> method_factory_;
102 };
103
104 ////////////////
105 // ExtensionHost
106
43 ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance, 107 ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance,
44 const GURL& url, ViewType::Type host_type) 108 const GURL& url, ViewType::Type host_type)
45 : extension_(extension), 109 : extension_(extension),
46 profile_(site_instance->browsing_instance()->profile()), 110 profile_(site_instance->browsing_instance()->profile()),
47 did_stop_loading_(false), 111 did_stop_loading_(false),
48 document_element_available_(false), 112 document_element_available_(false),
49 url_(url), 113 url_(url),
50 extension_host_type_(host_type) { 114 extension_host_type_(host_type) {
51 render_view_host_ = new RenderViewHost( 115 render_view_host_ = new RenderViewHost(
52 site_instance, this, MSG_ROUTING_NONE, NULL); 116 site_instance, this, MSG_ROUTING_NONE, NULL);
53 render_view_host_->AllowBindings(BindingsPolicy::EXTENSION); 117 render_view_host_->AllowBindings(BindingsPolicy::EXTENSION);
54 if (enable_dom_automation_) 118 if (enable_dom_automation_)
55 render_view_host_->AllowBindings(BindingsPolicy::DOM_AUTOMATION); 119 render_view_host_->AllowBindings(BindingsPolicy::DOM_AUTOMATION);
56 } 120 }
57 121
58 ExtensionHost::~ExtensionHost() { 122 ExtensionHost::~ExtensionHost() {
59 NotificationService::current()->Notify( 123 NotificationService::current()->Notify(
60 NotificationType::EXTENSION_HOST_DESTROYED, 124 NotificationType::EXTENSION_HOST_DESTROYED,
61 Source<Profile>(profile_), 125 Source<Profile>(profile_),
62 Details<ExtensionHost>(this)); 126 Details<ExtensionHost>(this));
127 ProcessCreationQueue::get()->Remove(this);
63 render_view_host_->Shutdown(); // deletes render_view_host 128 render_view_host_->Shutdown(); // deletes render_view_host
64 } 129 }
65 130
66 void ExtensionHost::CreateView(Browser* browser) { 131 void ExtensionHost::CreateView(Browser* browser) {
67 #if defined(TOOLKIT_VIEWS) 132 #if defined(TOOLKIT_VIEWS)
68 view_.reset(new ExtensionView(this, browser)); 133 view_.reset(new ExtensionView(this, browser));
69 // We own |view_|, so don't auto delete when it's removed from the view 134 // We own |view_|, so don't auto delete when it's removed from the view
70 // hierarchy. 135 // hierarchy.
71 view_->SetParentOwned(false); 136 view_->SetParentOwned(false);
72 #elif defined(OS_LINUX) 137 #elif defined(OS_LINUX)
(...skipping 13 matching lines...) Expand all
86 } 151 }
87 152
88 SiteInstance* ExtensionHost::site_instance() const { 153 SiteInstance* ExtensionHost::site_instance() const {
89 return render_view_host_->site_instance(); 154 return render_view_host_->site_instance();
90 } 155 }
91 156
92 bool ExtensionHost::IsRenderViewLive() const { 157 bool ExtensionHost::IsRenderViewLive() const {
93 return render_view_host_->IsRenderViewLive(); 158 return render_view_host_->IsRenderViewLive();
94 } 159 }
95 160
96 void ExtensionHost::CreateRenderView(RenderWidgetHostView* host_view) { 161 void ExtensionHost::CreateRenderViewSoon(RenderWidgetHostView* host_view) {
97 LOG(INFO) << "Creating RenderView for " + extension_->name(); 162 LOG(INFO) << "Creating RenderView for " + extension_->name();
98 render_view_host_->set_view(host_view); 163 render_view_host_->set_view(host_view);
164 ProcessCreationQueue::get()->CreateSoon(this);
165 }
166
167 void ExtensionHost::CreateRenderViewNow() {
99 render_view_host_->CreateRenderView(); 168 render_view_host_->CreateRenderView();
100 NavigateToURL(url_); 169 NavigateToURL(url_);
101 DCHECK(IsRenderViewLive()); 170 DCHECK(IsRenderViewLive());
102 LOG(INFO) << "Sending EXTENSION_PROCESS_CREATED"; 171 LOG(INFO) << "Sending EXTENSION_PROCESS_CREATED";
103 NotificationService::current()->Notify( 172 NotificationService::current()->Notify(
104 NotificationType::EXTENSION_PROCESS_CREATED, 173 NotificationType::EXTENSION_PROCESS_CREATED,
105 Source<Profile>(profile_), 174 Source<Profile>(profile_),
106 Details<ExtensionHost>(this)); 175 Details<ExtensionHost>(this));
107 } 176 }
108 177
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 window_id = ExtensionTabUtil::GetWindowId( 480 window_id = ExtensionTabUtil::GetWindowId(
412 const_cast<ExtensionHost* >(this)->GetBrowser()); 481 const_cast<ExtensionHost* >(this)->GetBrowser());
413 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) { 482 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) {
414 // Background page is not attached to any browser window, so pass -1. 483 // Background page is not attached to any browser window, so pass -1.
415 window_id = -1; 484 window_id = -1;
416 } else { 485 } else {
417 NOTREACHED(); 486 NOTREACHED();
418 } 487 }
419 return window_id; 488 return window_id;
420 } 489 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_host.h ('k') | chrome/browser/extensions/extension_process_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698