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

Side by Side Diff: content/browser/renderer_host/render_process_host_impl.cc

Issue 2929113002: Enable spare RenderProcessHost to be preinitialized. (Closed)
Patch Set: Change creation of storage partition to not break unittests with subtle threading issues Created 3 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 // Represents the browser side of the browser <--> renderer communication 5 // Represents the browser side of the browser <--> renderer communication
6 // channel. There will be one RenderProcessHost per renderer process. 6 // channel. There will be one RenderProcessHost per renderer process.
7 7
8 #include "content/browser/renderer_host/render_process_host_impl.h" 8 #include "content/browser/renderer_host/render_process_host_impl.h"
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 void Release(int old_route_id) { 457 void Release(int old_route_id) {
458 session_storage_namespaces_awaiting_close_->erase(old_route_id); 458 session_storage_namespaces_awaiting_close_->erase(old_route_id);
459 } 459 }
460 460
461 private: 461 private:
462 std::unique_ptr<std::map<int, SessionStorageNamespaceMap>> 462 std::unique_ptr<std::map<int, SessionStorageNamespaceMap>>
463 session_storage_namespaces_awaiting_close_; 463 session_storage_namespaces_awaiting_close_;
464 DISALLOW_COPY_AND_ASSIGN(SessionStorageHolder); 464 DISALLOW_COPY_AND_ASSIGN(SessionStorageHolder);
465 }; 465 };
466 466
467 // This class manages spare RenderProcessHosts.
468 //
469 // There is a singleton instance of this class which manages a single spare
470 // renderer (g_spare_render_process_host_manager, below). This class
471 // encapsulates the implementation of
472 // RenderProcessHost::WarmupSpareRenderProcessHost()
473 //
474 // RenderProcessHostImpl should call
475 // SpareRenderProcessHostManager::MaybeTakeSpareRenderProcessHost when creating
476 // a new RPH. In this implementation, the spare renderer is bound to a
477 // BrowserContext and its default StoragePartition. If
478 // MaybeTakeSpareRenderProcessHost is called with a BrowserContext and
479 // StoragePartition that does not match, the spare renderer is discarded. In
480 // particular, only the default StoragePartition will be able to use a spare
481 // renderer. The spare renderer will also not be used as a guest renderer
482 // (is_for_guests_ == true).
483 //
484 // It is safe to call WarmupSpareRenderProcessHost multiple times, although if
485 // called in a context where the spare renderer is not likely to be used
486 // performance may suffer due to the unnecessary RPH creation.
487 class SpareRenderProcessHostManager : public RenderProcessHostObserver {
488 public:
489 SpareRenderProcessHostManager() {}
490
491 void WarmupSpareRenderProcessHost(BrowserContext* browser_context) {
492 StoragePartitionImpl* current_partition =
493 static_cast<StoragePartitionImpl*>(
494 BrowserContext::GetStoragePartition(browser_context, nullptr));
495
496 if (spare_render_process_host_ &&
497 matching_browser_context_ == browser_context &&
498 matching_storage_partition_ == current_partition)
499 return; // Nothing to warm up.
500
501 CleanupSpareRenderProcessHost();
502
503 // Don't create a spare renderer if we're using --single-process or if we've
504 // got too many processes. See also ShouldTryToUseExistingProcessHost in
505 // this file.
506 if (RenderProcessHost::run_renderer_in_process() ||
507 g_all_hosts.Get().size() >=
508 RenderProcessHostImpl::GetMaxRendererProcessCount())
509 return;
510
511 matching_browser_context_ = browser_context;
512 matching_storage_partition_ = current_partition;
513
514 spare_render_process_host_ = RenderProcessHostImpl::CreateRenderProcessHost(
515 browser_context, current_partition, nullptr,
516 false /* is_for_guests_only */);
517 spare_render_process_host_->AddObserver(this);
518 spare_render_process_host_->Init();
519 }
520
521 // If |partition| is null, this gets the default partition from the browser
522 // context.
523 RenderProcessHost* MaybeTakeSpareRenderProcessHost(
524 BrowserContext* browser_context,
525 StoragePartition* partition,
526 SiteInstance* site_instance,
527 bool is_for_guests_only) {
528 if (spare_render_process_host_ &&
529 browser_context == matching_browser_context_ && !is_for_guests_only &&
530 !partition) {
531 // If the spare renderer matches for everything but possibly the storage
532 // partition, and the passed-in partition is null, get the default storage
533 // partition. If this is the case, the default storage partition will
534 // already have been created and there is no possibility of breaking tests
535 // by GetDefaultStoragePartition prematurely creating one.
536 partition =
537 BrowserContext::GetStoragePartition(browser_context, site_instance);
538 }
539
540 if (!spare_render_process_host_ ||
541 browser_context != matching_browser_context_ ||
542 partition != matching_storage_partition_ || is_for_guests_only) {
543 // As a new RenderProcessHost will almost certainly be created, we cleanup
544 // the non-matching one so as not to waste resources.
545 CleanupSpareRenderProcessHost();
546 return nullptr;
547 }
548
549 CHECK(spare_render_process_host_->HostHasNotBeenUsed());
550 RenderProcessHost* rph = spare_render_process_host_;
551 DropSpareRenderProcessHost(spare_render_process_host_);
552 return rph;
553 }
554
555 // Remove |host| as a possible spare renderer. Does not shut it down cleanly;
556 // the assumption is that the host was shutdown somewhere else and has
557 // notifying the SpareRenderProcessHostManager.
558 void DropSpareRenderProcessHost(RenderProcessHost* host) {
559 if (spare_render_process_host_ && spare_render_process_host_ == host) {
560 spare_render_process_host_->RemoveObserver(this);
561 spare_render_process_host_ = nullptr;
562 }
563 }
564
565 // Remove |host| as a possible spare renderer. If |host| is not the spare
566 // renderer, then shut down the spare renderer. The idea is that a navigation
567 // was just made to |host|, and we do not expect another immediate navigation,
568 // so that the spare renderer can be dropped in order to free up resources.
569 void DropSpareOnProcessCreation(RenderProcessHost* new_host) {
570 if (spare_render_process_host_ == new_host) {
571 DropSpareRenderProcessHost(new_host);
572 } else {
573 CleanupSpareRenderProcessHost();
574 }
575 }
576
577 // Gracefully remove and cleanup a spare RenderProcessHost if it exists.
578 void CleanupSpareRenderProcessHost() {
579 if (spare_render_process_host_) {
580 spare_render_process_host_->Cleanup();
581 DropSpareRenderProcessHost(spare_render_process_host_);
582 }
583 }
584
585 RenderProcessHost* spare_render_process_host() {
586 return spare_render_process_host_;
587 }
588
589 private:
590 // RenderProcessHostObserver
591 void RenderProcessWillExit(RenderProcessHost* host) override {
592 DropSpareRenderProcessHost(host);
593 }
594
595 void RenderProcessExited(RenderProcessHost* host,
596 base::TerminationStatus unused_status,
597 int unused_exit_code) override {
598 DropSpareRenderProcessHost(host);
599 }
600
601 void RenderProcessHostDestroyed(RenderProcessHost* host) override {
602 DropSpareRenderProcessHost(host);
603 }
604
605 // This is a bare pointer, because RenderProcessHost manages the lifetime of
606 // all its instances; see g_all_hosts, above.
607 RenderProcessHost* spare_render_process_host_ = nullptr;
608
609 // Used only to check if a creation request matches the spare, and not
610 // accessed.
611 const BrowserContext* matching_browser_context_ = nullptr;
612 const StoragePartition* matching_storage_partition_ = nullptr;
613
614 DISALLOW_COPY_AND_ASSIGN(SpareRenderProcessHostManager);
615 };
616
617 base::LazyInstance<SpareRenderProcessHostManager>::Leaky
618 g_spare_render_process_host_manager = LAZY_INSTANCE_INITIALIZER;
619
467 const void* const kDefaultSubframeProcessHostHolderKey = 620 const void* const kDefaultSubframeProcessHostHolderKey =
468 &kDefaultSubframeProcessHostHolderKey; 621 &kDefaultSubframeProcessHostHolderKey;
469 622
470 class DefaultSubframeProcessHostHolder : public base::SupportsUserData::Data, 623 class DefaultSubframeProcessHostHolder : public base::SupportsUserData::Data,
471 public RenderProcessHostObserver { 624 public RenderProcessHostObserver {
472 public: 625 public:
473 explicit DefaultSubframeProcessHostHolder(BrowserContext* browser_context) 626 explicit DefaultSubframeProcessHostHolder(BrowserContext* browser_context)
474 : browser_context_(browser_context) {} 627 : browser_context_(browser_context) {}
475 ~DefaultSubframeProcessHostHolder() override {} 628 ~DefaultSubframeProcessHostHolder() override {}
476 629
477 // Gets the correct render process to use for this SiteInstance. 630 // Gets the correct render process to use for this SiteInstance.
478 RenderProcessHost* GetProcessHost(SiteInstance* site_instance, 631 RenderProcessHost* GetProcessHost(SiteInstance* site_instance,
479 bool is_for_guests_only) { 632 bool is_for_guests_only) {
480 StoragePartition* default_partition = 633 StoragePartitionImpl* default_partition =
481 BrowserContext::GetDefaultStoragePartition(browser_context_); 634 static_cast<StoragePartitionImpl*>(
482 StoragePartition* partition = 635 BrowserContext::GetDefaultStoragePartition(browser_context_));
483 BrowserContext::GetStoragePartition(browser_context_, site_instance); 636 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
637 BrowserContext::GetStoragePartition(browser_context_, site_instance));
484 638
485 // Is this the default storage partition? If it isn't, then just give it its 639 // Is this the default storage partition? If it isn't, then just give it its
486 // own non-shared process. 640 // own non-shared process.
487 if (partition != default_partition || is_for_guests_only) { 641 if (partition != default_partition || is_for_guests_only) {
488 RenderProcessHostImpl* host = new RenderProcessHostImpl( 642 RenderProcessHost* host = RenderProcessHostImpl::CreateRenderProcessHost(
489 browser_context_, static_cast<StoragePartitionImpl*>(partition), 643 browser_context_, partition, site_instance, is_for_guests_only);
490 is_for_guests_only);
491 host->SetIsNeverSuitableForReuse(); 644 host->SetIsNeverSuitableForReuse();
492 return host; 645 return host;
493 } 646 }
494 647
495 // If we already have a shared host for the default storage partition, use 648 // If we already have a shared host for the default storage partition, use
496 // it. 649 // it.
497 if (host_) 650 if (host_)
498 return host_; 651 return host_;
499 652
500 host_ = new RenderProcessHostImpl( 653 host_ = RenderProcessHostImpl::CreateOrUseSpareRenderProcessHost(
501 browser_context_, static_cast<StoragePartitionImpl*>(partition), 654 browser_context_, partition, site_instance,
502 false /* for guests only */); 655 false /* is for guests only */);
503 host_->SetIsNeverSuitableForReuse(); 656 host_->SetIsNeverSuitableForReuse();
504 host_->AddObserver(this); 657 host_->AddObserver(this);
505 658
506 return host_; 659 return host_;
507 } 660 }
508 661
509 // Implementation of RenderProcessHostObserver. 662 // Implementation of RenderProcessHostObserver.
510 void RenderProcessHostDestroyed(RenderProcessHost* host) override { 663 void RenderProcessHostDestroyed(RenderProcessHost* host) override {
511 DCHECK_EQ(host_, host); 664 DCHECK_EQ(host_, host);
512 host_->RemoveObserver(this); 665 host_->RemoveObserver(this);
513 host_ = nullptr; 666 host_ = nullptr;
514 } 667 }
515 668
516 private: 669 private:
517 BrowserContext* browser_context_; 670 BrowserContext* browser_context_;
518 671
519 // The default subframe render process used for the default storage partition 672 // The default subframe render process used for the default storage partition
520 // of this BrowserContext. 673 // of this BrowserContext.
521 RenderProcessHostImpl* host_ = nullptr; 674 RenderProcessHost* host_ = nullptr;
522 }; 675 };
523 676
524 void CreateMemoryCoordinatorHandle( 677 void CreateMemoryCoordinatorHandle(
525 int render_process_id, 678 int render_process_id,
526 const service_manager::BindSourceInfo& source_info, 679 const service_manager::BindSourceInfo& source_info,
527 mojom::MemoryCoordinatorHandleRequest request) { 680 mojom::MemoryCoordinatorHandleRequest request) {
528 MemoryCoordinatorImpl::GetInstance()->CreateHandle(render_process_id, 681 MemoryCoordinatorImpl::GetInstance()->CreateHandle(render_process_id,
529 std::move(request)); 682 std::move(request));
530 } 683 }
531 684
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 max_count = std::min(max_count, kMaxRendererProcessCount); 1184 max_count = std::min(max_count, kMaxRendererProcessCount);
1032 } 1185 }
1033 return max_count; 1186 return max_count;
1034 } 1187 }
1035 1188
1036 // static 1189 // static
1037 void RenderProcessHost::SetMaxRendererProcessCount(size_t count) { 1190 void RenderProcessHost::SetMaxRendererProcessCount(size_t count) {
1038 g_max_renderer_count_override = count; 1191 g_max_renderer_count_override = count;
1039 } 1192 }
1040 1193
1194 // static
1195 RenderProcessHost* RenderProcessHostImpl::CreateRenderProcessHost(
1196 BrowserContext* browser_context,
1197 StoragePartitionImpl* storage_partition_impl,
1198 SiteInstance* site_instance,
1199 bool is_for_guests_only) {
1200 if (g_render_process_host_factory_) {
1201 return g_render_process_host_factory_->CreateRenderProcessHost(
1202 browser_context);
1203 }
1204
1205 if (!storage_partition_impl) {
1206 storage_partition_impl = static_cast<StoragePartitionImpl*>(
1207 BrowserContext::GetStoragePartition(browser_context, site_instance));
1208 }
1209
1210 return new RenderProcessHostImpl(browser_context, storage_partition_impl,
1211 is_for_guests_only);
1212 }
1213
1214 // static
1215 RenderProcessHost* RenderProcessHostImpl::CreateOrUseSpareRenderProcessHost(
1216 BrowserContext* browser_context,
1217 StoragePartitionImpl* storage_partition_impl,
1218 SiteInstance* site_instance,
1219 bool is_for_guests_only) {
1220 RenderProcessHost* render_process_host =
1221 g_spare_render_process_host_manager.Get().MaybeTakeSpareRenderProcessHost(
1222 browser_context, storage_partition_impl, site_instance,
1223 is_for_guests_only);
1224
1225 if (!render_process_host) {
1226 render_process_host =
1227 CreateRenderProcessHost(browser_context, storage_partition_impl,
1228 site_instance, is_for_guests_only);
1229 }
1230
1231 DCHECK(render_process_host);
1232 return render_process_host;
1233 }
1234
1041 RenderProcessHostImpl::RenderProcessHostImpl( 1235 RenderProcessHostImpl::RenderProcessHostImpl(
1042 BrowserContext* browser_context, 1236 BrowserContext* browser_context,
1043 StoragePartitionImpl* storage_partition_impl, 1237 StoragePartitionImpl* storage_partition_impl,
1044 bool is_for_guests_only) 1238 bool is_for_guests_only)
1045 : fast_shutdown_started_(false), 1239 : fast_shutdown_started_(false),
1046 deleting_soon_(false), 1240 deleting_soon_(false),
1047 #ifndef NDEBUG 1241 #ifndef NDEBUG
1048 is_self_deleted_(false), 1242 is_self_deleted_(false),
1049 #endif 1243 #endif
1050 pending_views_(0), 1244 pending_views_(0),
(...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after
1889 } 2083 }
1890 2084
1891 void RenderProcessHostImpl::ForceReleaseWorkerRefCounts() { 2085 void RenderProcessHostImpl::ForceReleaseWorkerRefCounts() {
1892 DCHECK_CURRENTLY_ON(BrowserThread::UI); 2086 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1893 DCHECK(!is_worker_ref_count_disabled_); 2087 DCHECK(!is_worker_ref_count_disabled_);
1894 is_worker_ref_count_disabled_ = true; 2088 is_worker_ref_count_disabled_ = true;
1895 if (!GetWorkerRefCount()) 2089 if (!GetWorkerRefCount())
1896 return; 2090 return;
1897 service_worker_ref_count_ = 0; 2091 service_worker_ref_count_ = 0;
1898 shared_worker_ref_count_ = 0; 2092 shared_worker_ref_count_ = 0;
2093 // Cleaning up will also remove this from the SpareRenderProcessHostManager.
1899 Cleanup(); 2094 Cleanup();
1900 } 2095 }
1901 2096
1902 bool RenderProcessHostImpl::IsWorkerRefCountDisabled() { 2097 bool RenderProcessHostImpl::IsWorkerRefCountDisabled() {
1903 DCHECK_CURRENTLY_ON(BrowserThread::UI); 2098 DCHECK_CURRENTLY_ON(BrowserThread::UI);
1904 return is_worker_ref_count_disabled_; 2099 return is_worker_ref_count_disabled_;
1905 } 2100 }
1906 2101
1907 void RenderProcessHostImpl::PurgeAndSuspend() { 2102 void RenderProcessHostImpl::PurgeAndSuspend() {
1908 Send(new ChildProcessMsg_PurgeAndSuspend()); 2103 Send(new ChildProcessMsg_PurgeAndSuspend());
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 SiteProcessCountTracker* tracker = static_cast<SiteProcessCountTracker*>( 2315 SiteProcessCountTracker* tracker = static_cast<SiteProcessCountTracker*>(
2121 browser_context->GetUserData(kPendingSiteProcessCountTrackerKey)); 2316 browser_context->GetUserData(kPendingSiteProcessCountTrackerKey));
2122 if (!tracker) { 2317 if (!tracker) {
2123 tracker = new SiteProcessCountTracker(); 2318 tracker = new SiteProcessCountTracker();
2124 browser_context->SetUserData(kPendingSiteProcessCountTrackerKey, 2319 browser_context->SetUserData(kPendingSiteProcessCountTrackerKey,
2125 base::WrapUnique(tracker)); 2320 base::WrapUnique(tracker));
2126 } 2321 }
2127 tracker->DecrementSiteProcessCount(site_url, render_process_host->GetID()); 2322 tracker->DecrementSiteProcessCount(site_url, render_process_host->GetID());
2128 } 2323 }
2129 2324
2325 // static
2326 void RenderProcessHostImpl::CleanupSpareRenderProcessHost() {
2327 g_spare_render_process_host_manager.Get().CleanupSpareRenderProcessHost();
2328 }
2329
2330 // static
2331 RenderProcessHost*
2332 RenderProcessHostImpl::GetSpareRenderProcessHostForTesting() {
2333 return g_spare_render_process_host_manager.Get().spare_render_process_host();
2334 }
2335
2336 bool RenderProcessHostImpl::HostHasNotBeenUsed() {
2337 return IsUnused() && listeners_.IsEmpty() && GetWorkerRefCount() == 0 &&
2338 pending_views_ == 0;
2339 }
2340
2130 bool RenderProcessHostImpl::IsForGuestsOnly() const { 2341 bool RenderProcessHostImpl::IsForGuestsOnly() const {
2131 return is_for_guests_only_; 2342 return is_for_guests_only_;
2132 } 2343 }
2133 2344
2134 StoragePartition* RenderProcessHostImpl::GetStoragePartition() const { 2345 StoragePartition* RenderProcessHostImpl::GetStoragePartition() const {
2135 return storage_partition_impl_; 2346 return storage_partition_impl_;
2136 } 2347 }
2137 2348
2138 static void AppendCompositorCommandLineFlags(base::CommandLine* command_line) { 2349 static void AppendCompositorCommandLineFlags(base::CommandLine* command_line) {
2139 command_line->AppendSwitchASCII( 2350 command_line->AppendSwitchASCII(
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after
3065 // Otherwise, if this process has been used to host any other content, it 3276 // Otherwise, if this process has been used to host any other content, it
3066 // cannot be reused if the destination site indeed requires a dedicated 3277 // cannot be reused if the destination site indeed requires a dedicated
3067 // process and can be locked to just that site. 3278 // process and can be locked to just that site.
3068 return false; 3279 return false;
3069 } 3280 }
3070 3281
3071 return GetContentClient()->browser()->IsSuitableHost(host, site_url); 3282 return GetContentClient()->browser()->IsSuitableHost(host, site_url);
3072 } 3283 }
3073 3284
3074 // static 3285 // static
3286 void RenderProcessHost::WarmupSpareRenderProcessHost(
3287 content::BrowserContext* browser_context) {
3288 g_spare_render_process_host_manager.Get().WarmupSpareRenderProcessHost(
3289 browser_context);
3290 }
3291
3292 // static
3075 bool RenderProcessHost::run_renderer_in_process() { 3293 bool RenderProcessHost::run_renderer_in_process() {
3076 return g_run_renderer_in_process_; 3294 return g_run_renderer_in_process_;
3077 } 3295 }
3078 3296
3079 // static 3297 // static
3080 void RenderProcessHost::SetRunRendererInProcess(bool value) { 3298 void RenderProcessHost::SetRunRendererInProcess(bool value) {
3081 g_run_renderer_in_process_ = value; 3299 g_run_renderer_in_process_ = value;
3082 3300
3083 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 3301 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
3084 if (value) { 3302 if (value) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3142 browser_context, site_url)) { 3360 browser_context, site_url)) {
3143 suitable_renderers.push_back(iter.GetCurrentValue()); 3361 suitable_renderers.push_back(iter.GetCurrentValue());
3144 } 3362 }
3145 iter.Advance(); 3363 iter.Advance();
3146 } 3364 }
3147 3365
3148 // Now pick a random suitable renderer, if we have any. 3366 // Now pick a random suitable renderer, if we have any.
3149 if (!suitable_renderers.empty()) { 3367 if (!suitable_renderers.empty()) {
3150 int suitable_count = static_cast<int>(suitable_renderers.size()); 3368 int suitable_count = static_cast<int>(suitable_renderers.size());
3151 int random_index = base::RandInt(0, suitable_count - 1); 3369 int random_index = base::RandInt(0, suitable_count - 1);
3370 // If the process chosen was the spare RenderProcessHost, ensure it won't be
3371 // used as a spare in the future, or drop the spare if it wasn't used.
3372 g_spare_render_process_host_manager.Get().DropSpareOnProcessCreation(
3373 suitable_renderers[random_index]);
3152 return suitable_renderers[random_index]; 3374 return suitable_renderers[random_index];
3153 } 3375 }
3154 3376
3155 return NULL; 3377 return NULL;
3156 } 3378 }
3157 3379
3158 // static 3380 // static
3159 bool RenderProcessHost::ShouldUseProcessPerSite(BrowserContext* browser_context, 3381 bool RenderProcessHost::ShouldUseProcessPerSite(BrowserContext* browser_context,
3160 const GURL& url) { 3382 const GURL& url) {
3161 // Returns true if we should use the process-per-site model. This will be 3383 // Returns true if we should use the process-per-site model. This will be
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
3268 render_process_host = UnmatchedServiceWorkerProcessTracker::MatchWithSite( 3490 render_process_host = UnmatchedServiceWorkerProcessTracker::MatchWithSite(
3269 browser_context, site_url); 3491 browser_context, site_url);
3270 } 3492 }
3271 3493
3272 // If not (or if none found), see if we should reuse an existing process. 3494 // If not (or if none found), see if we should reuse an existing process.
3273 if (!render_process_host && 3495 if (!render_process_host &&
3274 ShouldTryToUseExistingProcessHost(browser_context, site_url)) { 3496 ShouldTryToUseExistingProcessHost(browser_context, site_url)) {
3275 render_process_host = GetExistingProcessHost(browser_context, site_url); 3497 render_process_host = GetExistingProcessHost(browser_context, site_url);
3276 } 3498 }
3277 3499
3278 // Otherwise (or if that fails), create a new one. 3500 // Otherwise, use the spare RenderProcessHost or create a new one.
3279 if (!render_process_host) { 3501 if (!render_process_host) {
3280 if (g_render_process_host_factory_) { 3502 // Pass a null StoragePartition. Tests with TestBrowserContext using a
3281 render_process_host = 3503 // RenderProcessHostFactory may not instantiate a StoragePartition, and
3282 g_render_process_host_factory_->CreateRenderProcessHost( 3504 // creating one here with GetStoragePartition() can run into cross-thread
3283 browser_context); 3505 // issues as TestBrowserContext initialization is done on the main thread.
3284 } else { 3506 render_process_host = CreateOrUseSpareRenderProcessHost(
3285 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( 3507 browser_context, nullptr, site_instance, is_for_guests_only);
3286 BrowserContext::GetStoragePartition(browser_context, site_instance));
3287 render_process_host = new RenderProcessHostImpl(
3288 browser_context, partition, is_for_guests_only);
3289 }
3290 } 3508 }
3291 3509
3292 if (is_unmatched_service_worker) { 3510 if (is_unmatched_service_worker) {
3293 UnmatchedServiceWorkerProcessTracker::Register( 3511 UnmatchedServiceWorkerProcessTracker::Register(
3294 browser_context, render_process_host, site_url); 3512 browser_context, render_process_host, site_url);
3295 } 3513 }
3296 return render_process_host; 3514 return render_process_host;
3297 } 3515 }
3298 3516
3299 void RenderProcessHostImpl::CreateSharedRendererHistogramAllocator() { 3517 void RenderProcessHostImpl::CreateSharedRendererHistogramAllocator() {
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
3795 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; 4013 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error;
3796 4014
3797 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. 4015 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing.
3798 // Capture the error message in a crash key value. 4016 // Capture the error message in a crash key value.
3799 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); 4017 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error);
3800 bad_message::ReceivedBadMessage(render_process_id, 4018 bad_message::ReceivedBadMessage(render_process_id,
3801 bad_message::RPH_MOJO_PROCESS_ERROR); 4019 bad_message::RPH_MOJO_PROCESS_ERROR);
3802 } 4020 }
3803 4021
3804 } // namespace content 4022 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698