Commit 5970f41e authored by Chris Hamilton's avatar Chris Hamilton Committed by Commit Bot

Add ServiceWorkerToken to service worker code.

This adorns content::ServiceWorkerVersion, blink::ServiceWorkerThread
and blink::ServiceWorkerGlobalScope with a ServiceWorkerToken. The token
is generated in the browser process and communicated to the renderer as
the worker is started.

BUG=1085129, 1096617

Change-Id: I24972cf9be48dd0208042abaa3607807e0f6afed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2330450Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Chris Hamilton <chrisha@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795636}
parent a05c9ecd
...@@ -256,11 +256,10 @@ void WorkerWatcher::OnVersionStartedRunning( ...@@ -256,11 +256,10 @@ void WorkerWatcher::OnVersionStartedRunning(
const content::ServiceWorkerRunningInfo& running_info) { const content::ServiceWorkerRunningInfo& running_info) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// TODO(chrisha): Plumb in the ServiceWorkerToken.
auto worker_node = PerformanceManagerImpl::CreateWorkerNode( auto worker_node = PerformanceManagerImpl::CreateWorkerNode(
browser_context_id_, WorkerNode::WorkerType::kService, browser_context_id_, WorkerNode::WorkerType::kService,
process_node_source_->GetProcessNode(running_info.render_process_id), process_node_source_->GetProcessNode(running_info.render_process_id),
WorkerToken::Create()); WorkerToken(running_info.token.value()));
bool inserted = bool inserted =
service_worker_nodes_.emplace(version_id, std::move(worker_node)).second; service_worker_nodes_.emplace(version_id, std::move(worker_node)).second;
DCHECK(inserted); DCHECK(inserted);
......
...@@ -345,8 +345,10 @@ int64_t TestServiceWorkerContext::StartServiceWorker(int worker_process_id) { ...@@ -345,8 +345,10 @@ int64_t TestServiceWorkerContext::StartServiceWorker(int worker_process_id) {
// Notify observers. // Notify observers.
for (auto& observer : observer_list_) { for (auto& observer : observer_list_) {
observer.OnVersionStartedRunning(version_id, observer.OnVersionStartedRunning(
{worker_url, GURL(), worker_process_id}); version_id,
content::ServiceWorkerRunningInfo(worker_url, GURL(), worker_process_id,
blink::ServiceWorkerToken::Create()));
} }
return version_id; return version_id;
......
...@@ -864,6 +864,7 @@ void EmbeddedWorkerInstance::Start( ...@@ -864,6 +864,7 @@ void EmbeddedWorkerInstance::Start(
status_ = EmbeddedWorkerStatus::STARTING; status_ = EmbeddedWorkerStatus::STARTING;
starting_phase_ = ALLOCATING_PROCESS; starting_phase_ = ALLOCATING_PROCESS;
network_accessed_for_script_ = false; network_accessed_for_script_ = false;
token_ = blink::ServiceWorkerToken::Create();
for (auto& observer : listener_list_) for (auto& observer : listener_list_)
observer.OnStarting(); observer.OnStarting();
...@@ -873,6 +874,7 @@ void EmbeddedWorkerInstance::Start( ...@@ -873,6 +874,7 @@ void EmbeddedWorkerInstance::Start(
params->wait_for_debugger = false; params->wait_for_debugger = false;
params->subresource_loader_updater = params->subresource_loader_updater =
subresource_loader_updater_.BindNewPipeAndPassReceiver(); subresource_loader_updater_.BindNewPipeAndPassReceiver();
params->service_worker_token = token_.value();
// TODO(https://crbug.com/978694): Consider a reset flow since new mojo types // TODO(https://crbug.com/978694): Consider a reset flow since new mojo types
// check is_bound strictly. // check is_bound strictly.
...@@ -1373,6 +1375,7 @@ void EmbeddedWorkerInstance::ReleaseProcess() { ...@@ -1373,6 +1375,7 @@ void EmbeddedWorkerInstance::ReleaseProcess() {
status_ = EmbeddedWorkerStatus::STOPPED; status_ = EmbeddedWorkerStatus::STOPPED;
starting_phase_ = NOT_STARTING; starting_phase_ = NOT_STARTING;
thread_id_ = ServiceWorkerConsts::kInvalidEmbeddedWorkerThreadId; thread_id_ = ServiceWorkerConsts::kInvalidEmbeddedWorkerThreadId;
token_ = base::nullopt;
} }
void EmbeddedWorkerInstance::OnSetupFailed( void EmbeddedWorkerInstance::OnSetupFailed(
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/observer_list.h" #include "base/observer_list.h"
#include "base/optional.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/threading/sequence_bound.h" #include "base/threading/sequence_bound.h"
#include "base/time/time.h" #include "base/time/time.h"
...@@ -31,6 +32,7 @@ ...@@ -31,6 +32,7 @@
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "third_party/blink/public/common/service_worker/service_worker_status_code.h" #include "third_party/blink/public/common/service_worker/service_worker_status_code.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom.h" #include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom.h"
#include "third_party/blink/public/mojom/service_worker/controller_service_worker.mojom.h" #include "third_party/blink/public/mojom/service_worker/controller_service_worker.mojom.h"
#include "third_party/blink/public/mojom/service_worker/embedded_worker.mojom.h" #include "third_party/blink/public/mojom/service_worker/embedded_worker.mojom.h"
...@@ -247,6 +249,13 @@ class CONTENT_EXPORT EmbeddedWorkerInstance ...@@ -247,6 +249,13 @@ class CONTENT_EXPORT EmbeddedWorkerInstance
std::unique_ptr<blink::PendingURLLoaderFactoryBundle> subresouce_bundle)>; std::unique_ptr<blink::PendingURLLoaderFactoryBundle> subresouce_bundle)>;
void CreateFactoryBundles(CreateFactoryBundlesCallback callback); void CreateFactoryBundles(CreateFactoryBundlesCallback callback);
// Returns the unique token that has been generated to identify this worker
// instance, and its corresponding GlobalScope in the renderer process. If the
// service worker is not currently running, this is base::nullopt.
const base::Optional<blink::ServiceWorkerToken>& token() const {
return token_;
}
private: private:
typedef base::ObserverList<Listener>::Unchecked ListenerList; typedef base::ObserverList<Listener>::Unchecked ListenerList;
class ScopedLifetimeTracker; class ScopedLifetimeTracker;
...@@ -399,6 +408,12 @@ class CONTENT_EXPORT EmbeddedWorkerInstance ...@@ -399,6 +408,12 @@ class CONTENT_EXPORT EmbeddedWorkerInstance
mojo::Remote<network::mojom::CrossOriginEmbedderPolicyReporter> mojo::Remote<network::mojom::CrossOriginEmbedderPolicyReporter>
coep_reporter_; coep_reporter_;
// A unique identifier for this service worker instance. This is unique across
// the browser process, but not persistent across service worker restarts.
// This token is set every time the worker starts, and is plumbed through to
// the corresponding ServiceWorkerGlobalScope in the renderer process.
base::Optional<blink::ServiceWorkerToken> token_;
base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_{this}; base::WeakPtrFactory<EmbeddedWorkerInstance> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance); DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerInstance);
......
...@@ -959,7 +959,8 @@ void ServiceWorkerContextCore::OnRunningStateChanged( ...@@ -959,7 +959,8 @@ void ServiceWorkerContextCore::OnRunningStateChanged(
observer_list_->Notify( observer_list_->Notify(
FROM_HERE, &ServiceWorkerContextCoreObserver::OnStarted, FROM_HERE, &ServiceWorkerContextCoreObserver::OnStarted,
version->version_id(), version->scope(), version->version_id(), version->scope(),
version->embedded_worker()->process_id(), version->script_url()); version->embedded_worker()->process_id(), version->script_url(),
version->embedded_worker()->token().value());
break; break;
case EmbeddedWorkerStatus::STOPPING: case EmbeddedWorkerStatus::STOPPING:
observer_list_->Notify(FROM_HERE, observer_list_->Notify(FROM_HERE,
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "content/browser/service_worker/service_worker_version.h" #include "content/browser/service_worker/service_worker_version.h"
#include "content/public/browser/global_routing_id.h" #include "content/public/browser/global_routing_id.h"
#include "content/public/browser/service_worker_context_observer.h" #include "content/public/browser/service_worker_context_observer.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_container_type.mojom.h" #include "third_party/blink/public/mojom/service_worker/service_worker_container_type.mojom.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -33,7 +34,8 @@ class ServiceWorkerContextCoreObserver { ...@@ -33,7 +34,8 @@ class ServiceWorkerContextCoreObserver {
virtual void OnStarted(int64_t version_id, virtual void OnStarted(int64_t version_id,
const GURL& scope, const GURL& scope,
int process_id, int process_id,
const GURL& script_url) {} const GURL& script_url,
const blink::ServiceWorkerToken& token) {}
virtual void OnStopping(int64_t version_id) {} virtual void OnStopping(int64_t version_id) {}
virtual void OnStopped(int64_t version_id) {} virtual void OnStopped(int64_t version_id) {}
// Called when the context core is about to be deleted. After this is called, // Called when the context core is about to be deleted. After this is called,
......
...@@ -237,10 +237,12 @@ void ServiceWorkerContextWatcher::OnStarting(int64_t version_id) { ...@@ -237,10 +237,12 @@ void ServiceWorkerContextWatcher::OnStarting(int64_t version_id) {
OnRunningStateChanged(version_id, EmbeddedWorkerStatus::STARTING); OnRunningStateChanged(version_id, EmbeddedWorkerStatus::STARTING);
} }
void ServiceWorkerContextWatcher::OnStarted(int64_t version_id, void ServiceWorkerContextWatcher::OnStarted(
const GURL& scope, int64_t version_id,
int process_id, const GURL& scope,
const GURL& script_url) { int process_id,
const GURL& script_url,
const blink::ServiceWorkerToken& token) {
OnRunningStateChanged(version_id, EmbeddedWorkerStatus::RUNNING); OnRunningStateChanged(version_id, EmbeddedWorkerStatus::RUNNING);
} }
......
...@@ -89,7 +89,8 @@ class CONTENT_EXPORT ServiceWorkerContextWatcher ...@@ -89,7 +89,8 @@ class CONTENT_EXPORT ServiceWorkerContextWatcher
void OnStarted(int64_t version_id, void OnStarted(int64_t version_id,
const GURL& scope, const GURL& scope,
int process_id, int process_id,
const GURL& script_url) override; const GURL& script_url,
const blink::ServiceWorkerToken& token) override;
void OnStopping(int64_t version_id) override; void OnStopping(int64_t version_id) override;
void OnStopped(int64_t version_id) override; void OnStopped(int64_t version_id) override;
void OnVersionStateChanged(int64_t version_id, void OnVersionStateChanged(int64_t version_id,
......
...@@ -423,14 +423,17 @@ void ServiceWorkerContextWrapper::OnControlleeNavigationCommitted( ...@@ -423,14 +423,17 @@ void ServiceWorkerContextWrapper::OnControlleeNavigationCommitted(
render_frame_host_id); render_frame_host_id);
} }
void ServiceWorkerContextWrapper::OnStarted(int64_t version_id, void ServiceWorkerContextWrapper::OnStarted(
const GURL& scope, int64_t version_id,
int process_id, const GURL& scope,
const GURL& script_url) { int process_id,
const GURL& script_url,
const blink::ServiceWorkerToken& token) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
auto insertion_result = running_service_workers_.insert(std::make_pair( auto insertion_result = running_service_workers_.insert(std::make_pair(
version_id, ServiceWorkerRunningInfo(script_url, scope, process_id))); version_id,
ServiceWorkerRunningInfo(script_url, scope, process_id, token)));
DCHECK(insertion_result.second); DCHECK(insertion_result.second);
const auto& running_info = insertion_result.first->second; const auto& running_info = insertion_result.first->second;
......
...@@ -147,7 +147,8 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper ...@@ -147,7 +147,8 @@ class CONTENT_EXPORT ServiceWorkerContextWrapper
void OnStarted(int64_t version_id, void OnStarted(int64_t version_id,
const GURL& scope, const GURL& scope,
int process_id, int process_id,
const GURL& script_url) override; const GURL& script_url,
const blink::ServiceWorkerToken& token) override;
void OnStopped(int64_t version_id) override; void OnStopped(int64_t version_id) override;
void OnDeleteAndStartOver() override; void OnDeleteAndStartOver() override;
void OnVersionStateChanged(int64_t version_id, void OnVersionStateChanged(int64_t version_id,
......
...@@ -283,7 +283,8 @@ class ServiceWorkerInternalsUI::PartitionObserver ...@@ -283,7 +283,8 @@ class ServiceWorkerInternalsUI::PartitionObserver
void OnStarted(int64_t version_id, void OnStarted(int64_t version_id,
const GURL& scope, const GURL& scope,
int process_id, int process_id,
const GURL& script_url) override { const GURL& script_url,
const blink::ServiceWorkerToken& token) override {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
web_ui_->CallJavascriptFunctionUnsafe( web_ui_->CallJavascriptFunctionUnsafe(
"serviceworker.onRunningStateChanged"); "serviceworker.onRunningStateChanged");
......
...@@ -6,12 +6,15 @@ ...@@ -6,12 +6,15 @@
namespace content { namespace content {
ServiceWorkerRunningInfo::ServiceWorkerRunningInfo(const GURL& script_url, ServiceWorkerRunningInfo::ServiceWorkerRunningInfo(
const GURL& scope, const GURL& script_url,
int64_t render_process_id) const GURL& scope,
int64_t render_process_id,
const blink::ServiceWorkerToken& token)
: script_url(script_url), : script_url(script_url),
scope(scope), scope(scope),
render_process_id(render_process_id) {} render_process_id(render_process_id),
token(token) {}
ServiceWorkerRunningInfo::ServiceWorkerRunningInfo( ServiceWorkerRunningInfo::ServiceWorkerRunningInfo(
ServiceWorkerRunningInfo&& other) noexcept = default; ServiceWorkerRunningInfo&& other) noexcept = default;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/public/common/child_process_host.h" #include "content/public/common/child_process_host.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_object.mojom.h" #include "third_party/blink/public/mojom/service_worker/service_worker_object.mojom.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -16,7 +17,8 @@ namespace content { ...@@ -16,7 +17,8 @@ namespace content {
struct CONTENT_EXPORT ServiceWorkerRunningInfo { struct CONTENT_EXPORT ServiceWorkerRunningInfo {
ServiceWorkerRunningInfo(const GURL& script_url, ServiceWorkerRunningInfo(const GURL& script_url,
const GURL& scope, const GURL& scope,
int64_t render_process_id); int64_t render_process_id,
const blink::ServiceWorkerToken& token);
ServiceWorkerRunningInfo(ServiceWorkerRunningInfo&& other) noexcept; ServiceWorkerRunningInfo(ServiceWorkerRunningInfo&& other) noexcept;
ServiceWorkerRunningInfo& operator=( ServiceWorkerRunningInfo& operator=(
ServiceWorkerRunningInfo&& other) noexcept; ServiceWorkerRunningInfo&& other) noexcept;
...@@ -30,6 +32,9 @@ struct CONTENT_EXPORT ServiceWorkerRunningInfo { ...@@ -30,6 +32,9 @@ struct CONTENT_EXPORT ServiceWorkerRunningInfo {
// The ID of the render process on which this service worker lives. // The ID of the render process on which this service worker lives.
int render_process_id = content::ChildProcessHost::kInvalidUniqueID; int render_process_id = content::ChildProcessHost::kInvalidUniqueID;
// The token that uniquely identifies this worker.
blink::ServiceWorkerToken token;
}; };
} // namespace content } // namespace content
......
...@@ -176,6 +176,7 @@ EmbeddedWorkerInstanceClientImpl::BuildStartData( ...@@ -176,6 +176,7 @@ EmbeddedWorkerInstanceClientImpl::BuildStartData(
? blink::WebEmbeddedWorkerStartData::kWaitForDebugger ? blink::WebEmbeddedWorkerStartData::kWaitForDebugger
: blink::WebEmbeddedWorkerStartData::kDontWaitForDebugger; : blink::WebEmbeddedWorkerStartData::kDontWaitForDebugger;
start_data->devtools_worker_token = params.devtools_worker_token; start_data->devtools_worker_token = params.devtools_worker_token;
start_data->service_worker_token = params.service_worker_token;
return start_data; return start_data;
} }
......
...@@ -22,6 +22,7 @@ import "third_party/blink/public/mojom/service_worker/service_worker_installed_s ...@@ -22,6 +22,7 @@ import "third_party/blink/public/mojom/service_worker/service_worker_installed_s
import "third_party/blink/public/mojom/service_worker/service_worker_event_status.mojom"; import "third_party/blink/public/mojom/service_worker/service_worker_event_status.mojom";
import "third_party/blink/public/mojom/service_worker/service_worker_provider.mojom"; import "third_party/blink/public/mojom/service_worker/service_worker_provider.mojom";
import "third_party/blink/public/mojom/service_worker/service_worker_registration.mojom"; import "third_party/blink/public/mojom/service_worker/service_worker_registration.mojom";
import "third_party/blink/public/mojom/tokens/tokens.mojom";
import "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom"; import "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom";
import "third_party/blink/public/mojom/worker/worker_content_settings_proxy.mojom"; import "third_party/blink/public/mojom/worker/worker_content_settings_proxy.mojom";
import "third_party/blink/public/mojom/web_feature/web_feature.mojom"; import "third_party/blink/public/mojom/web_feature/web_feature.mojom";
...@@ -114,6 +115,12 @@ struct EmbeddedWorkerStartParams { ...@@ -114,6 +115,12 @@ struct EmbeddedWorkerStartParams {
// Used for updating subresource loaders after NetworkService crash etc. // Used for updating subresource loaders after NetworkService crash etc.
pending_receiver<SubresourceLoaderUpdater> subresource_loader_updater; pending_receiver<SubresourceLoaderUpdater> subresource_loader_updater;
// A unique token identifying this ServiceWorker. In can be used to identify
// this particular ServiceWorker in subsequent renderer -> browser messages
// that aren't on the EmbeddedWorkerInstanceHost interface. This is not
// persistent across worker restarts.
ServiceWorkerToken service_worker_token;
}; };
// Holds timing information about the start worker sequence for UMA. // Holds timing information about the start worker sequence for UMA.
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "base/unguessable_token.h" #include "base/unguessable_token.h"
#include "services/network/public/mojom/ip_address_space.mojom-shared.h" #include "services/network/public/mojom/ip_address_space.mojom-shared.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/common/user_agent/user_agent_metadata.h" #include "third_party/blink/public/common/user_agent/user_agent_metadata.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_registration.mojom-shared.h" #include "third_party/blink/public/mojom/service_worker/service_worker_registration.mojom-shared.h"
#include "third_party/blink/public/platform/web_fetch_client_settings_object.h" #include "third_party/blink/public/platform/web_fetch_client_settings_object.h"
...@@ -59,6 +60,10 @@ struct WebEmbeddedWorkerStartData { ...@@ -59,6 +60,10 @@ struct WebEmbeddedWorkerStartData {
WebFetchClientSettingsObject outside_fetch_client_settings_object; WebFetchClientSettingsObject outside_fetch_client_settings_object;
// Unique token that identifies this worker across the browser and renderer
// processes. This is not persistent across worker restarts.
blink::ServiceWorkerToken service_worker_token;
explicit WebEmbeddedWorkerStartData( explicit WebEmbeddedWorkerStartData(
WebFetchClientSettingsObject outside_fetch_client_settings_object) WebFetchClientSettingsObject outside_fetch_client_settings_object)
: wait_for_debugger_mode(kDontWaitForDebugger), : wait_for_debugger_mode(kDontWaitForDebugger),
......
...@@ -231,7 +231,7 @@ void WebEmbeddedWorkerImpl::StartWorkerThread( ...@@ -231,7 +231,7 @@ void WebEmbeddedWorkerImpl::StartWorkerThread(
std::make_unique<ServiceWorkerGlobalScopeProxy>( std::make_unique<ServiceWorkerGlobalScopeProxy>(
*this, *worker_context_client_, initiator_thread_task_runner), *this, *worker_context_client_, initiator_thread_task_runner),
std::move(installed_scripts_manager), std::move(cache_storage_remote), std::move(installed_scripts_manager), std::move(cache_storage_remote),
initiator_thread_task_runner); initiator_thread_task_runner, worker_start_data->service_worker_token);
auto devtools_params = std::make_unique<WorkerDevToolsParams>(); auto devtools_params = std::make_unique<WorkerDevToolsParams>();
devtools_params->devtools_worker_token = devtools_params->devtools_worker_token =
......
...@@ -193,7 +193,8 @@ ServiceWorkerGlobalScope* ServiceWorkerGlobalScope::Create( ...@@ -193,7 +193,8 @@ ServiceWorkerGlobalScope* ServiceWorkerGlobalScope::Create(
std::unique_ptr<ServiceWorkerInstalledScriptsManager> std::unique_ptr<ServiceWorkerInstalledScriptsManager>
installed_scripts_manager, installed_scripts_manager,
mojo::PendingRemote<mojom::blink::CacheStorage> cache_storage_remote, mojo::PendingRemote<mojom::blink::CacheStorage> cache_storage_remote,
base::TimeTicks time_origin) { base::TimeTicks time_origin,
const ServiceWorkerToken& service_worker_token) {
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
// If the script is being loaded via script streaming, the script is not yet // If the script is being loaded via script streaming, the script is not yet
// loaded. // loaded.
...@@ -210,7 +211,7 @@ ServiceWorkerGlobalScope* ServiceWorkerGlobalScope::Create( ...@@ -210,7 +211,7 @@ ServiceWorkerGlobalScope* ServiceWorkerGlobalScope::Create(
return MakeGarbageCollected<ServiceWorkerGlobalScope>( return MakeGarbageCollected<ServiceWorkerGlobalScope>(
std::move(creation_params), thread, std::move(installed_scripts_manager), std::move(creation_params), thread, std::move(installed_scripts_manager),
std::move(cache_storage_remote), time_origin); std::move(cache_storage_remote), time_origin, service_worker_token);
} }
ServiceWorkerGlobalScope::ServiceWorkerGlobalScope( ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(
...@@ -219,13 +220,15 @@ ServiceWorkerGlobalScope::ServiceWorkerGlobalScope( ...@@ -219,13 +220,15 @@ ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(
std::unique_ptr<ServiceWorkerInstalledScriptsManager> std::unique_ptr<ServiceWorkerInstalledScriptsManager>
installed_scripts_manager, installed_scripts_manager,
mojo::PendingRemote<mojom::blink::CacheStorage> cache_storage_remote, mojo::PendingRemote<mojom::blink::CacheStorage> cache_storage_remote,
base::TimeTicks time_origin) base::TimeTicks time_origin,
const ServiceWorkerToken& service_worker_token)
: WorkerGlobalScope(std::move(creation_params), : WorkerGlobalScope(std::move(creation_params),
thread, thread,
time_origin, time_origin,
ukm::kInvalidSourceId), ukm::kInvalidSourceId),
installed_scripts_manager_(std::move(installed_scripts_manager)), installed_scripts_manager_(std::move(installed_scripts_manager)),
cache_storage_remote_(std::move(cache_storage_remote)) { cache_storage_remote_(std::move(cache_storage_remote)),
token_(service_worker_token) {
// Create the event queue. At this point its timer is not started. It will be // Create the event queue. At this point its timer is not started. It will be
// started by DidEvaluateScript(). // started by DidEvaluateScript().
// //
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/network/public/mojom/network_context.mojom-blink-forward.h" #include "services/network/public/mojom/network_context.mojom-blink-forward.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom-blink-forward.h" #include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom-blink-forward.h"
#include "third_party/blink/public/mojom/service_worker/controller_service_worker.mojom-blink.h" #include "third_party/blink/public/mojom/service_worker/controller_service_worker.mojom-blink.h"
#include "third_party/blink/public/mojom/service_worker/service_worker.mojom-blink.h" #include "third_party/blink/public/mojom/service_worker/service_worker.mojom-blink.h"
...@@ -95,14 +96,16 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final ...@@ -95,14 +96,16 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final
std::unique_ptr<GlobalScopeCreationParams>, std::unique_ptr<GlobalScopeCreationParams>,
std::unique_ptr<ServiceWorkerInstalledScriptsManager>, std::unique_ptr<ServiceWorkerInstalledScriptsManager>,
mojo::PendingRemote<mojom::blink::CacheStorage>, mojo::PendingRemote<mojom::blink::CacheStorage>,
base::TimeTicks time_origin); base::TimeTicks time_origin,
const ServiceWorkerToken& service_worker_token);
ServiceWorkerGlobalScope( ServiceWorkerGlobalScope(
std::unique_ptr<GlobalScopeCreationParams>, std::unique_ptr<GlobalScopeCreationParams>,
ServiceWorkerThread*, ServiceWorkerThread*,
std::unique_ptr<ServiceWorkerInstalledScriptsManager>, std::unique_ptr<ServiceWorkerInstalledScriptsManager>,
mojo::PendingRemote<mojom::blink::CacheStorage>, mojo::PendingRemote<mojom::blink::CacheStorage>,
base::TimeTicks time_origin); base::TimeTicks time_origin,
const ServiceWorkerToken& service_worker_token);
~ServiceWorkerGlobalScope() override; ~ServiceWorkerGlobalScope() override;
// ExecutionContext overrides: // ExecutionContext overrides:
...@@ -325,6 +328,10 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final ...@@ -325,6 +328,10 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final
ResourceLoadScheduler::ThrottleOptionOverride GetThrottleOptionOverride() ResourceLoadScheduler::ThrottleOptionOverride GetThrottleOptionOverride()
const override; const override;
// TODO(chrisha): Lift this up to WorkerGlobalScope once all worker types
// have tokens.
const ServiceWorkerToken& token() const { return token_; }
private: private:
void importScripts(const Vector<String>& urls, ExceptionState&) override; void importScripts(const Vector<String>& urls, ExceptionState&) override;
SingleCachedMetadataHandler* CreateWorkerScriptCachedMetadataHandler( SingleCachedMetadataHandler* CreateWorkerScriptCachedMetadataHandler(
...@@ -710,6 +717,11 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final ...@@ -710,6 +717,11 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final
HeapMojoWrapperMode::kWithoutContextObserver, HeapMojoWrapperMode::kWithoutContextObserver,
std::unique_ptr<CrossOriginResourcePolicyChecker>> std::unique_ptr<CrossOriginResourcePolicyChecker>>
controller_receivers_{this, this}; controller_receivers_{this, this};
// Token that uniquely identifies this service worker. Corresponds to the
// same value in the browser representation of this object. This is not
// persistent across worker restarts.
const ServiceWorkerToken token_;
}; };
template <> template <>
......
...@@ -47,14 +47,16 @@ ServiceWorkerThread::ServiceWorkerThread( ...@@ -47,14 +47,16 @@ ServiceWorkerThread::ServiceWorkerThread(
installed_scripts_manager, installed_scripts_manager,
mojo::PendingRemote<mojom::blink::CacheStorage> cache_storage_remote, mojo::PendingRemote<mojom::blink::CacheStorage> cache_storage_remote,
scoped_refptr<base::SingleThreadTaskRunner> scoped_refptr<base::SingleThreadTaskRunner>
parent_thread_default_task_runner) parent_thread_default_task_runner,
const blink::ServiceWorkerToken& service_worker_token)
: WorkerThread(*global_scope_proxy, : WorkerThread(*global_scope_proxy,
std::move(parent_thread_default_task_runner)), std::move(parent_thread_default_task_runner)),
global_scope_proxy_(std::move(global_scope_proxy)), global_scope_proxy_(std::move(global_scope_proxy)),
worker_backing_thread_(std::make_unique<WorkerBackingThread>( worker_backing_thread_(std::make_unique<WorkerBackingThread>(
ThreadCreationParams(GetThreadType()))), ThreadCreationParams(GetThreadType()))),
installed_scripts_manager_(std::move(installed_scripts_manager)), installed_scripts_manager_(std::move(installed_scripts_manager)),
cache_storage_remote_(std::move(cache_storage_remote)) {} cache_storage_remote_(std::move(cache_storage_remote)),
service_worker_token_(service_worker_token) {}
ServiceWorkerThread::~ServiceWorkerThread() { ServiceWorkerThread::~ServiceWorkerThread() {
global_scope_proxy_->Detach(); global_scope_proxy_->Detach();
...@@ -73,7 +75,7 @@ WorkerOrWorkletGlobalScope* ServiceWorkerThread::CreateWorkerGlobalScope( ...@@ -73,7 +75,7 @@ WorkerOrWorkletGlobalScope* ServiceWorkerThread::CreateWorkerGlobalScope(
std::unique_ptr<GlobalScopeCreationParams> creation_params) { std::unique_ptr<GlobalScopeCreationParams> creation_params) {
return ServiceWorkerGlobalScope::Create( return ServiceWorkerGlobalScope::Create(
this, std::move(creation_params), std::move(installed_scripts_manager_), this, std::move(creation_params), std::move(installed_scripts_manager_),
std::move(cache_storage_remote_), time_origin_); std::move(cache_storage_remote_), time_origin_, service_worker_token_);
} }
} // namespace blink } // namespace blink
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <memory> #include <memory>
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom-blink-forward.h" #include "third_party/blink/public/mojom/cache_storage/cache_storage.mojom-blink-forward.h"
#include "third_party/blink/renderer/core/workers/worker_thread.h" #include "third_party/blink/renderer/core/workers/worker_thread.h"
#include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/modules_export.h"
...@@ -53,7 +54,8 @@ class MODULES_EXPORT ServiceWorkerThread final : public WorkerThread { ...@@ -53,7 +54,8 @@ class MODULES_EXPORT ServiceWorkerThread final : public WorkerThread {
std::unique_ptr<ServiceWorkerInstalledScriptsManager>, std::unique_ptr<ServiceWorkerInstalledScriptsManager>,
mojo::PendingRemote<mojom::blink::CacheStorage> cache_storage_remote, mojo::PendingRemote<mojom::blink::CacheStorage> cache_storage_remote,
scoped_refptr<base::SingleThreadTaskRunner> scoped_refptr<base::SingleThreadTaskRunner>
parent_thread_default_task_runner); parent_thread_default_task_runner,
const ServiceWorkerToken& service_worker_token);
~ServiceWorkerThread() override; ~ServiceWorkerThread() override;
WorkerBackingThread& GetWorkerBackingThread() override { WorkerBackingThread& GetWorkerBackingThread() override {
...@@ -77,6 +79,8 @@ class MODULES_EXPORT ServiceWorkerThread final : public WorkerThread { ...@@ -77,6 +79,8 @@ class MODULES_EXPORT ServiceWorkerThread final : public WorkerThread {
std::unique_ptr<ServiceWorkerInstalledScriptsManager> std::unique_ptr<ServiceWorkerInstalledScriptsManager>
installed_scripts_manager_; installed_scripts_manager_;
mojo::PendingRemote<mojom::blink::CacheStorage> cache_storage_remote_; mojo::PendingRemote<mojom::blink::CacheStorage> cache_storage_remote_;
const ServiceWorkerToken service_worker_token_;
}; };
} // namespace blink } // namespace blink
......
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