Index: content/browser/service_worker/service_worker_internals_ui.cc |
diff --git a/content/browser/service_worker/service_worker_internals_ui.cc b/content/browser/service_worker/service_worker_internals_ui.cc |
index 18fef0805ab1afe9e36025a86df02b2beb3760d3..1f6f55a40fa86b0638cf2ffd10489cfb4e1f5300 100644 |
--- a/content/browser/service_worker/service_worker_internals_ui.cc |
+++ b/content/browser/service_worker/service_worker_internals_ui.cc |
@@ -49,6 +49,9 @@ class ServiceWorkerInternalsUI::OperationProxy |
const GURL& scope); |
void StopWorkerOnIOThread(scoped_refptr<ServiceWorkerContextWrapper> context, |
const GURL& scope); |
+ void DispatchSyncEventToWorkerOnIOThread( |
+ scoped_refptr<ServiceWorkerContextWrapper> context, |
+ const GURL& scope); |
private: |
friend class base::RefCountedThreadSafe<OperationProxy>; |
@@ -67,6 +70,10 @@ class ServiceWorkerInternalsUI::OperationProxy |
ServiceWorkerStatusCode status, |
const scoped_refptr<ServiceWorkerRegistration>& registration); |
+ void DispatchSyncEventToActiveWorker( |
+ ServiceWorkerStatusCode status, |
+ const scoped_refptr<ServiceWorkerRegistration>& registration); |
+ |
WeakPtr<ServiceWorkerInternalsUI> internals_; |
scoped_ptr<ListValue> original_args_; |
}; |
@@ -103,6 +110,10 @@ ServiceWorkerInternalsUI::ServiceWorkerInternalsUI(WebUI* web_ui) |
"unregister", |
base::Bind(&ServiceWorkerInternalsUI::Unregister, |
base::Unretained(this))); |
+ web_ui->RegisterMessageCallback( |
+ "sync", |
+ base::Bind(&ServiceWorkerInternalsUI::DispatchSyncEventToWorker, |
+ base::Unretained(this))); |
} |
ServiceWorkerInternalsUI::~ServiceWorkerInternalsUI() {} |
@@ -178,6 +189,26 @@ bool ServiceWorkerInternalsUI::GetRegistrationInfo( |
return true; |
} |
+void ServiceWorkerInternalsUI::DispatchSyncEventToWorker( |
+ const ListValue* args) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ base::FilePath partition_path; |
+ GURL scope; |
+ scoped_refptr<ServiceWorkerContextWrapper> context; |
+ if (!GetRegistrationInfo(args, &partition_path, &scope, &context)) |
+ return; |
+ |
+ scoped_ptr<ListValue> args_copy(args->DeepCopy()); |
+ BrowserThread::PostTask( |
+ BrowserThread::IO, |
+ FROM_HERE, |
+ base::Bind(&ServiceWorkerInternalsUI::OperationProxy:: |
+ DispatchSyncEventToWorkerOnIOThread, |
+ new OperationProxy(AsWeakPtr(), args_copy.Pass()), |
+ context, |
+ scope)); |
+} |
+ |
void ServiceWorkerInternalsUI::Unregister(const ListValue* args) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
base::FilePath partition_path; |
@@ -281,6 +312,18 @@ void ServiceWorkerInternalsUI::OperationProxy::StopWorkerOnIOThread( |
this)); |
} |
+void |
+ServiceWorkerInternalsUI::OperationProxy::DispatchSyncEventToWorkerOnIOThread( |
+ scoped_refptr<ServiceWorkerContextWrapper> context, |
+ const GURL& scope) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ context->context()->storage()->FindRegistrationForPattern( |
+ scope, |
+ base::Bind(&ServiceWorkerInternalsUI::OperationProxy:: |
+ DispatchSyncEventToActiveWorker, |
+ this)); |
+} |
+ |
namespace { |
void UpdateVersionInfo(const ServiceWorkerVersionInfo& version, |
DictionaryValue* info) { |
@@ -420,4 +463,19 @@ void ServiceWorkerInternalsUI::OperationProxy::StopActiveWorker( |
OperationComplete(status); |
} |
+void ServiceWorkerInternalsUI::OperationProxy::DispatchSyncEventToActiveWorker( |
+ ServiceWorkerStatusCode status, |
+ const scoped_refptr<ServiceWorkerRegistration>& registration) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
+ if (status == SERVICE_WORKER_OK && registration->active_version() && |
+ registration->active_version()->status() == |
+ ServiceWorkerVersion::ACTIVE) { |
+ registration->active_version()->DispatchSyncEvent(base::Bind( |
+ &ServiceWorkerInternalsUI::OperationProxy::OperationComplete, this)); |
+ return; |
+ } |
+ |
+ OperationComplete(SERVICE_WORKER_ERROR_FAILED); |
+} |
+ |
} // namespace content |