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

Side by Side Diff: chrome/browser/renderer_host/site_instance.cc

Issue 2928004: Add unit test and supporting code to test process overflow case. (Closed)
Patch Set: linux compile error Created 10 years, 5 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-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/renderer_host/site_instance.h" 5 #include "chrome/browser/renderer_host/site_instance.h"
6 6
7 #include "chrome/browser/browsing_instance.h" 7 #include "chrome/browser/browsing_instance.h"
8 #include "chrome/browser/dom_ui/dom_ui_factory.h" 8 #include "chrome/browser/dom_ui/dom_ui_factory.h"
9 #include "chrome/browser/extensions/extensions_service.h" 9 #include "chrome/browser/extensions/extensions_service.h"
10 #include "chrome/browser/renderer_host/browser_render_process_host.h" 10 #include "chrome/browser/renderer_host/browser_render_process_host.h"
(...skipping 30 matching lines...) Expand all
41 // (within the same BrowsingInstance) can safely create a new SiteInstance. 41 // (within the same BrowsingInstance) can safely create a new SiteInstance.
42 if (has_site_) 42 if (has_site_)
43 browsing_instance_->UnregisterSiteInstance(this); 43 browsing_instance_->UnregisterSiteInstance(this);
44 } 44 }
45 45
46 bool SiteInstance::HasProcess() const { 46 bool SiteInstance::HasProcess() const {
47 return (process_ != NULL); 47 return (process_ != NULL);
48 } 48 }
49 49
50 RenderProcessHost* SiteInstance::GetProcess() { 50 RenderProcessHost* SiteInstance::GetProcess() {
51 // TODO(erikkay) It would be nice to ensure that the renderer type had been
52 // properly set before we get here. The default tab creation case winds up
53 // with no site set at this point, so it will default to TYPE_NORMAL. This
54 // may not be correct, so we'll wind up potentially creating a process that
55 // we then throw away, or worse sharing a process with the wrong process type.
56 // See crbug.com/43448.
57
51 // Create a new process if ours went away or was reused. 58 // Create a new process if ours went away or was reused.
52 if (!process_) { 59 if (!process_) {
53 // See if we should reuse an old process 60 // See if we should reuse an old process
54 if (RenderProcessHost::ShouldTryToUseExistingProcessHost()) 61 if (RenderProcessHost::ShouldTryToUseExistingProcessHost())
55 process_ = RenderProcessHost::GetExistingProcessHost( 62 process_ = RenderProcessHost::GetExistingProcessHost(
56 browsing_instance_->profile(), GetRendererType()); 63 browsing_instance_->profile(), GetRendererType());
57 64
58 // Otherwise (or if that fails), create a new one. 65 // Otherwise (or if that fails), create a new one.
59 if (!process_) { 66 if (!process_) {
60 if (render_process_host_factory_) { 67 if (render_process_host_factory_) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 profile->GetExtensionsService()->GetExtensionByWebExtent(url); 194 profile->GetExtensionsService()->GetExtensionByWebExtent(url);
188 if (extension) { 195 if (extension) {
189 // If the URL is part of an extension's web extent, convert it to an 196 // If the URL is part of an extension's web extent, convert it to an
190 // extension URL. 197 // extension URL.
191 return extension->GetResourceURL(url.path()); 198 return extension->GetResourceURL(url.path());
192 } else { 199 } else {
193 return url; 200 return url;
194 } 201 }
195 } 202 }
196 203
204 /*static*/
205 RenderProcessHost::Type SiteInstance::RendererTypeForURL(const GURL& url) {
206 if (!url.is_valid())
207 return RenderProcessHost::TYPE_NORMAL;
208
209 if (url.SchemeIs(chrome::kExtensionScheme))
210 return RenderProcessHost::TYPE_EXTENSION;
211
212 // TODO(erikkay) creis recommends using UseDOMUIForURL instead.
213 if (DOMUIFactory::HasDOMUIScheme(url))
214 return RenderProcessHost::TYPE_DOMUI;
215
216 return RenderProcessHost::TYPE_NORMAL;
217 }
218
197 RenderProcessHost::Type SiteInstance::GetRendererType() { 219 RenderProcessHost::Type SiteInstance::GetRendererType() {
198 // We may not have a site at this point, which generally means this is a 220 // We may not have a site at this point, which generally means this is a
199 // normal navigation. 221 // normal navigation.
200 if (!has_site_ || !site_.is_valid()) 222 if (!has_site_)
201 return RenderProcessHost::TYPE_NORMAL; 223 return RenderProcessHost::TYPE_NORMAL;
202 224
203 if (site_.SchemeIs(chrome::kExtensionScheme)) 225 return RendererTypeForURL(site_);
204 return RenderProcessHost::TYPE_EXTENSION;
205
206 if (DOMUIFactory::HasDOMUIScheme(site_))
207 return RenderProcessHost::TYPE_DOMUI;
208
209 return RenderProcessHost::TYPE_NORMAL;
210 } 226 }
211 227
212 void SiteInstance::Observe(NotificationType type, 228 void SiteInstance::Observe(NotificationType type,
213 const NotificationSource& source, 229 const NotificationSource& source,
214 const NotificationDetails& details) { 230 const NotificationDetails& details) {
215 DCHECK(type == NotificationType::RENDERER_PROCESS_TERMINATED); 231 DCHECK(type == NotificationType::RENDERER_PROCESS_TERMINATED);
216 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr(); 232 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr();
217 if (rph == process_) 233 if (rph == process_)
218 process_ = NULL; 234 process_ = NULL;
219 } 235 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/site_instance.h ('k') | chrome/browser/renderer_host/test/render_process_host_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698