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

Side by Side Diff: content/browser/site_instance_impl.cc

Issue 72203003: Introduce RenderProcessHostObserver, use it in its first client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: release mode Created 7 years, 1 month 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 "content/browser/site_instance_impl.h" 5 #include "content/browser/site_instance_impl.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "content/browser/browsing_instance.h" 8 #include "content/browser/browsing_instance.h"
9 #include "content/browser/child_process_security_policy_impl.h" 9 #include "content/browser/child_process_security_policy_impl.h"
10 #include "content/browser/renderer_host/render_process_host_impl.h" 10 #include "content/browser/renderer_host/render_process_host_impl.h"
11 #include "content/browser/storage_partition_impl.h" 11 #include "content/browser/storage_partition_impl.h"
12 #include "content/public/browser/content_browser_client.h" 12 #include "content/public/browser/content_browser_client.h"
13 #include "content/public/browser/notification_service.h"
14 #include "content/public/browser/notification_types.h"
15 #include "content/public/browser/render_process_host_factory.h" 13 #include "content/public/browser/render_process_host_factory.h"
16 #include "content/public/browser/web_ui_controller_factory.h" 14 #include "content/public/browser/web_ui_controller_factory.h"
17 #include "content/public/common/content_switches.h" 15 #include "content/public/common/content_switches.h"
18 #include "content/public/common/url_constants.h" 16 #include "content/public/common/url_constants.h"
19 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 17 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
20 18
21 namespace content { 19 namespace content {
22 20
23 static bool IsURLSameAsAnySiteInstance(const GURL& url) { 21 static bool IsURLSameAsAnySiteInstance(const GURL& url) {
24 if (!url.is_valid()) 22 if (!url.is_valid())
(...skipping 14 matching lines...) Expand all
39 SiteInstanceImpl::g_render_process_host_factory_ = NULL; 37 SiteInstanceImpl::g_render_process_host_factory_ = NULL;
40 int32 SiteInstanceImpl::next_site_instance_id_ = 1; 38 int32 SiteInstanceImpl::next_site_instance_id_ = 1;
41 39
42 SiteInstanceImpl::SiteInstanceImpl(BrowsingInstance* browsing_instance) 40 SiteInstanceImpl::SiteInstanceImpl(BrowsingInstance* browsing_instance)
43 : id_(next_site_instance_id_++), 41 : id_(next_site_instance_id_++),
44 active_view_count_(0), 42 active_view_count_(0),
45 browsing_instance_(browsing_instance), 43 browsing_instance_(browsing_instance),
46 process_(NULL), 44 process_(NULL),
47 has_site_(false) { 45 has_site_(false) {
48 DCHECK(browsing_instance); 46 DCHECK(browsing_instance);
49
50 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_TERMINATED,
51 NotificationService::AllBrowserContextsAndSources());
52 } 47 }
53 48
54 SiteInstanceImpl::~SiteInstanceImpl() { 49 SiteInstanceImpl::~SiteInstanceImpl() {
55 GetContentClient()->browser()->SiteInstanceDeleting(this); 50 GetContentClient()->browser()->SiteInstanceDeleting(this);
56 51
52 if (process_)
53 process_->RemoveObserver(this);
54
57 // Now that no one is referencing us, we can safely remove ourselves from 55 // Now that no one is referencing us, we can safely remove ourselves from
58 // the BrowsingInstance. Any future visits to a page from this site 56 // the BrowsingInstance. Any future visits to a page from this site
59 // (within the same BrowsingInstance) can safely create a new SiteInstance. 57 // (within the same BrowsingInstance) can safely create a new SiteInstance.
60 if (has_site_) 58 if (has_site_)
61 browsing_instance_->UnregisterSiteInstance( 59 browsing_instance_->UnregisterSiteInstance(
62 static_cast<SiteInstance*>(this)); 60 static_cast<SiteInstance*>(this));
63 } 61 }
64 62
65 int32 SiteInstanceImpl::GetId() { 63 int32 SiteInstanceImpl::GetId() {
66 return id_; 64 return id_;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 BrowserContext::GetStoragePartition(browser_context, this)); 120 BrowserContext::GetStoragePartition(browser_context, this));
123 bool supports_browser_plugin = GetContentClient()->browser()-> 121 bool supports_browser_plugin = GetContentClient()->browser()->
124 SupportsBrowserPlugin(browser_context, site_); 122 SupportsBrowserPlugin(browser_context, site_);
125 process_ = new RenderProcessHostImpl(browser_context, 123 process_ = new RenderProcessHostImpl(browser_context,
126 partition, 124 partition,
127 supports_browser_plugin, 125 supports_browser_plugin,
128 site_.SchemeIs(kGuestScheme)); 126 site_.SchemeIs(kGuestScheme));
129 } 127 }
130 } 128 }
131 CHECK(process_); 129 CHECK(process_);
130 process_->AddObserver(this);
132 131
133 // If we are using process-per-site, we need to register this process 132 // If we are using process-per-site, we need to register this process
134 // for the current site so that we can find it again. (If no site is set 133 // for the current site so that we can find it again. (If no site is set
135 // at this time, we will register it in SetSite().) 134 // at this time, we will register it in SetSite().)
136 if (use_process_per_site) { 135 if (use_process_per_site) {
137 RenderProcessHostImpl::RegisterProcessHostForSite(browser_context, 136 RenderProcessHostImpl::RegisterProcessHostForSite(browser_context,
138 process_, site_); 137 process_, site_);
139 } 138 }
140 139
141 GetContentClient()->browser()->SiteInstanceGotProcess(this); 140 GetContentClient()->browser()->SiteInstanceGotProcess(this);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 return site; 318 return site;
320 } 319 }
321 320
322 /*static*/ 321 /*static*/
323 GURL SiteInstanceImpl::GetEffectiveURL(BrowserContext* browser_context, 322 GURL SiteInstanceImpl::GetEffectiveURL(BrowserContext* browser_context,
324 const GURL& url) { 323 const GURL& url) {
325 return GetContentClient()->browser()-> 324 return GetContentClient()->browser()->
326 GetEffectiveURL(browser_context, url); 325 GetEffectiveURL(browser_context, url);
327 } 326 }
328 327
329 void SiteInstanceImpl::Observe(int type, 328 void SiteInstanceImpl::RenderProcessHostDestroyed(RenderProcessHost* host) {
330 const NotificationSource& source, 329 DCHECK_EQ(process_, host);
331 const NotificationDetails& details) { 330 process_->RemoveObserver(this);
332 DCHECK(type == NOTIFICATION_RENDERER_PROCESS_TERMINATED); 331 process_ = NULL;
333 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr();
334 if (rph == process_)
335 process_ = NULL;
336 } 332 }
337 333
338 void SiteInstanceImpl::LockToOrigin() { 334 void SiteInstanceImpl::LockToOrigin() {
339 // We currently only restrict this process to a particular site if the 335 // We currently only restrict this process to a particular site if the
340 // --enable-strict-site-isolation or --site-per-process flags are present. 336 // --enable-strict-site-isolation or --site-per-process flags are present.
341 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 337 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
342 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) || 338 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) ||
343 command_line.HasSwitch(switches::kSitePerProcess)) { 339 command_line.HasSwitch(switches::kSitePerProcess)) {
344 ChildProcessSecurityPolicyImpl* policy = 340 ChildProcessSecurityPolicyImpl* policy =
345 ChildProcessSecurityPolicyImpl::GetInstance(); 341 ChildProcessSecurityPolicyImpl::GetInstance();
346 policy->LockToOrigin(process_->GetID(), site_); 342 policy->LockToOrigin(process_->GetID(), site_);
347 } 343 }
348 } 344 }
349 345
350 } // namespace content 346 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698