Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 #include "content/browser/renderer_host/render_view_host_impl.h" | 117 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 118 #include "content/browser/renderer_host/render_widget_helper.h" | 118 #include "content/browser/renderer_host/render_widget_helper.h" |
| 119 #include "content/browser/renderer_host/render_widget_host_impl.h" | 119 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 120 #include "content/browser/renderer_host/render_widget_host_view_frame_subscriber .h" | 120 #include "content/browser/renderer_host/render_widget_host_view_frame_subscriber .h" |
| 121 #include "content/browser/renderer_host/text_input_client_message_filter.h" | 121 #include "content/browser/renderer_host/text_input_client_message_filter.h" |
| 122 #include "content/browser/resolve_proxy_msg_helper.h" | 122 #include "content/browser/resolve_proxy_msg_helper.h" |
| 123 #include "content/browser/service_worker/service_worker_context_wrapper.h" | 123 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 124 #include "content/browser/service_worker/service_worker_dispatcher_host.h" | 124 #include "content/browser/service_worker/service_worker_dispatcher_host.h" |
| 125 #include "content/browser/shared_worker/shared_worker_message_filter.h" | 125 #include "content/browser/shared_worker/shared_worker_message_filter.h" |
| 126 #include "content/browser/shared_worker/worker_storage_partition.h" | 126 #include "content/browser/shared_worker/worker_storage_partition.h" |
| 127 #include "content/browser/site_instance_impl.h" | |
| 127 #include "content/browser/speech/speech_recognition_dispatcher_host.h" | 128 #include "content/browser/speech/speech_recognition_dispatcher_host.h" |
| 128 #include "content/browser/storage_partition_impl.h" | 129 #include "content/browser/storage_partition_impl.h" |
| 129 #include "content/browser/streams/stream_context.h" | 130 #include "content/browser/streams/stream_context.h" |
| 130 #include "content/browser/tracing/trace_message_filter.h" | 131 #include "content/browser/tracing/trace_message_filter.h" |
| 131 #include "content/browser/websockets/websocket_manager.h" | 132 #include "content/browser/websockets/websocket_manager.h" |
| 132 #include "content/browser/webui/web_ui_controller_factory_registry.h" | 133 #include "content/browser/webui/web_ui_controller_factory_registry.h" |
| 133 #include "content/common/child_process_host_impl.h" | 134 #include "content/common/child_process_host_impl.h" |
| 134 #include "content/common/child_process_messages.h" | 135 #include "content/common/child_process_messages.h" |
| 135 #include "content/common/content_switches_internal.h" | 136 #include "content/common/content_switches_internal.h" |
| 136 #include "content/common/frame_messages.h" | 137 #include "content/common/frame_messages.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 | 252 |
| 252 #if defined(OS_WIN) | 253 #if defined(OS_WIN) |
| 253 #define IntToStringType base::IntToString16 | 254 #define IntToStringType base::IntToString16 |
| 254 #else | 255 #else |
| 255 #define IntToStringType base::IntToString | 256 #define IntToStringType base::IntToString |
| 256 #endif | 257 #endif |
| 257 | 258 |
| 258 namespace content { | 259 namespace content { |
| 259 namespace { | 260 namespace { |
| 260 | 261 |
| 262 const RenderProcessHostFactory* g_render_process_host_factory_ = nullptr; | |
| 261 const char kSiteProcessMapKeyName[] = "content_site_process_map"; | 263 const char kSiteProcessMapKeyName[] = "content_site_process_map"; |
| 262 | 264 |
| 263 #if BUILDFLAG(ENABLE_WEBRTC) | 265 #if BUILDFLAG(ENABLE_WEBRTC) |
| 264 const base::FilePath::CharType kAecDumpFileNameAddition[] = | 266 const base::FilePath::CharType kAecDumpFileNameAddition[] = |
| 265 FILE_PATH_LITERAL("aec_dump"); | 267 FILE_PATH_LITERAL("aec_dump"); |
| 266 #endif | 268 #endif |
| 267 | 269 |
| 268 void CacheShaderInfo(int32_t id, base::FilePath path) { | 270 void CacheShaderInfo(int32_t id, base::FilePath path) { |
| 269 if (GetShaderCacheFactorySingleton()) | 271 if (GetShaderCacheFactorySingleton()) |
| 270 GetShaderCacheFactorySingleton()->SetCacheInfo(id, path); | 272 GetShaderCacheFactorySingleton()->SetCacheInfo(id, path); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 442 void Release(int old_route_id) { | 444 void Release(int old_route_id) { |
| 443 session_storage_namespaces_awaiting_close_->erase(old_route_id); | 445 session_storage_namespaces_awaiting_close_->erase(old_route_id); |
| 444 } | 446 } |
| 445 | 447 |
| 446 private: | 448 private: |
| 447 std::unique_ptr<std::map<int, SessionStorageNamespaceMap>> | 449 std::unique_ptr<std::map<int, SessionStorageNamespaceMap>> |
| 448 session_storage_namespaces_awaiting_close_; | 450 session_storage_namespaces_awaiting_close_; |
| 449 DISALLOW_COPY_AND_ASSIGN(SessionStorageHolder); | 451 DISALLOW_COPY_AND_ASSIGN(SessionStorageHolder); |
| 450 }; | 452 }; |
| 451 | 453 |
| 454 const void* const kDefaultSubframeProcessHostHolderKey = | |
| 455 &kDefaultSubframeProcessHostHolderKey; | |
| 456 | |
| 457 class DefaultSubframeProcessHostHolder : public base::SupportsUserData::Data, | |
| 458 public RenderProcessHostObserver { | |
| 459 public: | |
| 460 explicit DefaultSubframeProcessHostHolder(BrowserContext* browser_context) | |
| 461 : browser_context_(browser_context) {} | |
| 462 ~DefaultSubframeProcessHostHolder() override {} | |
| 463 | |
| 464 // Gets the correct render process to use for this SiteInstance. | |
| 465 RenderProcessHost* GetProcessHost(SiteInstance* site_instance, | |
| 466 bool is_for_guests_only) { | |
| 467 StoragePartition* default_partition = | |
| 468 BrowserContext::GetDefaultStoragePartition(browser_context_); | |
| 469 StoragePartition* partition = | |
| 470 BrowserContext::GetStoragePartition(browser_context_, site_instance); | |
| 471 | |
| 472 // Is this the default storage partition? If it isn't, then just give it its | |
| 473 // own non-shared process. | |
| 474 if (partition != default_partition || is_for_guests_only) { | |
| 475 RenderProcessHostImpl* host = new RenderProcessHostImpl( | |
| 476 browser_context_, static_cast<StoragePartitionImpl*>(partition), | |
| 477 is_for_guests_only); | |
| 478 host->SetIsNeverSuitableForReuse(); | |
|
nasko
2017/05/03 23:46:16
What about different GuestView instances that shar
clamy
2017/05/04 15:56:18
Following the removing of is_for_guest only asked
| |
| 479 return host; | |
| 480 } | |
| 481 | |
| 482 if (host_) { | |
| 483 // If we already have a shared host for the default storage partition, use | |
|
nasko
2017/05/03 23:46:16
nit: I'd put the comment above the if statement an
clamy
2017/05/04 15:56:18
Done.
| |
| 484 // it. | |
| 485 return host_; | |
| 486 } | |
| 487 | |
| 488 host_ = new RenderProcessHostImpl( | |
| 489 browser_context_, static_cast<StoragePartitionImpl*>(partition), | |
| 490 false /* for guests only */); | |
| 491 host_->SetIsNeverSuitableForReuse(); | |
| 492 host_->AddObserver(this); | |
| 493 | |
| 494 return host_; | |
| 495 } | |
| 496 | |
| 497 void RenderProcessHostDestroyed(RenderProcessHost* host) override { | |
|
nasko
2017/05/03 23:46:17
nit: Add a comment above that this is an implement
clamy
2017/05/04 15:56:19
Done.
| |
| 498 DCHECK_EQ(host_, host); | |
| 499 host_->RemoveObserver(this); | |
| 500 host_ = nullptr; | |
| 501 } | |
| 502 | |
| 503 private: | |
| 504 BrowserContext* browser_context_; | |
| 505 | |
| 506 // The default subframe render process used for the default storage partition | |
| 507 // of this BrowserContext. | |
| 508 RenderProcessHostImpl* host_ = nullptr; | |
| 509 }; | |
| 510 | |
| 452 void CreateMemoryCoordinatorHandle( | 511 void CreateMemoryCoordinatorHandle( |
| 453 int render_process_id, | 512 int render_process_id, |
| 454 mojom::MemoryCoordinatorHandleRequest request) { | 513 mojom::MemoryCoordinatorHandleRequest request) { |
| 455 MemoryCoordinatorImpl::GetInstance()->CreateHandle(render_process_id, | 514 MemoryCoordinatorImpl::GetInstance()->CreateHandle(render_process_id, |
| 456 std::move(request)); | 515 std::move(request)); |
| 457 } | 516 } |
| 458 | 517 |
| 459 // Forwards service requests to Service Manager since the renderer cannot launch | 518 // Forwards service requests to Service Manager since the renderer cannot launch |
| 460 // out-of-process services on is own. | 519 // out-of-process services on is own. |
| 461 template <typename R> | 520 template <typename R> |
| (...skipping 1158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1620 ++audio_stream_count_; | 1679 ++audio_stream_count_; |
| 1621 UpdateProcessPriority(); | 1680 UpdateProcessPriority(); |
| 1622 } | 1681 } |
| 1623 | 1682 |
| 1624 void RenderProcessHostImpl::OnAudioStreamRemoved() { | 1683 void RenderProcessHostImpl::OnAudioStreamRemoved() { |
| 1625 DCHECK_GT(audio_stream_count_, 0); | 1684 DCHECK_GT(audio_stream_count_, 0); |
| 1626 --audio_stream_count_; | 1685 --audio_stream_count_; |
| 1627 UpdateProcessPriority(); | 1686 UpdateProcessPriority(); |
| 1628 } | 1687 } |
| 1629 | 1688 |
| 1689 void RenderProcessHostImpl::set_render_process_host_factory( | |
| 1690 const RenderProcessHostFactory* rph_factory) { | |
| 1691 g_render_process_host_factory_ = rph_factory; | |
| 1692 } | |
| 1693 | |
| 1630 bool RenderProcessHostImpl::IsForGuestsOnly() const { | 1694 bool RenderProcessHostImpl::IsForGuestsOnly() const { |
| 1631 return is_for_guests_only_; | 1695 return is_for_guests_only_; |
| 1632 } | 1696 } |
| 1633 | 1697 |
| 1634 StoragePartition* RenderProcessHostImpl::GetStoragePartition() const { | 1698 StoragePartition* RenderProcessHostImpl::GetStoragePartition() const { |
| 1635 return storage_partition_impl_; | 1699 return storage_partition_impl_; |
| 1636 } | 1700 } |
| 1637 | 1701 |
| 1638 static void AppendCompositorCommandLineFlags(base::CommandLine* command_line) { | 1702 static void AppendCompositorCommandLineFlags(base::CommandLine* command_line) { |
| 1639 command_line->AppendSwitchASCII( | 1703 command_line->AppendSwitchASCII( |
| (...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2714 | 2778 |
| 2715 // Only register valid, non-empty sites. Empty or invalid sites will not | 2779 // Only register valid, non-empty sites. Empty or invalid sites will not |
| 2716 // use process-per-site mode. We cannot check whether the process has | 2780 // use process-per-site mode. We cannot check whether the process has |
| 2717 // appropriate bindings here, because the bindings have not yet been granted. | 2781 // appropriate bindings here, because the bindings have not yet been granted. |
| 2718 std::string site = | 2782 std::string site = |
| 2719 SiteInstance::GetSiteForURL(browser_context, url).possibly_invalid_spec(); | 2783 SiteInstance::GetSiteForURL(browser_context, url).possibly_invalid_spec(); |
| 2720 if (!site.empty()) | 2784 if (!site.empty()) |
| 2721 map->RegisterProcess(site, process); | 2785 map->RegisterProcess(site, process); |
| 2722 } | 2786 } |
| 2723 | 2787 |
| 2788 // static | |
| 2789 RenderProcessHost* RenderProcessHostImpl::GetProcessHostForSiteInstance( | |
| 2790 BrowserContext* browser_context, | |
| 2791 SiteInstanceImpl* site_instance) { | |
| 2792 const GURL url = site_instance->GetSiteURL(); | |
|
Charlie Reis
2017/05/03 23:28:00
nit: site_url
(This is a meaningful difference in
clamy
2017/05/04 15:56:18
Done.
| |
| 2793 ProcessReusePolicy process_reuse_policy = | |
| 2794 site_instance->process_reuse_policy(); | |
| 2795 bool is_for_guests_only = url.SchemeIs(kGuestScheme); | |
| 2796 RenderProcessHost* render_process_host = nullptr; | |
| 2797 | |
| 2798 // First, attempt to reuse an existing RenderProcessHost if applicable. | |
|
Charlie Reis
2017/05/03 23:28:00
nit: s/applicable/necessary/
(We may also reuse wh
clamy
2017/05/04 15:56:19
Done.
| |
| 2799 switch (process_reuse_policy) { | |
| 2800 case ProcessReusePolicy::PROCESS_PER_SITE: | |
| 2801 render_process_host = GetProcessHostForSite(browser_context, url); | |
| 2802 break; | |
| 2803 case ProcessReusePolicy::USE_DEFAULT_SUBFRAME_INSTANCE: | |
| 2804 render_process_host = GetDefaultSubframeProcessHost( | |
|
Charlie Reis
2017/05/03 23:28:00
DCHECK(SiteIsolationPolicy::IsTopDocumentIsolation
clamy
2017/05/04 15:56:18
Done.
| |
| 2805 browser_context, site_instance, is_for_guests_only); | |
| 2806 break; | |
| 2807 default: | |
| 2808 break; | |
| 2809 } | |
| 2810 | |
| 2811 if (!render_process_host && | |
|
Charlie Reis
2017/05/03 23:28:00
Please keep the old comment:
// If not (or if none
clamy
2017/05/04 15:56:18
Done.
| |
| 2812 process_reuse_policy != ProcessReusePolicy::DONT && | |
| 2813 ShouldTryToUseExistingProcessHost(browser_context, url)) { | |
| 2814 render_process_host = GetExistingProcessHost(browser_context, url); | |
| 2815 } | |
| 2816 | |
| 2817 // Otherwise (or if that fails), create a new one. | |
| 2818 if (!render_process_host) { | |
| 2819 if (g_render_process_host_factory_) { | |
| 2820 render_process_host = | |
| 2821 g_render_process_host_factory_->CreateRenderProcessHost( | |
| 2822 browser_context, site_instance); | |
| 2823 } else { | |
| 2824 StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>( | |
| 2825 BrowserContext::GetStoragePartition(browser_context, site_instance)); | |
| 2826 render_process_host = new RenderProcessHostImpl( | |
| 2827 browser_context, partition, is_for_guests_only); | |
| 2828 } | |
| 2829 } | |
| 2830 return render_process_host; | |
| 2831 } | |
| 2832 | |
| 2724 void RenderProcessHostImpl::CreateSharedRendererHistogramAllocator() { | 2833 void RenderProcessHostImpl::CreateSharedRendererHistogramAllocator() { |
| 2725 // Create a persistent memory segment for renderer histograms only if | 2834 // Create a persistent memory segment for renderer histograms only if |
| 2726 // they're active in the browser. | 2835 // they're active in the browser. |
| 2727 if (!base::GlobalHistogramAllocator::Get()) | 2836 if (!base::GlobalHistogramAllocator::Get()) |
| 2728 return; | 2837 return; |
| 2729 | 2838 |
| 2730 // Get handle to the renderer process. Stop if there is none. | 2839 // Get handle to the renderer process. Stop if there is none. |
| 2731 base::ProcessHandle destination = GetHandle(); | 2840 base::ProcessHandle destination = GetHandle(); |
| 2732 if (destination == base::kNullProcessHandle) | 2841 if (destination == base::kNullProcessHandle) |
| 2733 return; | 2842 return; |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3042 static_cast<SessionStorageHolder*>(GetUserData(kSessionStorageHolderKey)); | 3151 static_cast<SessionStorageHolder*>(GetUserData(kSessionStorageHolderKey)); |
| 3043 if (!holder) | 3152 if (!holder) |
| 3044 return; | 3153 return; |
| 3045 holder->Release(old_route_id); | 3154 holder->Release(old_route_id); |
| 3046 } | 3155 } |
| 3047 | 3156 |
| 3048 void RenderProcessHostImpl::OnGpuSwitched() { | 3157 void RenderProcessHostImpl::OnGpuSwitched() { |
| 3049 RecomputeAndUpdateWebKitPreferences(); | 3158 RecomputeAndUpdateWebKitPreferences(); |
| 3050 } | 3159 } |
| 3051 | 3160 |
| 3161 // static | |
| 3162 RenderProcessHost* RenderProcessHostImpl::GetDefaultSubframeProcessHost( | |
| 3163 BrowserContext* browser_context, | |
| 3164 SiteInstanceImpl* site_instance, | |
| 3165 bool is_for_guests_only) { | |
|
nasko
2017/05/03 23:46:17
Thinking more about this, does this bool param mak
clamy
2017/05/04 15:56:18
Done.
Charlie Reis
2017/05/04 23:12:23
I'm pretty nervous about this change, for two reas
nasko
2017/05/05 05:27:23
As I pointed out in one of my comments, I added th
| |
| 3166 DefaultSubframeProcessHostHolder* holder = | |
| 3167 static_cast<DefaultSubframeProcessHostHolder*>( | |
| 3168 browser_context->GetUserData(&kDefaultSubframeProcessHostHolderKey)); | |
| 3169 if (!holder) { | |
| 3170 holder = new DefaultSubframeProcessHostHolder(browser_context); | |
| 3171 browser_context->SetUserData(kDefaultSubframeProcessHostHolderKey, | |
| 3172 base::WrapUnique(holder)); | |
| 3173 } | |
| 3174 | |
| 3175 return holder->GetProcessHost(site_instance, is_for_guests_only); | |
| 3176 } | |
| 3177 | |
| 3052 #if BUILDFLAG(ENABLE_WEBRTC) | 3178 #if BUILDFLAG(ENABLE_WEBRTC) |
| 3053 void RenderProcessHostImpl::OnRegisterAecDumpConsumer(int id) { | 3179 void RenderProcessHostImpl::OnRegisterAecDumpConsumer(int id) { |
| 3054 BrowserThread::PostTask( | 3180 BrowserThread::PostTask( |
| 3055 BrowserThread::UI, FROM_HERE, | 3181 BrowserThread::UI, FROM_HERE, |
| 3056 base::Bind(&RenderProcessHostImpl::RegisterAecDumpConsumerOnUIThread, | 3182 base::Bind(&RenderProcessHostImpl::RegisterAecDumpConsumerOnUIThread, |
| 3057 weak_factory_.GetWeakPtr(), id)); | 3183 weak_factory_.GetWeakPtr(), id)); |
| 3058 } | 3184 } |
| 3059 | 3185 |
| 3060 void RenderProcessHostImpl::OnUnregisterAecDumpConsumer(int id) { | 3186 void RenderProcessHostImpl::OnUnregisterAecDumpConsumer(int id) { |
| 3061 BrowserThread::PostTask( | 3187 BrowserThread::PostTask( |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3132 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 3258 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
| 3133 | 3259 |
| 3134 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. | 3260 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. |
| 3135 // Capture the error message in a crash key value. | 3261 // Capture the error message in a crash key value. |
| 3136 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); | 3262 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); |
| 3137 bad_message::ReceivedBadMessage(render_process_id, | 3263 bad_message::ReceivedBadMessage(render_process_id, |
| 3138 bad_message::RPH_MOJO_PROCESS_ERROR); | 3264 bad_message::RPH_MOJO_PROCESS_ERROR); |
| 3139 } | 3265 } |
| 3140 | 3266 |
| 3141 } // namespace content | 3267 } // namespace content |
| OLD | NEW |