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

Unified Diff: content/browser/service_worker/embedded_worker_instance.cc

Issue 2378073002: Reland of ServiceWorker: Implement StartWorker by using mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/service_worker/embedded_worker_instance.cc
diff --git a/content/browser/service_worker/embedded_worker_instance.cc b/content/browser/service_worker/embedded_worker_instance.cc
index 6c9dc1fc4e9250e9f9781c117285d15aa9745d5e..f2365771a03cdc888ea505ca6626c0771e68c0c6 100644
--- a/content/browser/service_worker/embedded_worker_instance.cc
+++ b/content/browser/service_worker/embedded_worker_instance.cc
@@ -20,11 +20,14 @@
#include "content/common/service_worker/embedded_worker_messages.h"
#include "content/common/service_worker/embedded_worker_settings.h"
#include "content/common/service_worker/embedded_worker_setup.mojom.h"
+#include "content/common/service_worker/embedded_worker_start_params.h"
#include "content/common/service_worker/service_worker_types.h"
+#include "content/common/service_worker/service_worker_utils.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/common/child_process_host.h"
+#include "content/public/common/content_switches.h"
#include "ipc/ipc_message.h"
#include "services/shell/public/cpp/interface_provider.h"
#include "services/shell/public/cpp/interface_registry.h"
@@ -69,7 +72,7 @@
worker_process_id, worker_route_id);
}
-void RegisterToWorkerDevToolsManagerOnUI(
+void SetupOnUI(
int process_id,
const ServiceWorkerContextCore* service_worker_context,
const base::WeakPtr<ServiceWorkerContextCore>& service_worker_context_weak,
@@ -77,6 +80,7 @@
const GURL& url,
const GURL& scope,
bool is_installed,
+ mojom::EmbeddedWorkerInstanceClientRequest request,
const base::Callback<void(int worker_devtools_agent_route_id,
bool wait_for_debugger)>& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
@@ -92,6 +96,8 @@
service_worker_context, service_worker_context_weak,
service_worker_version_id, url, scope),
is_installed);
+ if (request.is_pending())
+ rph->GetRemoteInterfaces()->GetInterface(std::move(request));
}
BrowserThread::PostTask(
BrowserThread::IO,
@@ -211,8 +217,11 @@
public:
enum class ProcessAllocationState { NOT_ALLOCATED, ALLOCATING, ALLOCATED };
- StartTask(EmbeddedWorkerInstance* instance, const GURL& script_url)
+ StartTask(EmbeddedWorkerInstance* instance,
+ const GURL& script_url,
+ mojom::EmbeddedWorkerInstanceClientRequest request)
: instance_(instance),
+ request_(std::move(request)),
state_(ProcessAllocationState::NOT_ALLOCATED),
is_installed_(false),
started_during_browser_startup_(false),
@@ -254,7 +263,7 @@
// TODO(nhiroki): Reconsider this bizarre layering.
}
- void Start(std::unique_ptr<EmbeddedWorkerMsg_StartWorker_Params> params,
+ void Start(std::unique_ptr<EmbeddedWorkerStartParams> params,
const StatusCallback& callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
state_ = ProcessAllocationState::ALLOCATING;
@@ -289,12 +298,11 @@
bool is_installed() const { return is_installed_; }
private:
- void OnProcessAllocated(
- std::unique_ptr<EmbeddedWorkerMsg_StartWorker_Params> params,
- ServiceWorkerStatusCode status,
- int process_id,
- bool is_new_process,
- const EmbeddedWorkerSettings& settings) {
+ void OnProcessAllocated(std::unique_ptr<EmbeddedWorkerStartParams> params,
+ ServiceWorkerStatusCode status,
+ int process_id,
+ bool is_new_process,
+ const EmbeddedWorkerSettings& settings) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (status != SERVICE_WORKER_OK) {
@@ -342,23 +350,22 @@
GURL script_url(params->script_url);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
- base::Bind(RegisterToWorkerDevToolsManagerOnUI, process_id,
- instance_->context_.get(), instance_->context_,
- service_worker_version_id, script_url, scope, is_installed_,
- base::Bind(&StartTask::OnRegisteredToDevToolsManager,
+ base::Bind(&SetupOnUI, process_id, instance_->context_.get(),
+ instance_->context_, service_worker_version_id, script_url,
+ scope, is_installed_, base::Passed(&request_),
+ base::Bind(&StartTask::OnSetupOnUICompleted,
weak_factory_.GetWeakPtr(), base::Passed(&params),
is_new_process)));
}
- void OnRegisteredToDevToolsManager(
- std::unique_ptr<EmbeddedWorkerMsg_StartWorker_Params> params,
- bool is_new_process,
- int worker_devtools_agent_route_id,
- bool wait_for_debugger) {
+ void OnSetupOnUICompleted(std::unique_ptr<EmbeddedWorkerStartParams> params,
+ bool is_new_process,
+ int worker_devtools_agent_route_id,
+ bool wait_for_debugger) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
TRACE_EVENT_ASYNC_STEP_PAST0("ServiceWorker",
"EmbeddedWorkerInstance::Start", this,
- "OnRegisteredToDevToolsManager");
+ "OnSetupOnUICompleted");
// Notify the instance that it is registered to the devtools manager.
instance_->OnRegisteredToDevToolsManager(
@@ -366,11 +373,14 @@
params->worker_devtools_agent_route_id = worker_devtools_agent_route_id;
params->wait_for_debugger = wait_for_debugger;
- SendStartWorker(std::move(params));
- }
-
- void SendStartWorker(
- std::unique_ptr<EmbeddedWorkerMsg_StartWorker_Params> params) {
+
+ if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled())
+ instance_->SendMojoStartWorker(std::move(params));
+ else
+ SendStartWorker(std::move(params));
+ }
+
+ void SendStartWorker(std::unique_ptr<EmbeddedWorkerStartParams> params) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
ServiceWorkerStatusCode status = instance_->registry_->SendStartWorker(
std::move(params), instance_->process_id());
@@ -393,6 +403,10 @@
// |instance_| must outlive |this|.
EmbeddedWorkerInstance* instance_;
+ // Ownership is transferred by base::Passed() to a task after process
+ // allocation.
+ mojom::EmbeddedWorkerInstanceClientRequest request_;
+
StatusCallback start_callback_;
ProcessAllocationState state_;
@@ -421,7 +435,7 @@
}
void EmbeddedWorkerInstance::Start(
- std::unique_ptr<EmbeddedWorkerMsg_StartWorker_Params> params,
+ std::unique_ptr<EmbeddedWorkerStartParams> params,
const StatusCallback& callback) {
if (!context_) {
callback.Run(SERVICE_WORKER_ERROR_ABORT);
@@ -445,7 +459,12 @@
params->wait_for_debugger = false;
params->settings.v8_cache_options = GetV8CacheOptions();
- inflight_start_task_.reset(new StartTask(this, params->script_url));
+ mojom::EmbeddedWorkerInstanceClientRequest request;
+ if (ServiceWorkerUtils::IsMojoForServiceWorkerEnabled())
+ request = mojo::GetProxy(&client_);
+
+ inflight_start_task_.reset(
+ new StartTask(this, params->script_url, std::move(request)));
inflight_start_task_->Start(std::move(params), callback);
}
@@ -565,6 +584,15 @@
}
}
+void EmbeddedWorkerInstance::SendMojoStartWorker(
+ std::unique_ptr<EmbeddedWorkerStartParams> params) {
+ client_->StartWorker(*params);
+ registry_->BindWorkerToProcess(process_id(), embedded_worker_id());
+ TRACE_EVENT_ASYNC_STEP_PAST1("ServiceWorker", "EmbeddedWorkerInstance::Start",
+ this, "SendStartWorker", "Status", "mojo");
+ OnStartWorkerMessageSent();
+}
+
void EmbeddedWorkerInstance::OnStartWorkerMessageSent() {
if (!step_time_.is_null()) {
base::TimeDelta duration = UpdateStepTime();
@@ -659,9 +687,10 @@
FOR_EACH_OBSERVER(Listener, listener_list_, OnThreadStarted());
shell::mojom::InterfaceProviderPtr exposed_interfaces;
- interface_registry_->Bind(GetProxy(&exposed_interfaces));
+ interface_registry_->Bind(mojo::GetProxy(&exposed_interfaces));
shell::mojom::InterfaceProviderPtr remote_interfaces;
- shell::mojom::InterfaceProviderRequest request = GetProxy(&remote_interfaces);
+ shell::mojom::InterfaceProviderRequest request =
+ mojo::GetProxy(&remote_interfaces);
remote_interfaces_->Bind(std::move(remote_interfaces));
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,

Powered by Google App Engine
This is Rietveld 408576698