Commit 018b2004 authored by Patrick Monette's avatar Patrick Monette Committed by Commit Bot

Rename ServiceWorkerTaskProvider to WorkerTaskProvider

This is a more suitable name for this class as it will be used
to track dedicated workers and shared workers in the future.

Bug: 1041093
Change-Id: I711aff37886fa63ad8b799694b9ab81f8bcf3d10
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1993728
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#734684}
parent 9e0ce0a6
......@@ -3595,10 +3595,6 @@ jumbo_static_library("browser") {
"task_manager/providers/fallback_task_provider.h",
"task_manager/providers/render_process_host_task_provider.cc",
"task_manager/providers/render_process_host_task_provider.h",
"task_manager/providers/service_worker_task.cc",
"task_manager/providers/service_worker_task.h",
"task_manager/providers/service_worker_task_provider.cc",
"task_manager/providers/service_worker_task_provider.h",
"task_manager/providers/task.cc",
"task_manager/providers/task.h",
"task_manager/providers/task_provider.cc",
......@@ -3646,6 +3642,10 @@ jumbo_static_library("browser") {
"task_manager/providers/web_contents/web_contents_tags_manager.h",
"task_manager/providers/web_contents/web_contents_task_provider.cc",
"task_manager/providers/web_contents/web_contents_task_provider.h",
"task_manager/providers/worker_task.cc",
"task_manager/providers/worker_task.h",
"task_manager/providers/worker_task_provider.cc",
"task_manager/providers/worker_task_provider.h",
"task_manager/sampling/shared_sampler.h",
"task_manager/sampling/shared_sampler_win.cc",
"task_manager/sampling/shared_sampler_win_defines.h",
......
......@@ -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 "chrome/browser/task_manager/providers/service_worker_task.h"
#include "chrome/browser/task_manager/providers/worker_task.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/grit/generated_resources.h"
......@@ -10,23 +10,35 @@
namespace task_manager {
ServiceWorkerTask::ServiceWorkerTask(base::ProcessHandle handle,
int render_process_id,
const GURL& script_url)
: Task(l10n_util::GetStringFUTF16(IDS_TASK_MANAGER_SERVICE_WORKER_PREFIX,
int GetTaskTitlePrefixMessageId(Task::Type task_type) {
switch (task_type) {
case Task::Type::SERVICE_WORKER:
return IDS_TASK_MANAGER_SERVICE_WORKER_PREFIX;
default:
NOTREACHED();
return 0;
}
}
WorkerTask::WorkerTask(base::ProcessHandle handle,
const GURL& script_url,
Task::Type task_type,
int render_process_id)
: Task(l10n_util::GetStringFUTF16(GetTaskTitlePrefixMessageId(task_type),
base::UTF8ToUTF16(script_url.spec())),
script_url.spec(),
nullptr /* icon */,
handle),
task_type_(task_type),
render_process_id_(render_process_id) {}
ServiceWorkerTask::~ServiceWorkerTask() = default;
WorkerTask::~WorkerTask() = default;
Task::Type ServiceWorkerTask::GetType() const {
return Task::SERVICE_WORKER;
Task::Type WorkerTask::GetType() const {
return task_type_;
}
int ServiceWorkerTask::GetChildProcessUniqueID() const {
int WorkerTask::GetChildProcessUniqueID() const {
return render_process_id_;
}
......
......@@ -2,34 +2,43 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_TASK_MANAGER_PROVIDERS_SERVICE_WORKER_TASK_H_
#define CHROME_BROWSER_TASK_MANAGER_PROVIDERS_SERVICE_WORKER_TASK_H_
#ifndef CHROME_BROWSER_TASK_MANAGER_PROVIDERS_WORKER_TASK_H_
#define CHROME_BROWSER_TASK_MANAGER_PROVIDERS_WORKER_TASK_H_
#include "chrome/browser/task_manager/providers/task.h"
#include "url/gurl.h"
namespace task_manager {
// This class represents a task that corresponds to a service worker.
// https://w3c.github.io/ServiceWorker/
class ServiceWorkerTask : public Task {
// This class represents a task that corresponds to a dedicated worker, a shared
// worker or a service worker.
// See https://w3c.github.io/workers/ or https://w3c.github.io/ServiceWorker/
// for more details.
class WorkerTask : public Task {
public:
ServiceWorkerTask(base::ProcessHandle handle,
int render_process_id,
const GURL& script_url);
~ServiceWorkerTask() override;
WorkerTask(base::ProcessHandle handle,
const GURL& script_url,
Task::Type task_type,
int render_process_id);
~WorkerTask() override;
// task_manager::Task implementation:
// Non-copyable.
WorkerTask(const WorkerTask& other) = delete;
WorkerTask& operator=(const WorkerTask& other) = delete;
// task_manager::Task:
Task::Type GetType() const override;
int GetChildProcessUniqueID() const override;
private:
// The type of this worker task. Can be one of DEDICATED_WORKER, SHARED_WORKER
// or SERVICE_WORKER.
const Task::Type task_type_;
// The unique ID of the RenderProcessHost.
const int render_process_id_;
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerTask);
};
} // namespace task_manager
#endif // CHROME_BROWSER_TASK_MANAGER_PROVIDERS_SERVICE_WORKER_TASK_H_
#endif // CHROME_BROWSER_TASK_MANAGER_PROVIDERS_WORKER_TASK_H_
......@@ -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 "chrome/browser/task_manager/providers/service_worker_task_provider.h"
#include "chrome/browser/task_manager/providers/worker_task_provider.h"
#include "base/stl_util.h"
#include "chrome/browser/browser_process.h"
......@@ -15,15 +15,15 @@ using content::BrowserThread;
namespace task_manager {
ServiceWorkerTaskProvider::ServiceWorkerTaskProvider() = default;
ServiceWorkerTaskProvider::~ServiceWorkerTaskProvider() = default;
WorkerTaskProvider::WorkerTaskProvider() = default;
Task* ServiceWorkerTaskProvider::GetTaskOfUrlRequest(int child_id,
int route_id) {
WorkerTaskProvider::~WorkerTaskProvider() = default;
Task* WorkerTaskProvider::GetTaskOfUrlRequest(int child_id, int route_id) {
return nullptr;
}
void ServiceWorkerTaskProvider::OnProfileAdded(Profile* profile) {
void WorkerTaskProvider::OnProfileAdded(Profile* profile) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
observed_profiles_.Add(profile);
......@@ -34,14 +34,13 @@ void ServiceWorkerTaskProvider::OnProfileAdded(Profile* profile) {
scoped_context_observer_.Add(context);
}
void ServiceWorkerTaskProvider::OnOffTheRecordProfileCreated(
Profile* off_the_record) {
void WorkerTaskProvider::OnOffTheRecordProfileCreated(Profile* off_the_record) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
OnProfileAdded(off_the_record);
}
void ServiceWorkerTaskProvider::OnProfileWillBeDestroyed(Profile* profile) {
void WorkerTaskProvider::OnProfileWillBeDestroyed(Profile* profile) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
observed_profiles_.Remove(profile);
......@@ -52,7 +51,7 @@ void ServiceWorkerTaskProvider::OnProfileWillBeDestroyed(Profile* profile) {
scoped_context_observer_.Remove(context);
}
void ServiceWorkerTaskProvider::OnVersionStartedRunning(
void WorkerTaskProvider::OnVersionStartedRunning(
content::ServiceWorkerContext* context,
int64_t version_id,
const content::ServiceWorkerRunningInfo& running_info) {
......@@ -61,7 +60,7 @@ void ServiceWorkerTaskProvider::OnVersionStartedRunning(
CreateTask(context, version_id, running_info);
}
void ServiceWorkerTaskProvider::OnVersionStoppedRunning(
void WorkerTaskProvider::OnVersionStoppedRunning(
content::ServiceWorkerContext* context,
int64_t version_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
......@@ -69,7 +68,7 @@ void ServiceWorkerTaskProvider::OnVersionStoppedRunning(
DeleteTask(context, version_id);
}
void ServiceWorkerTaskProvider::StartUpdating() {
void WorkerTaskProvider::StartUpdating() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
ProfileManager* profile_manager = g_browser_process->profile_manager();
......@@ -88,7 +87,7 @@ void ServiceWorkerTaskProvider::StartUpdating() {
}
}
void ServiceWorkerTaskProvider::StopUpdating() {
void WorkerTaskProvider::StopUpdating() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Stop observing profile creation and destruction.
......@@ -102,7 +101,7 @@ void ServiceWorkerTaskProvider::StopUpdating() {
service_worker_task_map_.clear();
}
void ServiceWorkerTaskProvider::CreateTasksForProfile(Profile* profile) {
void WorkerTaskProvider::CreateTasksForProfile(Profile* profile) {
content::ServiceWorkerContext* context =
content::BrowserContext::GetDefaultStoragePartition(profile)
->GetServiceWorkerContext();
......@@ -118,7 +117,7 @@ void ServiceWorkerTaskProvider::CreateTasksForProfile(Profile* profile) {
}
}
void ServiceWorkerTaskProvider::CreateTask(
void WorkerTaskProvider::CreateTask(
content::ServiceWorkerContext* context,
int64_t version_id,
const content::ServiceWorkerRunningInfo& running_info) {
......@@ -130,17 +129,16 @@ void ServiceWorkerTaskProvider::CreateTask(
const int render_process_id = running_info.render_process_id;
auto* host = content::RenderProcessHost::FromID(render_process_id);
auto result = service_worker_task_map_.emplace(
key, std::make_unique<ServiceWorkerTask>(host->GetProcess().Handle(),
render_process_id,
running_info.script_url));
key, std::make_unique<WorkerTask>(
host->GetProcess().Handle(), running_info.script_url,
Task::Type::SERVICE_WORKER, render_process_id));
DCHECK(result.second);
NotifyObserverTaskAdded(result.first->second.get());
}
void ServiceWorkerTaskProvider::DeleteTask(
content::ServiceWorkerContext* context,
int version_id) {
void WorkerTaskProvider::DeleteTask(content::ServiceWorkerContext* context,
int version_id) {
const ServiceWorkerTaskKey key(context, version_id);
auto it = service_worker_task_map_.find(key);
DCHECK(it != service_worker_task_map_.end());
......
......@@ -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 CHROME_BROWSER_TASK_MANAGER_PROVIDERS_SERVICE_WORKER_TASK_PROVIDER_H_
#define CHROME_BROWSER_TASK_MANAGER_PROVIDERS_SERVICE_WORKER_TASK_PROVIDER_H_
#ifndef CHROME_BROWSER_TASK_MANAGER_PROVIDERS_WORKER_TASK_PROVIDER_H_
#define CHROME_BROWSER_TASK_MANAGER_PROVIDERS_WORKER_TASK_PROVIDER_H_
#include <map>
#include <memory>
......@@ -14,24 +14,32 @@
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_manager_observer.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "chrome/browser/task_manager/providers/service_worker_task.h"
#include "chrome/browser/task_manager/providers/task_provider.h"
#include "chrome/browser/task_manager/providers/worker_task.h"
#include "content/public/browser/service_worker_context.h"
#include "content/public/browser/service_worker_context_observer.h"
namespace task_manager {
// This provides tasks that describe running service workers
// (https://w3c.github.io/ServiceWorker/). It adds itself as an observer of
// ServiceWorkerContext to listen to the running status changes of the service
// workers for the creation and destruction of the tasks.
class ServiceWorkerTaskProvider : public TaskProvider,
public ProfileManagerObserver,
public ProfileObserver,
public content::ServiceWorkerContextObserver {
// This class provides tasks that describe running workers of all types
// (dedicated, shared or service workers).
//
// See https://w3c.github.io/workers/ or https://w3c.github.io/ServiceWorker/
// for more details.
//
// TODO(https://crbug.com/1041093): Add support for dedicated workers and shared
// workers.
class WorkerTaskProvider : public TaskProvider,
public ProfileManagerObserver,
public ProfileObserver,
public content::ServiceWorkerContextObserver {
public:
ServiceWorkerTaskProvider();
~ServiceWorkerTaskProvider() override;
WorkerTaskProvider();
~WorkerTaskProvider() override;
// Non-copyable.
WorkerTaskProvider(const WorkerTaskProvider& other) = delete;
WorkerTaskProvider& operator=(const WorkerTaskProvider& other) = delete;
// task_manager::TaskProvider:
Task* GetTaskOfUrlRequest(int child_id, int route_id) override;
......@@ -56,17 +64,17 @@ class ServiceWorkerTaskProvider : public TaskProvider,
void StartUpdating() override;
void StopUpdating() override;
// Creates ServiceWorkerTasks for the given |profile| and notifies the
// observer of their additions.
// Creates WorkerTasks for the given |profile| and notifies the observer of
// their additions.
void CreateTasksForProfile(Profile* profile);
// Creates a ServiceWorkerTask from the given |running_info| and notifies the
// Creates a WorkerTask from the given |running_info| and notifies the
// observer of its addition.
void CreateTask(content::ServiceWorkerContext* context,
int64_t version_id,
const content::ServiceWorkerRunningInfo& running_info);
// Deletes a ServiceWorkerTask with the |version_id| after notifying the
// Deletes a WorkerTask associated with |version_id| after notifying the
// observer of its deletion.
void DeleteTask(content::ServiceWorkerContext* context, int version_id);
......@@ -78,16 +86,14 @@ class ServiceWorkerTaskProvider : public TaskProvider,
using ServiceWorkerTaskKey =
std::pair<content::ServiceWorkerContext*, int64_t /*version_id*/>;
using ServiceWorkerTaskMap =
std::map<ServiceWorkerTaskKey, std::unique_ptr<ServiceWorkerTask>>;
std::map<ServiceWorkerTaskKey, std::unique_ptr<WorkerTask>>;
ServiceWorkerTaskMap service_worker_task_map_;
ScopedObserver<content::ServiceWorkerContext,
content::ServiceWorkerContextObserver>
scoped_context_observer_{this};
DISALLOW_COPY_AND_ASSIGN(ServiceWorkerTaskProvider);
};
} // namespace task_manager
#endif // CHROME_BROWSER_TASK_MANAGER_PROVIDERS_SERVICE_WORKER_TASK_PROVIDER_H_
#endif // CHROME_BROWSER_TASK_MANAGER_PROVIDERS_WORKER_TASK_PROVIDER_H_
......@@ -12,8 +12,8 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/task_manager/providers/service_worker_task_provider.h"
#include "chrome/browser/task_manager/providers/task_provider_observer.h"
#include "chrome/browser/task_manager/providers/worker_task_provider.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
......@@ -62,19 +62,19 @@ int GetChildProcessID(Browser* browser) {
} // namespace
class ServiceWorkerTaskProviderBrowserTest : public InProcessBrowserTest,
public TaskProviderObserver {
class WorkerTaskProviderBrowserTest : public InProcessBrowserTest,
public TaskProviderObserver {
public:
ServiceWorkerTaskProviderBrowserTest() = default;
WorkerTaskProviderBrowserTest() = default;
~ServiceWorkerTaskProviderBrowserTest() override = default;
~WorkerTaskProviderBrowserTest() override = default;
void SetUpOnMainThread() override {
ASSERT_TRUE(embedded_test_server()->Start());
}
void StartUpdating() {
task_provider_ = std::make_unique<ServiceWorkerTaskProvider>();
task_provider_ = std::make_unique<WorkerTaskProvider>();
task_provider_->SetObserver(this);
}
......@@ -153,7 +153,7 @@ class ServiceWorkerTaskProviderBrowserTest : public InProcessBrowserTest,
}
private:
std::unique_ptr<ServiceWorkerTaskProvider> task_provider_;
std::unique_ptr<WorkerTaskProvider> task_provider_;
// Tasks created by |task_provider_|.
std::vector<Task*> tasks_;
......@@ -163,11 +163,11 @@ class ServiceWorkerTaskProviderBrowserTest : public InProcessBrowserTest,
uint64_t expected_task_count_ = 0;
};
// Make sure that the ServiceWorkerTaskProvider can create/delete
// a ServiceWorkerTask based on the actual service worker status, and the task
// Make sure that the WorkerTaskProvider can create/delete a WorkerTask of type
// SERVICE_WORKER based on the actual service worker status, and the task
// representing the service worker has the expected properties.
IN_PROC_BROWSER_TEST_F(ServiceWorkerTaskProviderBrowserTest,
CreateTasksForSingleProfile) {
IN_PROC_BROWSER_TEST_F(WorkerTaskProviderBrowserTest,
CreateServiceWorkerTasksForSingleProfile) {
StartUpdating();
EXPECT_TRUE(tasks().empty());
......@@ -196,10 +196,10 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerTaskProviderBrowserTest,
StopUpdating();
}
// If the profile is off the record, the ServiceWorkerTaskProvider can still
// grab the correct information and create/delete the task.
IN_PROC_BROWSER_TEST_F(ServiceWorkerTaskProviderBrowserTest,
CreateTasksForOffTheRecordProfile) {
// If the profile is off the record, the WorkerTaskProvider can still grab the
// correct information and create/delete the task.
IN_PROC_BROWSER_TEST_F(WorkerTaskProviderBrowserTest,
CreateServiceWorkerTasksForOffTheRecordProfile) {
StartUpdating();
EXPECT_TRUE(tasks().empty());
......@@ -235,8 +235,8 @@ IN_PROC_BROWSER_TEST_F(ServiceWorkerTaskProviderBrowserTest,
}
// If the profile are created dynamically and there is more than one profile
// simultaneously, the ServiceWorkerTaskProvider can still works.
IN_PROC_BROWSER_TEST_F(ServiceWorkerTaskProviderBrowserTest,
// simultaneously, the WorkerTaskProvider can still works.
IN_PROC_BROWSER_TEST_F(WorkerTaskProviderBrowserTest,
CreateTasksForMultiProfiles) {
StartUpdating();
......
......@@ -21,8 +21,8 @@
#include "chrome/browser/task_manager/providers/child_process_task_provider.h"
#include "chrome/browser/task_manager/providers/fallback_task_provider.h"
#include "chrome/browser/task_manager/providers/render_process_host_task_provider.h"
#include "chrome/browser/task_manager/providers/service_worker_task_provider.h"
#include "chrome/browser/task_manager/providers/web_contents/web_contents_task_provider.h"
#include "chrome/browser/task_manager/providers/worker_task_provider.h"
#include "chrome/browser/task_manager/sampling/shared_sampler.h"
#include "chrome/common/chrome_switches.h"
#include "components/nacl/common/buildflags.h"
......@@ -87,7 +87,7 @@ TaskManagerImpl::TaskManagerImpl()
task_providers_.emplace_back(new BrowserProcessTaskProvider());
task_providers_.emplace_back(new ChildProcessTaskProvider());
task_providers_.emplace_back(new ServiceWorkerTaskProvider());
task_providers_.emplace_back(new WorkerTaskProvider());
if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kTaskManagerShowExtraRenderers)) {
task_providers_.emplace_back(new WebContentsTaskProvider());
......
......@@ -1225,12 +1225,12 @@ if (!is_android) {
"../browser/tab_contents/view_source_browsertest.cc",
"../browser/task_manager/mock_web_contents_task_manager.cc",
"../browser/task_manager/mock_web_contents_task_manager.h",
"../browser/task_manager/providers/service_worker_task_provider_browsertest.cc",
"../browser/task_manager/providers/web_contents/background_contents_tag_browsertest.cc",
"../browser/task_manager/providers/web_contents/devtools_tag_browsertest.cc",
"../browser/task_manager/providers/web_contents/extension_tag_browsertest.cc",
"../browser/task_manager/providers/web_contents/subframe_task_browsertest.cc",
"../browser/task_manager/providers/web_contents/tab_contents_tag_browsertest.cc",
"../browser/task_manager/providers/worker_task_provider_browsertest.cc",
"../browser/task_manager/task_manager_browsertest.cc",
"../browser/task_manager/task_manager_browsertest_util.cc",
"../browser/task_manager/task_manager_browsertest_util.h",
......
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