Commit a7993547 authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

Fix unintentionally reverted change in DedicatedWorkerHost

After a bad git rebase, I mistakenly reverted part of a previously
landed CL in a subsequent one.

This is the CL that was partially reverted:
https://chromium-review.googlesource.com/c/chromium/src/+/1990211

This is the CL that did the partial revert:
https://chromium-review.googlesource.com/c/chromium/src/+/1988831

Also, I had to fix a test that was added since then.

Bug: 1040794
Change-Id: Icb662bd0bee94917ba2bc59b20e63289ca9d3247
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2008148Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/master@{#733421}
parent 8d4d0ff0
...@@ -6521,11 +6521,15 @@ void RenderFrameHostImpl::CreateInstalledAppProvider( ...@@ -6521,11 +6521,15 @@ void RenderFrameHostImpl::CreateInstalledAppProvider(
void RenderFrameHostImpl::CreateDedicatedWorkerHostFactory( void RenderFrameHostImpl::CreateDedicatedWorkerHostFactory(
mojo::PendingReceiver<blink::mojom::DedicatedWorkerHostFactory> receiver) { mojo::PendingReceiver<blink::mojom::DedicatedWorkerHostFactory> receiver) {
// Allocate the worker in the same process as the creator.
int worker_process_id = process_->GetID();
// When a dedicated worker is created from the frame script, the frame is both // When a dedicated worker is created from the frame script, the frame is both
// the creator and the ancestor. // the creator and the ancestor.
content::CreateDedicatedWorkerHostFactory( content::CreateDedicatedWorkerHostFactory(
/* creator_frame_routing_id = */ GetGlobalFrameRoutingId(), worker_process_id,
/* ancestor_frame_routing_id = */ GetGlobalFrameRoutingId(), /*creator_render_frame_host_id=*/GetGlobalFrameRoutingId(),
/*ancestor_render_frame_host_id=*/GetGlobalFrameRoutingId(),
last_committed_origin_, std::move(receiver)); last_committed_origin_, std::move(receiver));
} }
......
...@@ -43,7 +43,7 @@ DedicatedWorkerHost::DedicatedWorkerHost( ...@@ -43,7 +43,7 @@ DedicatedWorkerHost::DedicatedWorkerHost(
DedicatedWorkerServiceImpl* service, DedicatedWorkerServiceImpl* service,
DedicatedWorkerId id, DedicatedWorkerId id,
RenderProcessHost* worker_process_host, RenderProcessHost* worker_process_host,
GlobalFrameRoutingId creator_render_frame_host_id, base::Optional<GlobalFrameRoutingId> creator_render_frame_host_id,
GlobalFrameRoutingId ancestor_render_frame_host_id, GlobalFrameRoutingId ancestor_render_frame_host_id,
const url::Origin& origin, const url::Origin& origin,
mojo::PendingReceiver<blink::mojom::DedicatedWorkerHost> host) mojo::PendingReceiver<blink::mojom::DedicatedWorkerHost> host)
...@@ -167,9 +167,9 @@ void DedicatedWorkerHost::StartScriptLoad( ...@@ -167,9 +167,9 @@ void DedicatedWorkerHost::StartScriptLoad(
// If this is a nested worker, there is no creator frame. // If this is a nested worker, there is no creator frame.
RenderFrameHostImpl* creator_render_frame_host = nullptr; RenderFrameHostImpl* creator_render_frame_host = nullptr;
if (creator_render_frame_host_id_.frame_routing_id != MSG_ROUTING_NONE) { if (creator_render_frame_host_id_) {
creator_render_frame_host = creator_render_frame_host =
RenderFrameHostImpl::FromID(creator_render_frame_host_id_); RenderFrameHostImpl::FromID(creator_render_frame_host_id_.value());
if (!creator_render_frame_host) { if (!creator_render_frame_host) {
client_->OnScriptLoadStartFailed(); client_->OnScriptLoadStartFailed();
return; return;
...@@ -368,11 +368,11 @@ void DedicatedWorkerHost::CreateQuicTransportConnector( ...@@ -368,11 +368,11 @@ void DedicatedWorkerHost::CreateQuicTransportConnector(
void DedicatedWorkerHost::CreateNestedDedicatedWorker( void DedicatedWorkerHost::CreateNestedDedicatedWorker(
mojo::PendingReceiver<blink::mojom::DedicatedWorkerHostFactory> receiver) { mojo::PendingReceiver<blink::mojom::DedicatedWorkerHostFactory> receiver) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
GlobalFrameRoutingId new_creator_render_frame_host_id( // There is no creator frame when the worker is nested.
worker_process_host_->GetID(), MSG_ROUTING_NONE); CreateDedicatedWorkerHostFactory(
CreateDedicatedWorkerHostFactory(new_creator_render_frame_host_id, worker_process_host_->GetID(),
ancestor_render_frame_host_id_, origin_, /*creator_render_frame_host_id_=*/base::nullopt,
std::move(receiver)); ancestor_render_frame_host_id_, origin_, std::move(receiver));
} }
void DedicatedWorkerHost::CreateIdleManager( void DedicatedWorkerHost::CreateIdleManager(
...@@ -448,7 +448,6 @@ void DedicatedWorkerHost::UpdateSubresourceLoaderFactories() { ...@@ -448,7 +448,6 @@ void DedicatedWorkerHost::UpdateSubresourceLoaderFactories() {
auto* storage_partition_impl = static_cast<StoragePartitionImpl*>( auto* storage_partition_impl = static_cast<StoragePartitionImpl*>(
worker_process_host_->GetStoragePartition()); worker_process_host_->GetStoragePartition());
// Get a storage domain.
RenderFrameHostImpl* ancestor_render_frame_host = RenderFrameHostImpl* ancestor_render_frame_host =
RenderFrameHostImpl::FromID(ancestor_render_frame_host_id_); RenderFrameHostImpl::FromID(ancestor_render_frame_host_id_);
if (!ancestor_render_frame_host) if (!ancestor_render_frame_host)
...@@ -458,6 +457,7 @@ void DedicatedWorkerHost::UpdateSubresourceLoaderFactories() { ...@@ -458,6 +457,7 @@ void DedicatedWorkerHost::UpdateSubresourceLoaderFactories() {
if (!site_instance) if (!site_instance)
return; return;
// Get a storage domain.
std::string storage_domain; std::string storage_domain;
std::string partition_name; std::string partition_name;
bool in_memory; bool in_memory;
...@@ -496,10 +496,12 @@ class DedicatedWorkerHostFactoryImpl final ...@@ -496,10 +496,12 @@ class DedicatedWorkerHostFactoryImpl final
: public blink::mojom::DedicatedWorkerHostFactory { : public blink::mojom::DedicatedWorkerHostFactory {
public: public:
DedicatedWorkerHostFactoryImpl( DedicatedWorkerHostFactoryImpl(
GlobalFrameRoutingId creator_render_frame_host_id, int worker_process_id,
base::Optional<GlobalFrameRoutingId> creator_render_frame_host_id,
GlobalFrameRoutingId ancestor_render_frame_host_id, GlobalFrameRoutingId ancestor_render_frame_host_id,
const url::Origin& parent_context_origin) const url::Origin& parent_context_origin)
: creator_render_frame_host_id_(creator_render_frame_host_id), : worker_process_id_(worker_process_id),
creator_render_frame_host_id_(creator_render_frame_host_id),
ancestor_render_frame_host_id_(ancestor_render_frame_host_id), ancestor_render_frame_host_id_(ancestor_render_frame_host_id),
parent_context_origin_(parent_context_origin) { parent_context_origin_(parent_context_origin) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
...@@ -518,9 +520,7 @@ class DedicatedWorkerHostFactoryImpl final ...@@ -518,9 +520,7 @@ class DedicatedWorkerHostFactoryImpl final
return; return;
} }
// Allocate the worker in the same process as the creator. auto* worker_process_host = RenderProcessHost::FromID(worker_process_id_);
auto* worker_process_host =
RenderProcessHost::FromID(creator_render_frame_host_id_.child_id);
if (!worker_process_host) { if (!worker_process_host) {
// Abort if the worker's process host is gone. This means that the calling // Abort if the worker's process host is gone. This means that the calling
// frame or worker is also either destroyed or in the process of being // frame or worker is also either destroyed or in the process of being
...@@ -565,9 +565,7 @@ class DedicatedWorkerHostFactoryImpl final ...@@ -565,9 +565,7 @@ class DedicatedWorkerHostFactoryImpl final
return; return;
} }
// Allocate the worker in the same process as the creator. auto* worker_process_host = RenderProcessHost::FromID(worker_process_id_);
auto* worker_process_host =
RenderProcessHost::FromID(creator_render_frame_host_id_.child_id);
if (!worker_process_host) { if (!worker_process_host) {
// Abort if the worker's process host is gone. This means that the calling // Abort if the worker's process host is gone. This means that the calling
// frame or worker is also either destroyed or in the process of being // frame or worker is also either destroyed or in the process of being
...@@ -604,8 +602,11 @@ class DedicatedWorkerHostFactoryImpl final ...@@ -604,8 +602,11 @@ class DedicatedWorkerHostFactoryImpl final
} }
private: private:
// The ID of the RenderProcessHost where the worker will live.
const int worker_process_id_;
// See comments on the corresponding members of DedicatedWorkerHost. // See comments on the corresponding members of DedicatedWorkerHost.
const GlobalFrameRoutingId creator_render_frame_host_id_; const base::Optional<GlobalFrameRoutingId> creator_render_frame_host_id_;
const GlobalFrameRoutingId ancestor_render_frame_host_id_; const GlobalFrameRoutingId ancestor_render_frame_host_id_;
const url::Origin parent_context_origin_; const url::Origin parent_context_origin_;
...@@ -616,14 +617,16 @@ class DedicatedWorkerHostFactoryImpl final ...@@ -616,14 +617,16 @@ class DedicatedWorkerHostFactoryImpl final
} // namespace } // namespace
void CreateDedicatedWorkerHostFactory( void CreateDedicatedWorkerHostFactory(
GlobalFrameRoutingId creator_render_frame_host_id, int worker_process_id,
base::Optional<GlobalFrameRoutingId> creator_render_frame_host_id,
GlobalFrameRoutingId ancestor_render_frame_host_id, GlobalFrameRoutingId ancestor_render_frame_host_id,
const url::Origin& origin, const url::Origin& origin,
mojo::PendingReceiver<blink::mojom::DedicatedWorkerHostFactory> receiver) { mojo::PendingReceiver<blink::mojom::DedicatedWorkerHostFactory> receiver) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
mojo::MakeSelfOwnedReceiver( mojo::MakeSelfOwnedReceiver(
std::make_unique<DedicatedWorkerHostFactoryImpl>( std::make_unique<DedicatedWorkerHostFactoryImpl>(
creator_render_frame_host_id, ancestor_render_frame_host_id, origin), worker_process_id, creator_render_frame_host_id,
ancestor_render_frame_host_id, origin),
std::move(receiver)); std::move(receiver));
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef CONTENT_BROWSER_WORKER_HOST_DEDICATED_WORKER_HOST_H_ #ifndef CONTENT_BROWSER_WORKER_HOST_DEDICATED_WORKER_HOST_H_
#define CONTENT_BROWSER_WORKER_HOST_DEDICATED_WORKER_HOST_H_ #define CONTENT_BROWSER_WORKER_HOST_DEDICATED_WORKER_HOST_H_
#include "base/optional.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/browser/browser_interface_broker_impl.h" #include "content/browser/browser_interface_broker_impl.h"
...@@ -46,7 +47,8 @@ class StoragePartitionImpl; ...@@ -46,7 +47,8 @@ class StoragePartitionImpl;
// Creates a host factory for a dedicated worker. This must be called on the UI // Creates a host factory for a dedicated worker. This must be called on the UI
// thread. // thread.
CONTENT_EXPORT void CreateDedicatedWorkerHostFactory( CONTENT_EXPORT void CreateDedicatedWorkerHostFactory(
GlobalFrameRoutingId creator_render_frame_host_id, int worker_process_id,
base::Optional<GlobalFrameRoutingId> creator_render_frame_host_id,
GlobalFrameRoutingId ancestor_render_frame_host_id, GlobalFrameRoutingId ancestor_render_frame_host_id,
const url::Origin& origin, const url::Origin& origin,
mojo::PendingReceiver<blink::mojom::DedicatedWorkerHostFactory> receiver); mojo::PendingReceiver<blink::mojom::DedicatedWorkerHostFactory> receiver);
...@@ -61,7 +63,7 @@ class DedicatedWorkerHost final : public blink::mojom::DedicatedWorkerHost, ...@@ -61,7 +63,7 @@ class DedicatedWorkerHost final : public blink::mojom::DedicatedWorkerHost,
DedicatedWorkerServiceImpl* service, DedicatedWorkerServiceImpl* service,
DedicatedWorkerId id, DedicatedWorkerId id,
RenderProcessHost* worker_process_host, RenderProcessHost* worker_process_host,
GlobalFrameRoutingId creator_render_frame_host_id, base::Optional<GlobalFrameRoutingId> creator_render_frame_host_id,
GlobalFrameRoutingId ancestor_render_frame_host_id, GlobalFrameRoutingId ancestor_render_frame_host_id,
const url::Origin& origin, const url::Origin& origin,
mojo::PendingReceiver<blink::mojom::DedicatedWorkerHost> host); mojo::PendingReceiver<blink::mojom::DedicatedWorkerHost> host);
...@@ -164,10 +166,9 @@ class DedicatedWorkerHost final : public blink::mojom::DedicatedWorkerHost, ...@@ -164,10 +166,9 @@ class DedicatedWorkerHost final : public blink::mojom::DedicatedWorkerHost,
ScopedObserver<RenderProcessHost, RenderProcessHostObserver> ScopedObserver<RenderProcessHost, RenderProcessHostObserver>
scoped_process_host_observer_; scoped_process_host_observer_;
// The ID of the frame that directly starts this worker. This is // The ID of the frame that directly starts this worker. This is base::nullopt
// {creator_render_process_host_id, MSG_ROUTING_NONE} when this worker is // when this worker is nested.
// nested. const base::Optional<GlobalFrameRoutingId> creator_render_frame_host_id_;
const GlobalFrameRoutingId creator_render_frame_host_id_;
// The ID of the frame that owns this worker, either directly, or (in the case // The ID of the frame that owns this worker, either directly, or (in the case
// of nested workers) indirectly via a tree of dedicated workers. // of nested workers) indirectly via a tree of dedicated workers.
......
...@@ -26,9 +26,10 @@ namespace content { ...@@ -26,9 +26,10 @@ namespace content {
class MockDedicatedWorker class MockDedicatedWorker
: public blink::mojom::DedicatedWorkerHostFactoryClient { : public blink::mojom::DedicatedWorkerHostFactoryClient {
public: public:
explicit MockDedicatedWorker(GlobalFrameRoutingId render_frame_host_id) { MockDedicatedWorker(int worker_process_id,
CreateDedicatedWorkerHostFactory(render_frame_host_id, render_frame_host_id, GlobalFrameRoutingId render_frame_host_id) {
url::Origin(), CreateDedicatedWorkerHostFactory(worker_process_id, render_frame_host_id,
render_frame_host_id, url::Origin(),
factory_.BindNewPipeAndPassReceiver()); factory_.BindNewPipeAndPassReceiver());
if (base::FeatureList::IsEnabled(blink::features::kPlzDedicatedWorker)) { if (base::FeatureList::IsEnabled(blink::features::kPlzDedicatedWorker)) {
...@@ -185,8 +186,8 @@ TEST_P(DedicatedWorkerServiceImplTest, ObserveWorkerCreationAndDestruction) { ...@@ -185,8 +186,8 @@ TEST_P(DedicatedWorkerServiceImplTest, ObserveWorkerCreationAndDestruction) {
// Create the dedicated worker. // Create the dedicated worker.
GlobalFrameRoutingId ancestor_render_frame_host_id = GlobalFrameRoutingId ancestor_render_frame_host_id =
render_frame_host->GetGlobalFrameRoutingId(); render_frame_host->GetGlobalFrameRoutingId();
auto mock_dedicated_worker = auto mock_dedicated_worker = std::make_unique<MockDedicatedWorker>(
std::make_unique<MockDedicatedWorker>(ancestor_render_frame_host_id); render_frame_host->GetProcess()->GetID(), ancestor_render_frame_host_id);
RunUntilWorkerEvent(); RunUntilWorkerEvent();
// The service sent a OnWorkerStarted() notification. // The service sent a OnWorkerStarted() notification.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment