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

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

Issue 998173002: Revise ServiceWorker DevTools protocols. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ServiceWorkerContextWatcher 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 68f05c08f01e0b08e914169631b867db7c22cdd6..5daf6628abd62e7032a7d5864f4e29366f65e903 100644
--- a/content/browser/devtools/protocol/service_worker_handler.cc
+++ b/content/browser/devtools/protocol/service_worker_handler.cc
@@ -5,11 +5,13 @@
#include "content/browser/devtools/protocol/service_worker_handler.h"
#include "base/bind.h"
+#include "base/containers/scoped_ptr_hash_map.h"
#include "base/strings/string_number_conversions.h"
#include "content/browser/devtools/service_worker_devtools_agent_host.h"
#include "content/browser/devtools/service_worker_devtools_manager.h"
-#include "content/browser/service_worker/service_worker_context_observer.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"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/devtools_agent_host.h"
@@ -83,22 +85,8 @@ scoped_refptr<ServiceWorkerRegistration> CreateRegistrationDictionaryValue(
ServiceWorkerRegistration::Create()
->set_registration_id(
base::Int64ToString(registration_info.registration_id))
- ->set_scope_url(registration_info.pattern.spec()));
- if (registration_info.active_version.version_id !=
- kInvalidServiceWorkerVersionId) {
- registration->set_active_version(
- CreateVersionDictionaryValue(registration_info.active_version));
- }
- if (registration_info.waiting_version.version_id !=
- kInvalidServiceWorkerVersionId) {
- registration->set_waiting_version(
- CreateVersionDictionaryValue(registration_info.waiting_version));
- }
- if (registration_info.installing_version.version_id !=
- kInvalidServiceWorkerVersionId) {
- registration->set_installing_version(
kinuko 2015/03/13 09:09:21 Ok so we assume version.state info should be enoug
horo 2015/03/13 10:03:49 Yes.
- CreateVersionDictionaryValue(registration_info.installing_version));
- }
+ ->set_scope_url(registration_info.pattern.spec())
+ ->set_is_deleted(registration_info.is_deleted));
return registration;
}
@@ -106,157 +94,6 @@ scoped_refptr<ServiceWorkerRegistration> CreateRegistrationDictionaryValue(
using Response = DevToolsProtocolClient::Response;
-class ServiceWorkerHandler::ContextObserver
- : public ServiceWorkerContextObserver,
- public base::RefCountedThreadSafe<ContextObserver> {
- public:
- ContextObserver(scoped_refptr<ServiceWorkerContextWrapper> context,
- base::WeakPtr<ServiceWorkerHandler> handler);
- void Start();
- void Stop();
-
- private:
- friend class base::RefCountedThreadSafe<ContextObserver>;
- ~ContextObserver() override;
- void GetStoredRegistrationsOnIOThread();
- void OnStoredRegistrationsOnIOThread(
- const std::vector<ServiceWorkerRegistrationInfo>& registrations);
- void StopOnIOThread();
-
- void OnVersionUpdated(int64 version_id);
- void OnRegistrationUpdated(int64 registration_id);
-
- // ServiceWorkerContextObserver implements
- void OnRunningStateChanged(int64 version_id) override;
- void OnVersionStateChanged(int64 version_id) override;
- void OnRegistrationStored(int64 registration_id,
- const GURL& pattern) override;
- void OnRegistrationDeleted(int64 registration_id,
- const GURL& pattern) override;
-
- scoped_refptr<ServiceWorkerContextWrapper> context_;
- base::WeakPtr<ServiceWorkerHandler> handler_;
-};
-
-ServiceWorkerHandler::ContextObserver::ContextObserver(
- scoped_refptr<ServiceWorkerContextWrapper> context,
- base::WeakPtr<ServiceWorkerHandler> handler)
- : context_(context), handler_(handler) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
-}
-
-void ServiceWorkerHandler::ContextObserver::Start() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
- base::Bind(&ServiceWorkerHandler::ContextObserver::
- GetStoredRegistrationsOnIOThread,
- this));
-}
-
-void ServiceWorkerHandler::ContextObserver::Stop() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&ServiceWorkerHandler::ContextObserver::StopOnIOThread, this));
-}
-
-void ServiceWorkerHandler::ContextObserver::GetStoredRegistrationsOnIOThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- context_->context()->storage()->GetAllRegistrations(base::Bind(
- &ServiceWorkerHandler::ContextObserver::OnStoredRegistrationsOnIOThread,
- this));
-}
-
-void ServiceWorkerHandler::ContextObserver::OnStoredRegistrationsOnIOThread(
- const std::vector<ServiceWorkerRegistrationInfo>& registrations) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- context_->AddObserver(this);
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&ServiceWorkerHandler::OnWorkerRegistrationUpdated, handler_,
- registrations));
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&ServiceWorkerHandler::OnWorkerRegistrationUpdated, handler_,
- context_->context()->GetAllLiveRegistrationInfo()));
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&ServiceWorkerHandler::OnWorkerVersionUpdated, handler_,
- context_->context()->GetAllLiveVersionInfo()));
-}
-
-void ServiceWorkerHandler::ContextObserver::StopOnIOThread() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- context_->RemoveObserver(this);
-}
-
-ServiceWorkerHandler::ContextObserver::~ContextObserver() {
-}
-
-void ServiceWorkerHandler::ContextObserver::OnVersionUpdated(int64 version_id) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- content::ServiceWorkerVersion* version =
- context_->context()->GetLiveVersion(version_id);
- if (!version)
- return;
- OnRegistrationUpdated(version->registration_id());
- std::vector<ServiceWorkerVersionInfo> versions;
- versions.push_back(version->GetInfo());
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&ServiceWorkerHandler::OnWorkerVersionUpdated, handler_,
- versions));
-}
-
-void ServiceWorkerHandler::ContextObserver::OnRegistrationUpdated(
- int64 registration_id) {
- content::ServiceWorkerRegistration* registration =
- context_->context()->GetLiveRegistration(registration_id);
- if (!registration)
- return;
- std::vector<ServiceWorkerRegistrationInfo> registrations;
- registrations.push_back(registration->GetInfo());
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&ServiceWorkerHandler::OnWorkerRegistrationUpdated, handler_,
- registrations));
-}
-
-void ServiceWorkerHandler::ContextObserver::OnRunningStateChanged(
- int64 version_id) {
- OnVersionUpdated(version_id);
-}
-
-void ServiceWorkerHandler::ContextObserver::OnVersionStateChanged(
- int64 version_id) {
- OnVersionUpdated(version_id);
-}
-
-void ServiceWorkerHandler::ContextObserver::OnRegistrationStored(
- int64 registration_id,
- const GURL& pattern) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- content::ServiceWorkerRegistration* registration =
- context_->context()->GetLiveRegistration(registration_id);
- DCHECK(registration);
- std::vector<ServiceWorkerRegistrationInfo> registrations;
- registrations.push_back(registration->GetInfo());
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&ServiceWorkerHandler::OnWorkerRegistrationUpdated, handler_,
- registrations));
-}
-
-void ServiceWorkerHandler::ContextObserver::OnRegistrationDeleted(
- int64 registration_id,
- const GURL& pattern) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(&ServiceWorkerHandler::OnWorkerRegistrationDeleted, handler_,
- registration_id));
-}
-
ServiceWorkerHandler::ServiceWorkerHandler()
: enabled_(false), weak_factory_(this) {
}
@@ -325,8 +162,12 @@ Response ServiceWorkerHandler::Enable() {
for (auto host : agent_hosts)
WorkerReadyForInspection(host.get());
- context_observer_ = new ContextObserver(context_, weak_factory_.GetWeakPtr());
- context_observer_->Start();
+ context_watcher_ = new ServiceWorkerContextWatcher(
+ context_, base::Bind(&ServiceWorkerHandler::OnWorkerRegistrationUpdated,
+ weak_factory_.GetWeakPtr()),
+ base::Bind(&ServiceWorkerHandler::OnWorkerVersionUpdated,
+ weak_factory_.GetWeakPtr()));
+ context_watcher_->Start();
return Response::OK();
}
@@ -339,9 +180,9 @@ Response ServiceWorkerHandler::Disable() {
for (const auto& pair : attached_hosts_)
pair.second->DetachClient();
attached_hosts_.clear();
- DCHECK(context_observer_);
- context_observer_->Stop();
- context_observer_ = nullptr;
+ DCHECK(context_watcher_);
+ context_watcher_->Stop();
+ context_watcher_ = nullptr;
return Response::OK();
}
@@ -386,12 +227,6 @@ void ServiceWorkerHandler::OnWorkerVersionUpdated(
WorkerVersionUpdatedParams::Create()->set_versions(version_values));
}
-void ServiceWorkerHandler::OnWorkerRegistrationDeleted(int64 registration_id) {
- client_->WorkerRegistrationDeleted(
- WorkerRegistrationDeletedParams::Create()->set_registration_id(
- base::Int64ToString(registration_id)));
-}
-
void ServiceWorkerHandler::DispatchProtocolMessage(
DevToolsAgentHost* host,
const std::string& message) {

Powered by Google App Engine
This is Rietveld 408576698