| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/service_worker/service_worker_internals_ui.h" | 5 #include "content/browser/service_worker/service_worker_internals_ui.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 const base::FilePath& context_path); | 50 const base::FilePath& context_path); |
| 51 void UnregisterOnIOThread(scoped_refptr<ServiceWorkerContextWrapper> context, | 51 void UnregisterOnIOThread(scoped_refptr<ServiceWorkerContextWrapper> context, |
| 52 const GURL& scope); | 52 const GURL& scope); |
| 53 void StartWorkerOnIOThread(scoped_refptr<ServiceWorkerContextWrapper> context, | 53 void StartWorkerOnIOThread(scoped_refptr<ServiceWorkerContextWrapper> context, |
| 54 const GURL& scope); | 54 const GURL& scope); |
| 55 void StopWorkerOnIOThread(scoped_refptr<ServiceWorkerContextWrapper> context, | 55 void StopWorkerOnIOThread(scoped_refptr<ServiceWorkerContextWrapper> context, |
| 56 const GURL& scope); | 56 const GURL& scope); |
| 57 void DispatchSyncEventToWorkerOnIOThread( | 57 void DispatchSyncEventToWorkerOnIOThread( |
| 58 scoped_refptr<ServiceWorkerContextWrapper> context, | 58 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 59 const GURL& scope); | 59 const GURL& scope); |
| 60 void DispatchPushEventToWorkerOnIOThread( |
| 61 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 62 const GURL& scope); |
| 60 void InspectWorkerOnIOThread( | 63 void InspectWorkerOnIOThread( |
| 61 scoped_refptr<ServiceWorkerContextWrapper> context, | 64 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 62 const GURL& scope); | 65 const GURL& scope); |
| 63 | 66 |
| 64 private: | 67 private: |
| 65 friend class base::RefCountedThreadSafe<OperationProxy>; | 68 friend class base::RefCountedThreadSafe<OperationProxy>; |
| 66 ~OperationProxy() {} | 69 ~OperationProxy() {} |
| 67 void OnHaveRegistrations( | 70 void OnHaveRegistrations( |
| 68 int partition_id, | 71 int partition_id, |
| 69 const base::FilePath& context_path, | 72 const base::FilePath& context_path, |
| 70 const std::vector<ServiceWorkerRegistrationInfo>& registrations); | 73 const std::vector<ServiceWorkerRegistrationInfo>& registrations); |
| 71 | 74 |
| 72 void OperationComplete(ServiceWorkerStatusCode status); | 75 void OperationComplete(ServiceWorkerStatusCode status); |
| 73 | 76 |
| 74 void StartActiveWorker( | 77 void StartActiveWorker( |
| 75 ServiceWorkerStatusCode status, | 78 ServiceWorkerStatusCode status, |
| 76 const scoped_refptr<ServiceWorkerRegistration>& registration); | 79 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 77 | 80 |
| 78 void StopActiveWorker( | 81 void StopActiveWorker( |
| 79 ServiceWorkerStatusCode status, | 82 ServiceWorkerStatusCode status, |
| 80 const scoped_refptr<ServiceWorkerRegistration>& registration); | 83 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 81 | 84 |
| 82 void DispatchSyncEventToActiveWorker( | 85 void DispatchSyncEventToActiveWorker( |
| 83 ServiceWorkerStatusCode status, | 86 ServiceWorkerStatusCode status, |
| 84 const scoped_refptr<ServiceWorkerRegistration>& registration); | 87 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 85 | 88 |
| 89 void DispatchPushEventToActiveWorker( |
| 90 ServiceWorkerStatusCode status, |
| 91 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 92 |
| 86 void InspectActiveWorker( | 93 void InspectActiveWorker( |
| 87 const ServiceWorkerContextCore* const service_worker_context, | 94 const ServiceWorkerContextCore* const service_worker_context, |
| 88 ServiceWorkerStatusCode status, | 95 ServiceWorkerStatusCode status, |
| 89 const scoped_refptr<ServiceWorkerRegistration>& registration); | 96 const scoped_refptr<ServiceWorkerRegistration>& registration); |
| 90 | 97 |
| 91 void InspectWorkerOnUIThread( | 98 void InspectWorkerOnUIThread( |
| 92 const ServiceWorkerContextCore* const service_worker_context, | 99 const ServiceWorkerContextCore* const service_worker_context, |
| 93 int64 version_id); | 100 int64 version_id); |
| 94 | 101 |
| 95 WeakPtr<ServiceWorkerInternalsUI> internals_; | 102 WeakPtr<ServiceWorkerInternalsUI> internals_; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 base::Unretained(this))); | 224 base::Unretained(this))); |
| 218 web_ui->RegisterMessageCallback( | 225 web_ui->RegisterMessageCallback( |
| 219 "unregister", | 226 "unregister", |
| 220 base::Bind(&ServiceWorkerInternalsUI::Unregister, | 227 base::Bind(&ServiceWorkerInternalsUI::Unregister, |
| 221 base::Unretained(this))); | 228 base::Unretained(this))); |
| 222 web_ui->RegisterMessageCallback( | 229 web_ui->RegisterMessageCallback( |
| 223 "sync", | 230 "sync", |
| 224 base::Bind(&ServiceWorkerInternalsUI::DispatchSyncEventToWorker, | 231 base::Bind(&ServiceWorkerInternalsUI::DispatchSyncEventToWorker, |
| 225 base::Unretained(this))); | 232 base::Unretained(this))); |
| 226 web_ui->RegisterMessageCallback( | 233 web_ui->RegisterMessageCallback( |
| 234 "push", |
| 235 base::Bind(&ServiceWorkerInternalsUI::DispatchPushEventToWorker, |
| 236 base::Unretained(this))); |
| 237 web_ui->RegisterMessageCallback( |
| 227 "inspect", | 238 "inspect", |
| 228 base::Bind(&ServiceWorkerInternalsUI::InspectWorker, | 239 base::Bind(&ServiceWorkerInternalsUI::InspectWorker, |
| 229 base::Unretained(this))); | 240 base::Unretained(this))); |
| 230 } | 241 } |
| 231 | 242 |
| 232 ServiceWorkerInternalsUI::~ServiceWorkerInternalsUI() { | 243 ServiceWorkerInternalsUI::~ServiceWorkerInternalsUI() { |
| 233 BrowserContext* browser_context = | 244 BrowserContext* browser_context = |
| 234 web_ui()->GetWebContents()->GetBrowserContext(); | 245 web_ui()->GetWebContents()->GetBrowserContext(); |
| 235 // Safe to use base::Unretained(this) because | 246 // Safe to use base::Unretained(this) because |
| 236 // ForEachStoragePartition is synchronous. | 247 // ForEachStoragePartition is synchronous. |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 BrowserThread::PostTask( | 359 BrowserThread::PostTask( |
| 349 BrowserThread::IO, | 360 BrowserThread::IO, |
| 350 FROM_HERE, | 361 FROM_HERE, |
| 351 base::Bind(&ServiceWorkerInternalsUI::OperationProxy:: | 362 base::Bind(&ServiceWorkerInternalsUI::OperationProxy:: |
| 352 DispatchSyncEventToWorkerOnIOThread, | 363 DispatchSyncEventToWorkerOnIOThread, |
| 353 new OperationProxy(AsWeakPtr(), args_copy.Pass()), | 364 new OperationProxy(AsWeakPtr(), args_copy.Pass()), |
| 354 context, | 365 context, |
| 355 scope)); | 366 scope)); |
| 356 } | 367 } |
| 357 | 368 |
| 369 void ServiceWorkerInternalsUI::DispatchPushEventToWorker( |
| 370 const ListValue* args) { |
| 371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 372 base::FilePath partition_path; |
| 373 GURL scope; |
| 374 scoped_refptr<ServiceWorkerContextWrapper> context; |
| 375 if (!GetRegistrationInfo(args, &partition_path, &scope, &context)) |
| 376 return; |
| 377 |
| 378 scoped_ptr<ListValue> args_copy(args->DeepCopy()); |
| 379 BrowserThread::PostTask( |
| 380 BrowserThread::IO, |
| 381 FROM_HERE, |
| 382 base::Bind(&ServiceWorkerInternalsUI::OperationProxy:: |
| 383 DispatchPushEventToWorkerOnIOThread, |
| 384 new OperationProxy(AsWeakPtr(), args_copy.Pass()), |
| 385 context, |
| 386 scope)); |
| 387 } |
| 388 |
| 358 void ServiceWorkerInternalsUI::InspectWorker(const ListValue* args) { | 389 void ServiceWorkerInternalsUI::InspectWorker(const ListValue* args) { |
| 359 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 360 base::FilePath partition_path; | 391 base::FilePath partition_path; |
| 361 GURL scope; | 392 GURL scope; |
| 362 scoped_refptr<ServiceWorkerContextWrapper> context; | 393 scoped_refptr<ServiceWorkerContextWrapper> context; |
| 363 if (!GetRegistrationInfo(args, &partition_path, &scope, &context)) | 394 if (!GetRegistrationInfo(args, &partition_path, &scope, &context)) |
| 364 return; | 395 return; |
| 365 scoped_ptr<ListValue> args_copy(args->DeepCopy()); | 396 scoped_ptr<ListValue> args_copy(args->DeepCopy()); |
| 366 BrowserThread::PostTask( | 397 BrowserThread::PostTask( |
| 367 BrowserThread::IO, | 398 BrowserThread::IO, |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 scoped_refptr<ServiceWorkerContextWrapper> context, | 513 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 483 const GURL& scope) { | 514 const GURL& scope) { |
| 484 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 515 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 485 context->context()->storage()->FindRegistrationForPattern( | 516 context->context()->storage()->FindRegistrationForPattern( |
| 486 scope, | 517 scope, |
| 487 base::Bind(&ServiceWorkerInternalsUI::OperationProxy:: | 518 base::Bind(&ServiceWorkerInternalsUI::OperationProxy:: |
| 488 DispatchSyncEventToActiveWorker, | 519 DispatchSyncEventToActiveWorker, |
| 489 this)); | 520 this)); |
| 490 } | 521 } |
| 491 | 522 |
| 523 void |
| 524 ServiceWorkerInternalsUI::OperationProxy::DispatchPushEventToWorkerOnIOThread( |
| 525 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 526 const GURL& scope) { |
| 527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 528 context->context()->storage()->FindRegistrationForPattern( |
| 529 scope, |
| 530 base::Bind(&ServiceWorkerInternalsUI::OperationProxy:: |
| 531 DispatchPushEventToActiveWorker, |
| 532 this)); |
| 533 } |
| 534 |
| 492 void ServiceWorkerInternalsUI::OperationProxy::InspectWorkerOnIOThread( | 535 void ServiceWorkerInternalsUI::OperationProxy::InspectWorkerOnIOThread( |
| 493 scoped_refptr<ServiceWorkerContextWrapper> context, | 536 scoped_refptr<ServiceWorkerContextWrapper> context, |
| 494 const GURL& scope) { | 537 const GURL& scope) { |
| 495 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 538 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 496 context->context()->storage()->FindRegistrationForPattern( | 539 context->context()->storage()->FindRegistrationForPattern( |
| 497 scope, | 540 scope, |
| 498 base::Bind(&ServiceWorkerInternalsUI::OperationProxy::InspectActiveWorker, | 541 base::Bind(&ServiceWorkerInternalsUI::OperationProxy::InspectActiveWorker, |
| 499 this, | 542 this, |
| 500 context->context())); | 543 context->context())); |
| 501 } | 544 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 registration->active_version()->status() == | 693 registration->active_version()->status() == |
| 651 ServiceWorkerVersion::ACTIVE) { | 694 ServiceWorkerVersion::ACTIVE) { |
| 652 registration->active_version()->DispatchSyncEvent(base::Bind( | 695 registration->active_version()->DispatchSyncEvent(base::Bind( |
| 653 &ServiceWorkerInternalsUI::OperationProxy::OperationComplete, this)); | 696 &ServiceWorkerInternalsUI::OperationProxy::OperationComplete, this)); |
| 654 return; | 697 return; |
| 655 } | 698 } |
| 656 | 699 |
| 657 OperationComplete(SERVICE_WORKER_ERROR_FAILED); | 700 OperationComplete(SERVICE_WORKER_ERROR_FAILED); |
| 658 } | 701 } |
| 659 | 702 |
| 703 void ServiceWorkerInternalsUI::OperationProxy::DispatchPushEventToActiveWorker( |
| 704 ServiceWorkerStatusCode status, |
| 705 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| 706 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 707 if (status == SERVICE_WORKER_OK && registration->active_version() && |
| 708 registration->active_version()->status() == |
| 709 ServiceWorkerVersion::ACTIVE) { |
| 710 registration->active_version()->DispatchPushEvent(base::Bind( |
| 711 &ServiceWorkerInternalsUI::OperationProxy::OperationComplete, this)); |
| 712 return; |
| 713 } |
| 714 |
| 715 OperationComplete(SERVICE_WORKER_ERROR_FAILED); |
| 716 } |
| 717 |
| 660 void ServiceWorkerInternalsUI::OperationProxy::InspectActiveWorker( | 718 void ServiceWorkerInternalsUI::OperationProxy::InspectActiveWorker( |
| 661 const ServiceWorkerContextCore* const service_worker_context, | 719 const ServiceWorkerContextCore* const service_worker_context, |
| 662 ServiceWorkerStatusCode status, | 720 ServiceWorkerStatusCode status, |
| 663 const scoped_refptr<ServiceWorkerRegistration>& registration) { | 721 const scoped_refptr<ServiceWorkerRegistration>& registration) { |
| 664 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 722 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 665 if (status == SERVICE_WORKER_OK) { | 723 if (status == SERVICE_WORKER_OK) { |
| 666 BrowserThread::PostTask( | 724 BrowserThread::PostTask( |
| 667 BrowserThread::UI, | 725 BrowserThread::UI, |
| 668 FROM_HERE, | 726 FROM_HERE, |
| 669 base::Bind(&OperationProxy::InspectWorkerOnUIThread, | 727 base::Bind(&OperationProxy::InspectWorkerOnUIThread, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 689 DevToolsManagerImpl::GetInstance()->Inspect( | 747 DevToolsManagerImpl::GetInstance()->Inspect( |
| 690 internals_->web_ui()->GetWebContents()->GetBrowserContext(), | 748 internals_->web_ui()->GetWebContents()->GetBrowserContext(), |
| 691 agent_host.get()); | 749 agent_host.get()); |
| 692 OperationComplete(SERVICE_WORKER_OK); | 750 OperationComplete(SERVICE_WORKER_OK); |
| 693 return; | 751 return; |
| 694 } | 752 } |
| 695 OperationComplete(SERVICE_WORKER_ERROR_NOT_FOUND); | 753 OperationComplete(SERVICE_WORKER_ERROR_NOT_FOUND); |
| 696 } | 754 } |
| 697 | 755 |
| 698 } // namespace content | 756 } // namespace content |
| OLD | NEW |