Commit eb123fa0 authored by Alex Turner's avatar Alex Turner Committed by Commit Bot

Add ukm::SourceIds to ServiceWorkers

This cl adds a ukm::SourceId to each ServiceWorkerVersion and propagates
that down to the ServiceWorkerGlobalScope.

A followup cl will have each service worker client inform its respective
ServiceWorkerContainerHost of the client's ukm::SourceId. A UKM event
will also be emitted on on that connection in order to associate the two
ukm::SourceIds.

Bug: 1085645
Change-Id: I9a77e4196834379162c8e7516eb0bde58f5fa5e5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2298349
Commit-Queue: Alex Turner <alexmt@chromium.org>
Reviewed-by: default avatarAlex Gough <ajgo@chromium.org>
Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Reviewed-by: default avatarAsanka Herath <asanka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795710}
parent 61215d44
......@@ -267,7 +267,9 @@ ServiceWorkerVersion::ServiceWorkerVersion(
clock_(base::DefaultClock::GetInstance()),
ping_controller_(this),
validator_(std::make_unique<blink::TrialTokenValidator>()),
remote_reference_(std::move(remote_reference)) {
remote_reference_(std::move(remote_reference)),
ukm_source_id_(ukm::ConvertToSourceId(ukm::AssignNewSourceId(),
ukm::SourceIdType::WORKER_ID)) {
DCHECK_NE(blink::mojom::kInvalidServiceWorkerVersionId, version_id);
DCHECK(context_);
DCHECK(registration);
......@@ -1896,6 +1898,8 @@ void ServiceWorkerVersion::StartWorkerInternal() {
params->provider_info = std::move(provider_info);
params->ukm_source_id = ukm_source_id_;
embedded_worker_->Start(std::move(params),
base::BindOnce(&ServiceWorkerVersion::OnStartSent,
weak_factory_.GetWeakPtr()));
......
......@@ -48,6 +48,7 @@
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "services/network/public/cpp/cross_origin_embedder_policy.h"
#include "third_party/blink/public/common/origin_trials/trial_token_validator.h"
#include "third_party/blink/public/common/service_worker/service_worker_status_code.h"
......@@ -213,6 +214,7 @@ class CONTENT_EXPORT ServiceWorkerVersion
}
ServiceWorkerVersionInfo GetInfo();
Status status() const { return status_; }
ukm::SourceId ukm_source_id() const { return ukm_source_id_; }
// This status is set to EXISTS or DOES_NOT_EXIST when the install event has
// been executed in a new version or when an installed version is loaded from
......@@ -1095,6 +1097,10 @@ class CONTENT_EXPORT ServiceWorkerVersion
// for more details.
mojo::Remote<storage::mojom::ServiceWorkerLiveVersionRef> remote_reference_;
// Identifier for UKM recording in the service worker thread. Stored here so
// it can be associated with clients' source IDs.
const ukm::SourceId ukm_source_id_;
base::WeakPtrFactory<ServiceWorkerVersion> weak_factory_{this};
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerVersion);
......
......@@ -177,6 +177,7 @@ EmbeddedWorkerInstanceClientImpl::BuildStartData(
: blink::WebEmbeddedWorkerStartData::kDontWaitForDebugger;
start_data->devtools_worker_token = params.devtools_worker_token;
start_data->service_worker_token = params.service_worker_token;
start_data->ukm_source_id = params.ukm_source_id;
return start_data;
}
......
......@@ -121,6 +121,11 @@ struct EmbeddedWorkerStartParams {
// that aren't on the EmbeddedWorkerInstanceHost interface. This is not
// persistent across worker restarts.
ServiceWorkerToken service_worker_token;
// The UKM SourceId associated with the service worker. This persists across
// service worker restarts, but not browser restarts. It is distinct from the
// IDs associated with the connected clients.
int64 ukm_source_id;
};
// Holds timing information about the start worker sequence for UMA.
......
......@@ -32,6 +32,7 @@
#define THIRD_PARTY_BLINK_PUBLIC_WEB_WEB_EMBEDDED_WORKER_START_DATA_H_
#include "base/unguessable_token.h"
#include "services/metrics/public/cpp/ukm_source_id.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"
......@@ -55,6 +56,7 @@ struct WebEmbeddedWorkerStartData {
// Unique worker token used by DevTools to attribute different instrumentation
// to the same worker.
base::UnguessableToken devtools_worker_token;
ukm::SourceId ukm_source_id = ukm::kInvalidSourceId;
network::mojom::IPAddressSpace address_space;
......
......@@ -231,7 +231,8 @@ void WebEmbeddedWorkerImpl::StartWorkerThread(
std::make_unique<ServiceWorkerGlobalScopeProxy>(
*this, *worker_context_client_, initiator_thread_task_runner),
std::move(installed_scripts_manager), std::move(cache_storage_remote),
initiator_thread_task_runner, worker_start_data->service_worker_token);
initiator_thread_task_runner, worker_start_data->service_worker_token,
worker_start_data->ukm_source_id);
auto devtools_params = std::make_unique<WorkerDevToolsParams>();
devtools_params->devtools_worker_token =
......
......@@ -4,6 +4,7 @@ include_rules = [
"+base/trace_event/trace_event.h",
"+mojo/public/cpp/system/data_pipe.h",
"+services/network/public",
"+services/metrics/public/cpp/ukm_source_id.h",
"-third_party/blink/renderer/modules",
"+third_party/blink/renderer/modules/event_modules.h",
"+third_party/blink/renderer/modules/event_target_modules.h",
......@@ -13,7 +14,6 @@ include_rules = [
specific_include_rules = {
"service_worker_global_scope\.cc": [
"+services/metrics/public/cpp/ukm_source_id.h",
"+third_party/blink/renderer/modules/background_fetch",
"+third_party/blink/renderer/modules/background_sync",
"+third_party/blink/renderer/modules/content_index",
......
......@@ -40,7 +40,6 @@
#include "base/numerics/safe_conversions.h"
#include "base/time/time.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "services/network/public/cpp/cross_origin_embedder_policy.h"
#include "services/network/public/mojom/cross_origin_embedder_policy.mojom.h"
#include "third_party/blink/public/common/features.h"
......@@ -194,7 +193,8 @@ ServiceWorkerGlobalScope* ServiceWorkerGlobalScope::Create(
installed_scripts_manager,
mojo::PendingRemote<mojom::blink::CacheStorage> cache_storage_remote,
base::TimeTicks time_origin,
const ServiceWorkerToken& service_worker_token) {
const ServiceWorkerToken& service_worker_token,
ukm::SourceId ukm_source_id) {
#if DCHECK_IS_ON()
// If the script is being loaded via script streaming, the script is not yet
// loaded.
......@@ -211,7 +211,8 @@ ServiceWorkerGlobalScope* ServiceWorkerGlobalScope::Create(
return MakeGarbageCollected<ServiceWorkerGlobalScope>(
std::move(creation_params), thread, std::move(installed_scripts_manager),
std::move(cache_storage_remote), time_origin, service_worker_token);
std::move(cache_storage_remote), time_origin, service_worker_token,
ukm_source_id);
}
ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(
......@@ -221,11 +222,12 @@ ServiceWorkerGlobalScope::ServiceWorkerGlobalScope(
installed_scripts_manager,
mojo::PendingRemote<mojom::blink::CacheStorage> cache_storage_remote,
base::TimeTicks time_origin,
const ServiceWorkerToken& service_worker_token)
const ServiceWorkerToken& service_worker_token,
ukm::SourceId ukm_source_id)
: WorkerGlobalScope(std::move(creation_params),
thread,
time_origin,
ukm::kInvalidSourceId),
ukm_source_id),
installed_scripts_manager_(std::move(installed_scripts_manager)),
cache_storage_remote_(std::move(cache_storage_remote)),
token_(service_worker_token) {
......
......@@ -37,6 +37,7 @@
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/metrics/public/cpp/ukm_source_id.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"
......@@ -97,7 +98,8 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final
std::unique_ptr<ServiceWorkerInstalledScriptsManager>,
mojo::PendingRemote<mojom::blink::CacheStorage>,
base::TimeTicks time_origin,
const ServiceWorkerToken& service_worker_token);
const ServiceWorkerToken& service_worker_token,
ukm::SourceId ukm_source_id);
ServiceWorkerGlobalScope(
std::unique_ptr<GlobalScopeCreationParams>,
......@@ -105,7 +107,8 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final
std::unique_ptr<ServiceWorkerInstalledScriptsManager>,
mojo::PendingRemote<mojom::blink::CacheStorage>,
base::TimeTicks time_origin,
const ServiceWorkerToken& service_worker_token);
const ServiceWorkerToken& service_worker_token,
ukm::SourceId ukm_source_id);
~ServiceWorkerGlobalScope() override;
// ExecutionContext overrides:
......
......@@ -48,7 +48,8 @@ ServiceWorkerThread::ServiceWorkerThread(
mojo::PendingRemote<mojom::blink::CacheStorage> cache_storage_remote,
scoped_refptr<base::SingleThreadTaskRunner>
parent_thread_default_task_runner,
const blink::ServiceWorkerToken& service_worker_token)
const blink::ServiceWorkerToken& service_worker_token,
ukm::SourceId ukm_source_id)
: WorkerThread(*global_scope_proxy,
std::move(parent_thread_default_task_runner)),
global_scope_proxy_(std::move(global_scope_proxy)),
......@@ -56,7 +57,8 @@ ServiceWorkerThread::ServiceWorkerThread(
ThreadCreationParams(GetThreadType()))),
installed_scripts_manager_(std::move(installed_scripts_manager)),
cache_storage_remote_(std::move(cache_storage_remote)),
service_worker_token_(service_worker_token) {}
service_worker_token_(service_worker_token),
ukm_source_id_(ukm_source_id) {}
ServiceWorkerThread::~ServiceWorkerThread() {
global_scope_proxy_->Detach();
......@@ -75,7 +77,8 @@ WorkerOrWorkletGlobalScope* ServiceWorkerThread::CreateWorkerGlobalScope(
std::unique_ptr<GlobalScopeCreationParams> creation_params) {
return ServiceWorkerGlobalScope::Create(
this, std::move(creation_params), std::move(installed_scripts_manager_),
std::move(cache_storage_remote_), time_origin_, service_worker_token_);
std::move(cache_storage_remote_), time_origin_, service_worker_token_,
ukm_source_id_);
}
} // namespace blink
......@@ -55,7 +55,8 @@ class MODULES_EXPORT ServiceWorkerThread final : public WorkerThread {
mojo::PendingRemote<mojom::blink::CacheStorage> cache_storage_remote,
scoped_refptr<base::SingleThreadTaskRunner>
parent_thread_default_task_runner,
const ServiceWorkerToken& service_worker_token);
const ServiceWorkerToken& service_worker_token,
ukm::SourceId ukm_source_id);
~ServiceWorkerThread() override;
WorkerBackingThread& GetWorkerBackingThread() override {
......@@ -81,6 +82,8 @@ class MODULES_EXPORT ServiceWorkerThread final : public WorkerThread {
mojo::PendingRemote<mojom::blink::CacheStorage> cache_storage_remote_;
const ServiceWorkerToken service_worker_token_;
const ukm::SourceId ukm_source_id_;
};
} // 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