Commit 20f60637 authored by Hayato Ito's avatar Hayato Ito Committed by Commit Bot

Rename ServiceWorkerTimeoutTimer to ServiceWorkerEventQueue

Follow-up of http://crrev/c/1906452.
This CL intentionally did only the file renaming and necessary minimum
changes so that Gerrit can recognize the file renaming correctly.

Note if we did all follow-up tasks in one CL, Gerrit
couldn't recognize the file renaming, as seen in http://crrev/c/1942903.

Other trivial and non-trivial changes, such as PushTask -> EnqueueNormal,
renaming functions and variables, will be included in other follow-up
CLs.

TBR=kinuko@chromium.org

Bug: 965802
Change-Id: I68ee6edfdad4083a7056928b246c6ff916619067
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1945951
Commit-Queue: Hayato Ito <hayato@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720847}
parent 4bb949f4
......@@ -395,8 +395,8 @@ jumbo_source_set("unit_tests") {
"sensor/sensor_test_utils.cc",
"sensor/sensor_test_utils.h",
"service_worker/service_worker_container_test.cc",
"service_worker/service_worker_event_queue_test.cc",
"service_worker/service_worker_installed_scripts_manager_test.cc",
"service_worker/service_worker_timeout_timer_test.cc",
"service_worker/thread_safe_script_container_test.cc",
"service_worker/web_embedded_worker_impl_test.cc",
"wake_lock/wake_lock_manager_test.cc",
......
......@@ -36,6 +36,8 @@ blink_modules_sources("service_worker") {
"service_worker_content_settings_proxy.h",
"service_worker_error.cc",
"service_worker_error.h",
"service_worker_event_queue.cc",
"service_worker_event_queue.h",
"service_worker_global_scope.cc",
"service_worker_global_scope.h",
"service_worker_global_scope_proxy.cc",
......@@ -50,8 +52,6 @@ blink_modules_sources("service_worker") {
"service_worker_script_cached_metadata_handler.h",
"service_worker_thread.cc",
"service_worker_thread.h",
"service_worker_timeout_timer.cc",
"service_worker_timeout_timer.h",
"service_worker_window_client.cc",
"service_worker_window_client.h",
"thread_safe_script_container.cc",
......
......@@ -33,7 +33,7 @@ specific_include_rules = {
"+base/run_loop.h",
"+mojo/public/cpp/bindings/binding.h",
],
"service_worker_timeout_timer_test\.cc": [
"service_worker_event_queue_test\.cc": [
"+base/test/test_mock_time_task_runner.h",
],
"web_embedded_worker_impl_test\.cc": [
......
......@@ -140,7 +140,7 @@ class FetchLoaderClient final : public GarbageCollected<FetchLoaderClient>,
public:
FetchLoaderClient(
std::unique_ptr<ServiceWorkerTimeoutTimer::StayAwakeToken> token)
std::unique_ptr<ServiceWorkerEventQueue::StayAwakeToken> token)
: token_(std::move(token)) {
// We need to make |callback_| callable in the first place because some
// DidFetchDataLoadXXX() accessing it may be called synchronously from
......@@ -187,7 +187,7 @@ class FetchLoaderClient final : public GarbageCollected<FetchLoaderClient>,
callback_receiver_;
mojo::Remote<mojom::blink::ServiceWorkerStreamCallback> callback_;
std::unique_ptr<ServiceWorkerTimeoutTimer::StayAwakeToken> token_;
std::unique_ptr<ServiceWorkerEventQueue::StayAwakeToken> token_;
DISALLOW_COPY_AND_ASSIGN(FetchLoaderClient);
};
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/service_worker/service_worker_timeout_timer.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_event_queue.h"
#include "base/atomic_sequence_num.h"
#include "base/bind.h"
......@@ -28,40 +28,40 @@ int NextEventId() {
} // namespace
// static
constexpr base::TimeDelta ServiceWorkerTimeoutTimer::kIdleDelay;
constexpr base::TimeDelta ServiceWorkerTimeoutTimer::kEventTimeout;
constexpr base::TimeDelta ServiceWorkerTimeoutTimer::kUpdateInterval;
constexpr base::TimeDelta ServiceWorkerEventQueue::kIdleDelay;
constexpr base::TimeDelta ServiceWorkerEventQueue::kEventTimeout;
constexpr base::TimeDelta ServiceWorkerEventQueue::kUpdateInterval;
ServiceWorkerTimeoutTimer::StayAwakeToken::StayAwakeToken(
base::WeakPtr<ServiceWorkerTimeoutTimer> timer)
: timer_(std::move(timer)) {
DCHECK(timer_);
timer_->num_of_stay_awake_tokens_++;
ServiceWorkerEventQueue::StayAwakeToken::StayAwakeToken(
base::WeakPtr<ServiceWorkerEventQueue> event_queue)
: event_queue_(std::move(event_queue)) {
DCHECK(event_queue_);
event_queue_->num_of_stay_awake_tokens_++;
}
ServiceWorkerTimeoutTimer::StayAwakeToken::~StayAwakeToken() {
// If |timer_| has already been destroyed, it means the worker thread has
// already been killed.
if (!timer_)
ServiceWorkerEventQueue::StayAwakeToken::~StayAwakeToken() {
// If |event_queue_| has already been destroyed, it means the worker thread
// has already been killed.
if (!event_queue_)
return;
DCHECK_GT(timer_->num_of_stay_awake_tokens_, 0);
timer_->num_of_stay_awake_tokens_--;
DCHECK_GT(event_queue_->num_of_stay_awake_tokens_, 0);
event_queue_->num_of_stay_awake_tokens_--;
if (!timer_->HasInflightEvent())
timer_->OnNoInflightEvent();
if (!event_queue_->HasInflightEvent())
event_queue_->OnNoInflightEvent();
}
ServiceWorkerTimeoutTimer::ServiceWorkerTimeoutTimer(
ServiceWorkerEventQueue::ServiceWorkerEventQueue(
base::RepeatingClosure idle_callback)
: ServiceWorkerTimeoutTimer(std::move(idle_callback),
base::DefaultTickClock::GetInstance()) {}
: ServiceWorkerEventQueue(std::move(idle_callback),
base::DefaultTickClock::GetInstance()) {}
ServiceWorkerTimeoutTimer::ServiceWorkerTimeoutTimer(
ServiceWorkerEventQueue::ServiceWorkerEventQueue(
base::RepeatingClosure idle_callback,
const base::TickClock* tick_clock)
: idle_callback_(std::move(idle_callback)), tick_clock_(tick_clock) {}
ServiceWorkerTimeoutTimer::~ServiceWorkerTimeoutTimer() {
ServiceWorkerEventQueue::~ServiceWorkerEventQueue() {
in_dtor_ = true;
// Abort all callbacks.
for (auto& event : id_event_map_) {
......@@ -70,17 +70,17 @@ ServiceWorkerTimeoutTimer::~ServiceWorkerTimeoutTimer() {
}
}
void ServiceWorkerTimeoutTimer::Start() {
void ServiceWorkerEventQueue::Start() {
DCHECK(!timer_.IsRunning());
// |idle_callback_| will be invoked if no event happens in |kIdleDelay|.
if (!HasInflightEvent() && idle_time_.is_null())
idle_time_ = tick_clock_->NowTicks() + kIdleDelay;
timer_.Start(FROM_HERE, kUpdateInterval,
WTF::BindRepeating(&ServiceWorkerTimeoutTimer::UpdateStatus,
WTF::BindRepeating(&ServiceWorkerEventQueue::UpdateStatus,
WTF::Unretained(this)));
}
void ServiceWorkerTimeoutTimer::PushTask(std::unique_ptr<Task> task) {
void ServiceWorkerEventQueue::PushTask(std::unique_ptr<Task> task) {
DCHECK(task->type != Task::Type::Pending || did_idle_timeout());
bool can_start_processing_tasks =
!processing_tasks_ && task->type != Task::Type::Pending;
......@@ -94,7 +94,7 @@ void ServiceWorkerTimeoutTimer::PushTask(std::unique_ptr<Task> task) {
ProcessTasks();
}
void ServiceWorkerTimeoutTimer::ProcessTasks() {
void ServiceWorkerEventQueue::ProcessTasks() {
DCHECK(!processing_tasks_);
processing_tasks_ = true;
while (!task_queue_.IsEmpty()) {
......@@ -110,14 +110,14 @@ void ServiceWorkerTimeoutTimer::ProcessTasks() {
OnNoInflightEvent();
}
void ServiceWorkerTimeoutTimer::StartTask(std::unique_ptr<Task> task) {
void ServiceWorkerEventQueue::StartTask(std::unique_ptr<Task> task) {
int event_id = StartEvent(std::move(task->abort_callback),
task->custom_timeout.value_or(kEventTimeout));
std::move(task->start_callback).Run(event_id);
}
int ServiceWorkerTimeoutTimer::StartEvent(AbortCallback abort_callback,
base::TimeDelta timeout) {
int ServiceWorkerEventQueue::StartEvent(AbortCallback abort_callback,
base::TimeDelta timeout) {
idle_time_ = base::TimeTicks();
const int event_id = NextEventId();
auto add_result = id_event_map_.insert(
......@@ -128,7 +128,7 @@ int ServiceWorkerTimeoutTimer::StartEvent(AbortCallback abort_callback,
return event_id;
}
void ServiceWorkerTimeoutTimer::EndEvent(int event_id) {
void ServiceWorkerEventQueue::EndEvent(int event_id) {
DCHECK(HasEvent(event_id));
id_event_map_.erase(event_id);
// Check |processing_tasks_| here because EndEvent() can be called
......@@ -138,23 +138,23 @@ void ServiceWorkerTimeoutTimer::EndEvent(int event_id) {
OnNoInflightEvent();
}
bool ServiceWorkerTimeoutTimer::HasEvent(int event_id) const {
bool ServiceWorkerEventQueue::HasEvent(int event_id) const {
return id_event_map_.find(event_id) != id_event_map_.end();
}
std::unique_ptr<ServiceWorkerTimeoutTimer::StayAwakeToken>
ServiceWorkerTimeoutTimer::CreateStayAwakeToken() {
return std::make_unique<ServiceWorkerTimeoutTimer::StayAwakeToken>(
std::unique_ptr<ServiceWorkerEventQueue::StayAwakeToken>
ServiceWorkerEventQueue::CreateStayAwakeToken() {
return std::make_unique<ServiceWorkerEventQueue::StayAwakeToken>(
weak_factory_.GetWeakPtr());
}
void ServiceWorkerTimeoutTimer::SetIdleTimerDelayToZero() {
void ServiceWorkerEventQueue::SetIdleTimerDelayToZero() {
zero_idle_timer_delay_ = true;
if (!HasInflightEvent())
MaybeTriggerIdleTimer();
}
void ServiceWorkerTimeoutTimer::UpdateStatus() {
void ServiceWorkerEventQueue::UpdateStatus() {
base::TimeTicks now = tick_clock_->NowTicks();
HashMap<int /* event_id */, std::unique_ptr<EventInfo>> new_id_event_map;
......@@ -187,7 +187,7 @@ void ServiceWorkerTimeoutTimer::UpdateStatus() {
}
}
bool ServiceWorkerTimeoutTimer::MaybeTriggerIdleTimer() {
bool ServiceWorkerEventQueue::MaybeTriggerIdleTimer() {
DCHECK(!HasInflightEvent());
if (!zero_idle_timer_delay_)
return false;
......@@ -197,18 +197,18 @@ bool ServiceWorkerTimeoutTimer::MaybeTriggerIdleTimer() {
return true;
}
void ServiceWorkerTimeoutTimer::OnNoInflightEvent() {
void ServiceWorkerEventQueue::OnNoInflightEvent() {
DCHECK(!HasInflightEvent());
idle_time_ = tick_clock_->NowTicks() + kIdleDelay;
MaybeTriggerIdleTimer();
}
bool ServiceWorkerTimeoutTimer::HasInflightEvent() const {
bool ServiceWorkerEventQueue::HasInflightEvent() const {
return !id_event_map_.IsEmpty() || num_of_stay_awake_tokens_ > 0;
}
ServiceWorkerTimeoutTimer::Task::Task(
ServiceWorkerTimeoutTimer::Task::Type type,
ServiceWorkerEventQueue::Task::Task(
ServiceWorkerEventQueue::Task::Type type,
StartCallback start_callback,
AbortCallback abort_callback,
base::Optional<base::TimeDelta> custom_timeout)
......@@ -217,15 +217,15 @@ ServiceWorkerTimeoutTimer::Task::Task(
abort_callback(std::move(abort_callback)),
custom_timeout(custom_timeout) {}
ServiceWorkerTimeoutTimer::Task::~Task() = default;
ServiceWorkerEventQueue::Task::~Task() = default;
ServiceWorkerTimeoutTimer::EventInfo::EventInfo(
ServiceWorkerEventQueue::EventInfo::EventInfo(
base::TimeTicks expiration_time,
base::OnceCallback<void(blink::mojom::ServiceWorkerEventStatus)>
abort_callback)
: expiration_time(expiration_time),
abort_callback(std::move(abort_callback)) {}
ServiceWorkerTimeoutTimer::EventInfo::~EventInfo() = default;
ServiceWorkerEventQueue::EventInfo::~EventInfo() = default;
} // namespace blink
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SERVICE_WORKER_SERVICE_WORKER_TIMEOUT_TIMER_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SERVICE_WORKER_SERVICE_WORKER_TIMEOUT_TIMER_H_
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SERVICE_WORKER_SERVICE_WORKER_EVENT_QUEUE_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SERVICE_WORKER_SERVICE_WORKER_EVENT_QUEUE_H_
#include <set>
......@@ -24,7 +24,7 @@ class TickClock;
namespace blink {
// ServiceWorkerTimeoutTimer manages two types of timeouts: the long standing
// ServiceWorkerEventQueue manages two types of timeouts: the long standing
// event timeout and the idle timeout.
//
// 1) Event timeout: when an event starts, StartEvent() records the expiration
......@@ -33,39 +33,39 @@ namespace blink {
// status TIMEOUT. Also, |zero_idle_timer_delay_| is set to true to shut down
// the worker as soon as possible since the worker may have gone into bad state.
// 2) Idle timeout: when a certain time has passed (kIdleDelay) since all of
// events have ended, ServiceWorkerTimeoutTimer calls the |idle_callback|.
// events have ended, ServiceWorkerEventQueue calls the |idle_callback|.
// |idle_callback| will be continuously called at a certain interval
// (kUpdateInterval) until the next event starts.
//
// The lifetime of ServiceWorkerTimeoutTimer is the same with the worker
// thread. If ServiceWorkerTimeoutTimer is destructed while there are inflight
// The lifetime of ServiceWorkerEventQueue is the same with the worker
// thread. If ServiceWorkerEventQueue is destructed while there are inflight
// events, all |abort_callback|s will be immediately called with status ABORTED.
class MODULES_EXPORT ServiceWorkerTimeoutTimer {
class MODULES_EXPORT ServiceWorkerEventQueue {
public:
// A token to keep the timeout timer from going into the idle state if any of
// A token to keep the event queue from going into the idle state if any of
// them are alive.
class MODULES_EXPORT StayAwakeToken {
public:
explicit StayAwakeToken(base::WeakPtr<ServiceWorkerTimeoutTimer> timer);
explicit StayAwakeToken(base::WeakPtr<ServiceWorkerEventQueue> event_queue);
~StayAwakeToken();
private:
base::WeakPtr<ServiceWorkerTimeoutTimer> timer_;
base::WeakPtr<ServiceWorkerEventQueue> event_queue_;
};
using AbortCallback =
base::OnceCallback<void(int /* event_id */,
mojom::blink::ServiceWorkerEventStatus)>;
explicit ServiceWorkerTimeoutTimer(base::RepeatingClosure idle_callback);
explicit ServiceWorkerEventQueue(base::RepeatingClosure idle_callback);
// For testing.
ServiceWorkerTimeoutTimer(base::RepeatingClosure idle_callback,
const base::TickClock* tick_clock);
~ServiceWorkerTimeoutTimer();
ServiceWorkerEventQueue(base::RepeatingClosure idle_callback,
const base::TickClock* tick_clock);
~ServiceWorkerEventQueue();
// Starts the timer. This may also update |idle_time_| if there was no
// Starts the event_queue. This may also update |idle_time_| if there was no
// activities (i.e., StartEvent()/EndEvent() or StayAwakeToken creation)
// on the timer before.
// on the event_queue before.
void Start();
using StartCallback = base::OnceCallback<void(int /* event_id */)>;
......@@ -93,12 +93,12 @@ class MODULES_EXPORT ServiceWorkerTimeoutTimer {
base::Optional<base::TimeDelta> custom_timeout);
~Task();
Type type;
// Callback which is run when the timer starts this task. The
// Callback which is run when the event_queue starts this task. The
// callback receives |event_id|, which is the result of
// StartEvent(). When an event finishes, EndEvent() should be
// called with the given |event_id|.
StartCallback start_callback;
// Callback which is run when the timer aborts a started task.
// Callback which is run when the event_queue aborts a started task.
AbortCallback abort_callback;
// The custom timeout value.
base::Optional<base::TimeDelta> custom_timeout;
......@@ -106,8 +106,8 @@ class MODULES_EXPORT ServiceWorkerTimeoutTimer {
void EndEvent(int event_id);
// Push the task to the task queue in the timer and tasks in the queue can run
// synchronously. See also Task's comment.
// Push the task to the queue, and tasks in the queue can run synchronously.
// See also Task's comment.
void PushTask(std::unique_ptr<Task> task);
// Returns true if |event_id| was started and hasn't ended.
......@@ -134,7 +134,7 @@ class MODULES_EXPORT ServiceWorkerTimeoutTimer {
// called.
static constexpr base::TimeDelta kEventTimeout =
base::TimeDelta::FromMinutes(5);
// ServiceWorkerTimeoutTimer periodically updates the timeout state by
// ServiceWorkerEventQueue periodically updates the timeout state by
// kUpdateInterval.
static constexpr base::TimeDelta kUpdateInterval =
base::TimeDelta::FromSeconds(30);
......@@ -214,9 +214,9 @@ class MODULES_EXPORT ServiceWorkerTimeoutTimer {
bool in_dtor_ = false;
base::WeakPtrFactory<ServiceWorkerTimeoutTimer> weak_factory_{this};
base::WeakPtrFactory<ServiceWorkerEventQueue> weak_factory_{this};
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_SERVICE_WORKER_SERVICE_WORKER_TIMEOUT_TIMER_H_
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_SERVICE_WORKER_SERVICE_WORKER_EVENT_QUEUE_H_
......@@ -45,8 +45,8 @@
#include "third_party/blink/renderer/bindings/core/v8/request_or_usv_string.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_event_queue.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_installed_scripts_manager.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_timeout_timer.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/wtf/casting.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
......@@ -168,9 +168,9 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final
// PauseEvaluation() is called.
void ResumeEvaluation();
// Creates a ServiceWorkerTimeoutTimer::StayAwakeToken to ensure that the idle
// Creates a ServiceWorkerEventQueue::StayAwakeToken to ensure that the idle
// timer won't be triggered while any of these are alive.
std::unique_ptr<ServiceWorkerTimeoutTimer::StayAwakeToken>
std::unique_ptr<ServiceWorkerEventQueue::StayAwakeToken>
CreateStayAwakeToken();
// Returns the ServiceWorker object described by the given info. Creates a new
......@@ -338,7 +338,7 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final
// number of scripts and the total bytes of scripts.
void CountScriptInternal(size_t script_size, size_t cached_metadata_size);
// Called by ServiceWorkerTimeoutTimer when a certain time has passed since
// Called by ServiceWorkerEventQueue when a certain time has passed since
// the last task finished.
void OnIdleTimeout();
......@@ -583,7 +583,7 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final
mojo::Receiver<mojom::blink::ServiceWorker> receiver_{this};
// Maps for inflight event callbacks.
// These are mapped from an event id issued from ServiceWorkerTimeoutTimer to
// These are mapped from an event id issued from ServiceWorkerEventQueue to
// the Mojo callback to notify the end of the event.
HashMap<int, DispatchInstallEventCallback> install_event_callbacks_;
HashMap<int, DispatchActivateEventCallback> activate_event_callbacks_;
......@@ -643,7 +643,7 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final
// Timer triggered when the service worker considers it should be stopped or
// an event should be aborted.
std::unique_ptr<ServiceWorkerTimeoutTimer> timeout_timer_;
std::unique_ptr<ServiceWorkerEventQueue> event_queue_;
// InitializeGlobalScope() pauses the top level script evaluation when this
// flag is true.
......@@ -653,9 +653,9 @@ class MODULES_EXPORT ServiceWorkerGlobalScope final
// Connected by the ServiceWorkerProviderHost in the browser process and by
// the controllees. |controller_bindings_| should be destroyed before
// |timeout_timer_| since the pipe needs to be disconnected before callbacks
// |event_queue_| since the pipe needs to be disconnected before callbacks
// passed by DispatchSomeEvent() get destructed, which may be stored in
// |timeout_timer_|.
// |event_queue_|.
// network::mojom::blink::CrossOriginEmbedderPolicy set as the context of
// mojo::ReceiverSet is the policy for the client which dispatches FetchEvents
// to the ControllerServiceWorker. It should be referred to before sending the
......
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