Chromium Code Reviews| 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..037a0105437e4b340a4f0b8b7948a19d9810454b 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,17 @@ 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) { |
|
kinuko
2014/04/01 14:40:49
Shouldn't we check if registration->active_version
jkarlin
2014/04/01 15:06:06
Done.
|
| + registration->active_version()->DispatchSyncEvent(base::Bind( |
| + &ServiceWorkerInternalsUI::OperationProxy::OperationComplete, this)); |
| + return; |
| + } |
| + |
| + OperationComplete(status); |
| +} |
| + |
| } // namespace content |