Commit 1b25c303 authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

Dedicated workers: Replace started/terminated with created/destroyed

This change simply renames OnWorkerStarted() and
OnBeforeWorkerTerminated() with OnWorkerCreated() and
OnBeforeWorkerDestroyed() to be be more in line with the
SharedWorkerService observer interface.

No behavior changes.

Bug: 993029
Change-Id: I53582e7d7704116166127de426ed581cf1dd4b4d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2200077
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: default avatarSigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771146}
parent 7820f093
......@@ -58,7 +58,7 @@ PerProfileWorkerTaskTracker::~PerProfileWorkerTaskTracker() {
worker_task_provider_->OnWorkerTaskRemoved(kv.second.get());
}
void PerProfileWorkerTaskTracker::OnWorkerStarted(
void PerProfileWorkerTaskTracker::OnWorkerCreated(
content::DedicatedWorkerId dedicated_worker_id,
int worker_process_id,
content::GlobalFrameRoutingId ancestor_render_frame_host_id) {
......@@ -66,7 +66,7 @@ void PerProfileWorkerTaskTracker::OnWorkerStarted(
worker_process_id, &dedicated_worker_tasks_);
}
void PerProfileWorkerTaskTracker::OnBeforeWorkerTerminated(
void PerProfileWorkerTaskTracker::OnBeforeWorkerDestroyed(
content::DedicatedWorkerId dedicated_worker_id,
content::GlobalFrameRoutingId ancestor_render_frame_host_id) {
DeleteWorkerTask(dedicated_worker_id, &dedicated_worker_tasks_);
......
......@@ -42,11 +42,11 @@ class PerProfileWorkerTaskTracker
delete;
// content::DedicatedWorkerService::Observer:
void OnWorkerStarted(
void OnWorkerCreated(
content::DedicatedWorkerId dedicated_worker_id,
int worker_process_id,
content::GlobalFrameRoutingId ancestor_render_frame_host_id) override;
void OnBeforeWorkerTerminated(
void OnBeforeWorkerDestroyed(
content::DedicatedWorkerId dedicated_worker_id,
content::GlobalFrameRoutingId ancestor_render_frame_host_id) override;
void OnFinalResponseURLDetermined(
......
......@@ -129,7 +129,7 @@ void WorkerWatcher::TearDown() {
service_worker_context_observer_.RemoveAll();
}
void WorkerWatcher::OnWorkerStarted(
void WorkerWatcher::OnWorkerCreated(
content::DedicatedWorkerId dedicated_worker_id,
int worker_process_id,
content::GlobalFrameRoutingId ancestor_render_frame_host_id) {
......@@ -147,7 +147,7 @@ void WorkerWatcher::OnWorkerStarted(
ancestor_render_frame_host_id);
}
void WorkerWatcher::OnBeforeWorkerTerminated(
void WorkerWatcher::OnBeforeWorkerDestroyed(
content::DedicatedWorkerId dedicated_worker_id,
content::GlobalFrameRoutingId ancestor_render_frame_host_id) {
auto it = dedicated_worker_nodes_.find(dedicated_worker_id);
......
......@@ -49,11 +49,11 @@ class WorkerWatcher : public content::DedicatedWorkerService::Observer,
void TearDown();
// content::DedicatedWorkerService::Observer:
void OnWorkerStarted(
void OnWorkerCreated(
content::DedicatedWorkerId dedicated_worker_id,
int worker_process_id,
content::GlobalFrameRoutingId ancestor_render_frame_host_id) override;
void OnBeforeWorkerTerminated(
void OnBeforeWorkerDestroyed(
content::DedicatedWorkerId dedicated_worker_id,
content::GlobalFrameRoutingId ancestor_render_frame_host_id) override;
void OnFinalResponseURLDetermined(
......
......@@ -53,8 +53,8 @@ bool IsWorkerClient(WorkerNodeImpl* worker_node,
// TestDedicatedWorkerService --------------------------------------------------
// A test TestDedicatedWorkerService that allows to simulate starting and
// stopping a dedicated worker.
// A test DedicatedWorkerService that allows to simulate creating and destroying
// dedicated workers.
class TestDedicatedWorkerService : public content::DedicatedWorkerService {
public:
TestDedicatedWorkerService();
......@@ -65,13 +65,13 @@ class TestDedicatedWorkerService : public content::DedicatedWorkerService {
void RemoveObserver(Observer* observer) override;
void EnumerateDedicatedWorkers(Observer* observer) override;
// Starts a new dedicated worker and returns its ID.
content::DedicatedWorkerId StartDedicatedWorker(
// Creates a new dedicated worker and returns its ID.
content::DedicatedWorkerId CreateDedicatedWorker(
int worker_process_id,
content::GlobalFrameRoutingId client_render_frame_host_id);
// Stops a running shared worker.
void StopDedicatedWorker(content::DedicatedWorkerId dedicated_worker_id);
// Destroys an existing dedicated worker.
void DestroyDedicatedWorker(content::DedicatedWorkerId dedicated_worker_id);
private:
base::ObserverList<Observer> observer_list_;
......@@ -103,7 +103,7 @@ void TestDedicatedWorkerService::EnumerateDedicatedWorkers(Observer* observer) {
ADD_FAILURE();
}
content::DedicatedWorkerId TestDedicatedWorkerService::StartDedicatedWorker(
content::DedicatedWorkerId TestDedicatedWorkerService::CreateDedicatedWorker(
int worker_process_id,
content::GlobalFrameRoutingId client_render_frame_host_id) {
// Create a new DedicatedWorkerId for the worker and add it to the map, along
......@@ -118,21 +118,21 @@ content::DedicatedWorkerId TestDedicatedWorkerService::StartDedicatedWorker(
// Notify observers.
for (auto& observer : observer_list_) {
observer.OnWorkerStarted(dedicated_worker_id, worker_process_id,
observer.OnWorkerCreated(dedicated_worker_id, worker_process_id,
client_render_frame_host_id);
}
return dedicated_worker_id;
}
void TestDedicatedWorkerService::StopDedicatedWorker(
void TestDedicatedWorkerService::DestroyDedicatedWorker(
content::DedicatedWorkerId dedicated_worker_id) {
auto it = dedicated_worker_client_frame_.find(dedicated_worker_id);
DCHECK(it != dedicated_worker_client_frame_.end());
// Notify observers that the worker is terminating.
// Notify observers that the worker is being destroyed.
for (auto& observer : observer_list_)
observer.OnBeforeWorkerTerminated(dedicated_worker_id, it->second);
observer.OnBeforeWorkerDestroyed(dedicated_worker_id, it->second);
// Remove the worker ID from the map.
dedicated_worker_client_frame_.erase(it);
......@@ -714,8 +714,8 @@ TEST_F(WorkerWatcherTest, SimpleDedicatedWorker) {
// Create the worker.
content::DedicatedWorkerId dedicated_worker_id =
dedicated_worker_service()->StartDedicatedWorker(render_process_id,
render_frame_host_id);
dedicated_worker_service()->CreateDedicatedWorker(render_process_id,
render_frame_host_id);
// Check expectations on the graph.
CallOnGraphAndWait(base::BindLambdaForTesting(
......@@ -731,7 +731,7 @@ TEST_F(WorkerWatcherTest, SimpleDedicatedWorker) {
}));
// Disconnect and clean up the worker.
dedicated_worker_service()->StopDedicatedWorker(dedicated_worker_id);
dedicated_worker_service()->DestroyDedicatedWorker(dedicated_worker_id);
}
// This test creates one shared worker with one client frame.
......@@ -953,8 +953,8 @@ TEST_F(WorkerWatcherTest, FrameDestroyed) {
// Create a worker of each type.
content::DedicatedWorkerId dedicated_worker_id =
dedicated_worker_service()->StartDedicatedWorker(render_process_id,
render_frame_host_id);
dedicated_worker_service()->CreateDedicatedWorker(render_process_id,
render_frame_host_id);
content::SharedWorkerId shared_worker_id =
shared_worker_service()->CreateSharedWorker(render_process_id);
int64_t service_worker_version_id =
......@@ -1006,7 +1006,7 @@ TEST_F(WorkerWatcherTest, FrameDestroyed) {
shared_worker_service()->RemoveFrameClientFromWorker(shared_worker_id,
render_frame_host_id);
shared_worker_service()->DestroySharedWorker(shared_worker_id);
dedicated_worker_service()->StopDedicatedWorker(dedicated_worker_id);
dedicated_worker_service()->DestroyDedicatedWorker(dedicated_worker_id);
}
} // namespace performance_manager
......@@ -65,12 +65,12 @@ DedicatedWorkerHost::DedicatedWorkerHost(
scoped_process_host_observer_.Add(worker_process_host_);
service_->NotifyWorkerStarted(id_, worker_process_host_->GetID(),
service_->NotifyWorkerCreated(id_, worker_process_host_->GetID(),
ancestor_render_frame_host_id_);
}
DedicatedWorkerHost::~DedicatedWorkerHost() {
service_->NotifyWorkerTerminating(id_, ancestor_render_frame_host_id_);
service_->NotifyBeforeWorkerDestroyed(id_, ancestor_render_frame_host_id_);
}
void DedicatedWorkerHost::BindBrowserInterfaceBrokerReceiver(
......
......@@ -25,7 +25,7 @@ void DedicatedWorkerServiceImpl::EnumerateDedicatedWorkers(Observer* observer) {
DedicatedWorkerId dedicated_worker_id = kv.first;
const DedicatedWorkerInfo& dedicated_worker_info = kv.second;
observer->OnWorkerStarted(
observer->OnWorkerCreated(
dedicated_worker_id, dedicated_worker_info.worker_process_id,
dedicated_worker_info.ancestor_render_frame_host_id);
}
......@@ -35,7 +35,7 @@ DedicatedWorkerId DedicatedWorkerServiceImpl::GenerateNextDedicatedWorkerId() {
return dedicated_worker_id_generator_.GenerateNextId();
}
void DedicatedWorkerServiceImpl::NotifyWorkerStarted(
void DedicatedWorkerServiceImpl::NotifyWorkerCreated(
DedicatedWorkerId dedicated_worker_id,
int worker_process_id,
GlobalFrameRoutingId ancestor_render_frame_host_id) {
......@@ -48,20 +48,20 @@ void DedicatedWorkerServiceImpl::NotifyWorkerStarted(
DCHECK(inserted);
for (Observer& observer : observers_) {
observer.OnWorkerStarted(dedicated_worker_id, worker_process_id,
observer.OnWorkerCreated(dedicated_worker_id, worker_process_id,
ancestor_render_frame_host_id);
}
}
void DedicatedWorkerServiceImpl::NotifyWorkerTerminating(
void DedicatedWorkerServiceImpl::NotifyBeforeWorkerDestroyed(
DedicatedWorkerId dedicated_worker_id,
GlobalFrameRoutingId ancestor_render_frame_host_id) {
size_t removed = dedicated_worker_infos_.erase(dedicated_worker_id);
DCHECK_EQ(removed, 1u);
for (Observer& observer : observers_) {
observer.OnBeforeWorkerTerminated(dedicated_worker_id,
ancestor_render_frame_host_id);
observer.OnBeforeWorkerDestroyed(dedicated_worker_id,
ancestor_render_frame_host_id);
}
}
......
......@@ -25,13 +25,13 @@ class CONTENT_EXPORT DedicatedWorkerServiceImpl
DedicatedWorkerId GenerateNextDedicatedWorkerId();
// Notifies all observers about a starting worker.
void NotifyWorkerStarted(DedicatedWorkerId dedicated_worker_id,
// Notifies all observers about a new worker.
void NotifyWorkerCreated(DedicatedWorkerId dedicated_worker_id,
int worker_process_id,
GlobalFrameRoutingId ancestor_render_frame_host_id);
// Notifies all observers about a terminating worker.
void NotifyWorkerTerminating(
// Notifies all observers about a worker being destroyed.
void NotifyBeforeWorkerDestroyed(
DedicatedWorkerId dedicated_worker_id,
GlobalFrameRoutingId ancestor_render_frame_host_id);
......
......@@ -161,7 +161,7 @@ class TestDedicatedWorkerServiceObserver
const TestDedicatedWorkerServiceObserver& other) = delete;
// DedicatedWorkerService::Observer:
void OnWorkerStarted(
void OnWorkerCreated(
DedicatedWorkerId dedicated_worker_id,
int worker_process_id,
GlobalFrameRoutingId ancestor_render_frame_host_id) override {
......@@ -176,7 +176,7 @@ class TestDedicatedWorkerServiceObserver
if (on_worker_event_callback_)
std::move(on_worker_event_callback_).Run();
}
void OnBeforeWorkerTerminated(
void OnBeforeWorkerDestroyed(
DedicatedWorkerId dedicated_worker_id,
GlobalFrameRoutingId ancestor_render_frame_host_id) override {
size_t removed = dedicated_worker_infos_.erase(dedicated_worker_id);
......
......@@ -20,12 +20,14 @@ class CONTENT_EXPORT DedicatedWorkerService {
public:
class Observer : public base::CheckedObserver {
public:
// Called when a dedicated worker has started/stopped.
virtual void OnWorkerStarted(
// Called when a dedicated worker is created/destroyed. Note that it is not
// yet started in the renderer since its script still has to be downloaded
// and evaluated.
virtual void OnWorkerCreated(
DedicatedWorkerId dedicated_worker_id,
int worker_process_id,
GlobalFrameRoutingId ancestor_render_frame_host_id) = 0;
virtual void OnBeforeWorkerTerminated(
virtual void OnBeforeWorkerDestroyed(
DedicatedWorkerId dedicated_worker_id,
GlobalFrameRoutingId ancestor_render_frame_host_id) = 0;
......@@ -42,13 +44,13 @@ class CONTENT_EXPORT DedicatedWorkerService {
virtual void AddObserver(Observer* observer) = 0;
virtual void RemoveObserver(Observer* observer) = 0;
// Invokes OnWorkerStarted() on |observer| for all existing dedicated workers.
// Invokes OnWorkerCreated() on |observer| for all existing dedicated workers.
//
// This function must be invoked in conjunction with AddObserver(). It is
// meant to be used by an observer that dynamically subscribes to the
// DedicatedWorkerService while some workers are already running. It avoids
// receiving a OnBeforeWorkerTerminated() event without having received the
// corresponding OnWorkerStart() event.
// receiving a OnBeforeWorkerDestroyed() event without having received the
// corresponding OnWorkerCreated() event.
virtual void EnumerateDedicatedWorkers(Observer* observer) = 0;
protected:
......
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