Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Unified Diff: content/browser/devtools/protocol/service_worker_handler.cc

Issue 1029553002: [DevTools] Introduce Unregister/Start/Stop/Inspect buttons to ServiceWorkersView [1/2 chromium] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix indent Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/devtools/protocol/service_worker_handler.cc
diff --git a/content/browser/devtools/protocol/service_worker_handler.cc b/content/browser/devtools/protocol/service_worker_handler.cc
index 788bcb0c6d8c57673efed5154944c86d7f8b4bcd..c2736017a73ec2c53234656a586a7e019835a163 100644
--- a/content/browser/devtools/protocol/service_worker_handler.cc
+++ b/content/browser/devtools/protocol/service_worker_handler.cc
@@ -12,6 +12,7 @@
#include "content/browser/frame_host/frame_tree.h"
#include "content/browser/frame_host/frame_tree_node.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
+#include "content/browser/service_worker/service_worker_context_core.h"
#include "content/browser/service_worker/service_worker_context_watcher.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/service_worker/service_worker_version.h"
@@ -32,19 +33,14 @@ namespace content {
namespace devtools {
namespace service_worker {
-namespace {
+using Response = DevToolsProtocolClient::Response;
-const char kServiceWorkerVersionRunningStatusStopped[] = "stopped";
-const char kServiceWorkerVersionRunningStatusStarting[] = "starting";
-const char kServiceWorkerVersionRunningStatusRunning[] = "running";
-const char kServiceWorkerVersionRunningStatusStopping[] = "stopping";
+namespace {
-const char kServiceWorkerVersionStatusNew[] = "new";
-const char kServiceWorkerVersionStatusInstalling[] = "installing";
-const char kServiceWorkerVersionStatusInstalled[] = "installed";
-const char kServiceWorkerVersionStatusActivating[] = "activating";
-const char kServiceWorkerVersionStatusActivated[] = "activated";
-const char kServiceWorkerVersionStatusRedundant[] = "redundant";
+void ResultNoOp(bool success) {
+}
+void StatusNoOp(ServiceWorkerStatusCode status) {
+}
const std::string GetVersionRunningStatusString(
content::ServiceWorkerVersion::RunningStatus running_status) {
@@ -145,9 +141,43 @@ bool CollectURLs(std::set<GURL>* urls, FrameTreeNode* tree_node) {
return false;
}
-} // namespace
+void StopServiceWorkerOnIO(scoped_refptr<ServiceWorkerContextWrapper> context,
+ int64 version_id) {
+ ServiceWorkerContextCore* context_core = context->context();
+ if (!context_core)
+ return;
+ if (content::ServiceWorkerVersion* version =
+ context_core->GetLiveVersion(version_id)) {
+ version->StopWorker(base::Bind(&StatusNoOp));
+ }
+}
-using Response = DevToolsProtocolClient::Response;
+void GetDevToolsRouteInfoOnIO(
+ scoped_refptr<ServiceWorkerContextWrapper> context,
+ int64 version_id,
+ const base::Callback<void(int, int)>& callback) {
+ ServiceWorkerContextCore* context_core = context->context();
+ if (!context_core)
+ return;
+ if (content::ServiceWorkerVersion* version =
+ context_core->GetLiveVersion(version_id)) {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(
+ callback, version->embedded_worker()->process_id(),
+ version->embedded_worker()->worker_devtools_agent_route_id()));
+ }
+}
+
+Response CreateContextErrorResoponse() {
+ return Response::InternalError("Could not connect to the context");
+}
+
+Response CreateInvalidVersionIdErrorResoponse() {
+ return Response::InternalError("Invalid version ID");
+}
+
+} // namespace
ServiceWorkerHandler::ServiceWorkerHandler()
: enabled_(false), weak_factory_(this) {
@@ -260,6 +290,64 @@ Response ServiceWorkerHandler::Stop(
return Response::OK();
}
+Response ServiceWorkerHandler::Unregister(const std::string& scope_url) {
+ if (!enabled_)
+ return Response::OK();
+ if (!context_)
+ return CreateContextErrorResoponse();
+ context_->UnregisterServiceWorker(GURL(scope_url), base::Bind(&ResultNoOp));
+ return Response::OK();
+}
+
+Response ServiceWorkerHandler::StartWorker(const std::string& scope_url) {
+ if (!enabled_)
+ return Response::OK();
+ if (!context_)
+ return CreateContextErrorResoponse();
+ context_->StartServiceWorker(GURL(scope_url), base::Bind(&StatusNoOp));
+ return Response::OK();
+}
+
+Response ServiceWorkerHandler::StopWorker(const std::string& version_id) {
+ if (!enabled_)
+ return Response::OK();
+ if (!context_)
+ return CreateContextErrorResoponse();
+ int64 id = 0;
+ if (!base::StringToInt64(version_id, &id))
+ return CreateInvalidVersionIdErrorResoponse();
+ BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
+ base::Bind(&StopServiceWorkerOnIO, context_, id));
+ return Response::OK();
+}
+
+Response ServiceWorkerHandler::InspectWorker(const std::string& version_id) {
+ if (!enabled_)
+ return Response::OK();
+ if (!context_)
+ return CreateContextErrorResoponse();
+
+ int64 id = 0;
+ if (!base::StringToInt64(version_id, &id))
+ return CreateInvalidVersionIdErrorResoponse();
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&GetDevToolsRouteInfoOnIO, context_, id,
+ base::Bind(&ServiceWorkerHandler::OpenNewDevToolsWindow,
+ weak_factory_.GetWeakPtr())));
+ return Response::OK();
+}
+
+void ServiceWorkerHandler::OpenNewDevToolsWindow(int process_id,
+ int devtools_agent_route_id) {
+ scoped_refptr<DevToolsAgentHostImpl> agent_host(
+ ServiceWorkerDevToolsManager::GetInstance()
+ ->GetDevToolsAgentHostForWorker(process_id, devtools_agent_route_id));
+ if (!agent_host.get())
+ return;
+ agent_host->Inspect(render_frame_host_->GetProcess()->GetBrowserContext());
+}
+
void ServiceWorkerHandler::OnWorkerRegistrationUpdated(
const std::vector<ServiceWorkerRegistrationInfo>& registrations) {
std::vector<scoped_refptr<ServiceWorkerRegistration>> registration_values;

Powered by Google App Engine
This is Rietveld 408576698