OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_version.h" | 5 #include "content/browser/service_worker/service_worker_version.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "content/browser/service_worker/embedded_worker_instance.h" | 10 #include "content/browser/service_worker/embedded_worker_instance.h" |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 embedded_worker_->SendMessage(ServiceWorkerMsg_ActivateEvent(request_id)); | 565 embedded_worker_->SendMessage(ServiceWorkerMsg_ActivateEvent(request_id)); |
566 if (status != SERVICE_WORKER_OK) { | 566 if (status != SERVICE_WORKER_OK) { |
567 activate_callbacks_.Remove(request_id); | 567 activate_callbacks_.Remove(request_id); |
568 RunSoon(base::Bind(callback, status)); | 568 RunSoon(base::Bind(callback, status)); |
569 } | 569 } |
570 } | 570 } |
571 | 571 |
572 void ServiceWorkerVersion::OnGetClientDocuments(int request_id) { | 572 void ServiceWorkerVersion::OnGetClientDocuments(int request_id) { |
573 std::vector<int> client_ids; | 573 std::vector<int> client_ids; |
574 ControlleeByIDMap::iterator it(&controllee_by_id_); | 574 ControlleeByIDMap::iterator it(&controllee_by_id_); |
| 575 TRACE_EVENT0("ServiceWorker", |
| 576 "ServiceWorkerVersion::OnGetClientDocuments"); |
575 while (!it.IsAtEnd()) { | 577 while (!it.IsAtEnd()) { |
576 client_ids.push_back(it.GetCurrentKey()); | 578 client_ids.push_back(it.GetCurrentKey()); |
577 it.Advance(); | 579 it.Advance(); |
578 } | 580 } |
579 // Don't bother if it's no longer running. | 581 // Don't bother if it's no longer running. |
580 if (running_status() == RUNNING) { | 582 if (running_status() == RUNNING) { |
581 embedded_worker_->SendMessage( | 583 embedded_worker_->SendMessage( |
582 ServiceWorkerMsg_DidGetClientDocuments(request_id, client_ids)); | 584 ServiceWorkerMsg_DidGetClientDocuments(request_id, client_ids)); |
583 } | 585 } |
584 } | 586 } |
585 | 587 |
586 void ServiceWorkerVersion::OnActivateEventFinished( | 588 void ServiceWorkerVersion::OnActivateEventFinished( |
587 int request_id, | 589 int request_id, |
588 blink::WebServiceWorkerEventResult result) { | 590 blink::WebServiceWorkerEventResult result) { |
589 DCHECK(ACTIVATING == status() || | 591 DCHECK(ACTIVATING == status() || |
590 REDUNDANT == status()) << status(); | 592 REDUNDANT == status()) << status(); |
| 593 TRACE_EVENT0("ServiceWorker", |
| 594 "ServiceWorkerVersion::OnActivateEventFinished"); |
591 | 595 |
592 StatusCallback* callback = activate_callbacks_.Lookup(request_id); | 596 StatusCallback* callback = activate_callbacks_.Lookup(request_id); |
593 if (!callback) { | 597 if (!callback) { |
594 NOTREACHED() << "Got unexpected message: " << request_id; | 598 NOTREACHED() << "Got unexpected message: " << request_id; |
595 return; | 599 return; |
596 } | 600 } |
597 ServiceWorkerStatusCode rv = SERVICE_WORKER_OK; | 601 ServiceWorkerStatusCode rv = SERVICE_WORKER_OK; |
598 if (result == blink::WebServiceWorkerEventResultRejected || | 602 if (result == blink::WebServiceWorkerEventResultRejected || |
599 status() != ACTIVATING) { | 603 status() != ACTIVATING) { |
600 rv = SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED; | 604 rv = SERVICE_WORKER_ERROR_ACTIVATE_WORKER_FAILED; |
601 } | 605 } |
602 | 606 |
603 scoped_refptr<ServiceWorkerVersion> protect(this); | 607 scoped_refptr<ServiceWorkerVersion> protect(this); |
604 callback->Run(rv); | 608 callback->Run(rv); |
605 activate_callbacks_.Remove(request_id); | 609 activate_callbacks_.Remove(request_id); |
606 } | 610 } |
607 | 611 |
608 void ServiceWorkerVersion::OnInstallEventFinished( | 612 void ServiceWorkerVersion::OnInstallEventFinished( |
609 int request_id, | 613 int request_id, |
610 blink::WebServiceWorkerEventResult result) { | 614 blink::WebServiceWorkerEventResult result) { |
611 DCHECK_EQ(INSTALLING, status()) << status(); | 615 DCHECK_EQ(INSTALLING, status()) << status(); |
| 616 TRACE_EVENT0("ServiceWorker", |
| 617 "ServiceWorkerVersion::OnInstallEventFinished"); |
612 | 618 |
613 StatusCallback* callback = install_callbacks_.Lookup(request_id); | 619 StatusCallback* callback = install_callbacks_.Lookup(request_id); |
614 if (!callback) { | 620 if (!callback) { |
615 NOTREACHED() << "Got unexpected message: " << request_id; | 621 NOTREACHED() << "Got unexpected message: " << request_id; |
616 return; | 622 return; |
617 } | 623 } |
618 ServiceWorkerStatusCode status = SERVICE_WORKER_OK; | 624 ServiceWorkerStatusCode status = SERVICE_WORKER_OK; |
619 if (result == blink::WebServiceWorkerEventResultRejected) | 625 if (result == blink::WebServiceWorkerEventResultRejected) |
620 status = SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED; | 626 status = SERVICE_WORKER_ERROR_INSTALL_WORKER_FAILED; |
621 | 627 |
622 scoped_refptr<ServiceWorkerVersion> protect(this); | 628 scoped_refptr<ServiceWorkerVersion> protect(this); |
623 callback->Run(status); | 629 callback->Run(status); |
624 install_callbacks_.Remove(request_id); | 630 install_callbacks_.Remove(request_id); |
625 } | 631 } |
626 | 632 |
627 void ServiceWorkerVersion::OnFetchEventFinished( | 633 void ServiceWorkerVersion::OnFetchEventFinished( |
628 int request_id, | 634 int request_id, |
629 ServiceWorkerFetchEventResult result, | 635 ServiceWorkerFetchEventResult result, |
630 const ServiceWorkerResponse& response) { | 636 const ServiceWorkerResponse& response) { |
| 637 TRACE_EVENT1("ServiceWorker", |
| 638 "ServiceWorkerVersion::OnFetchEventFinished", |
| 639 "Request id", request_id); |
631 FetchCallback* callback = fetch_callbacks_.Lookup(request_id); | 640 FetchCallback* callback = fetch_callbacks_.Lookup(request_id); |
632 if (!callback) { | 641 if (!callback) { |
633 NOTREACHED() << "Got unexpected message: " << request_id; | 642 NOTREACHED() << "Got unexpected message: " << request_id; |
634 return; | 643 return; |
635 } | 644 } |
636 | 645 |
637 scoped_refptr<ServiceWorkerVersion> protect(this); | 646 scoped_refptr<ServiceWorkerVersion> protect(this); |
638 callback->Run(SERVICE_WORKER_OK, result, response); | 647 callback->Run(SERVICE_WORKER_OK, result, response); |
639 fetch_callbacks_.Remove(request_id); | 648 fetch_callbacks_.Remove(request_id); |
640 } | 649 } |
641 | 650 |
642 void ServiceWorkerVersion::OnSyncEventFinished( | 651 void ServiceWorkerVersion::OnSyncEventFinished( |
643 int request_id) { | 652 int request_id) { |
| 653 TRACE_EVENT1("ServiceWorker", |
| 654 "ServiceWorkerVersion::OnSyncEventFinished", |
| 655 "Request id", request_id); |
644 StatusCallback* callback = sync_callbacks_.Lookup(request_id); | 656 StatusCallback* callback = sync_callbacks_.Lookup(request_id); |
645 if (!callback) { | 657 if (!callback) { |
646 NOTREACHED() << "Got unexpected message: " << request_id; | 658 NOTREACHED() << "Got unexpected message: " << request_id; |
647 return; | 659 return; |
648 } | 660 } |
649 | 661 |
650 scoped_refptr<ServiceWorkerVersion> protect(this); | 662 scoped_refptr<ServiceWorkerVersion> protect(this); |
651 callback->Run(SERVICE_WORKER_OK); | 663 callback->Run(SERVICE_WORKER_OK); |
652 sync_callbacks_.Remove(request_id); | 664 sync_callbacks_.Remove(request_id); |
653 } | 665 } |
654 | 666 |
655 void ServiceWorkerVersion::OnPushEventFinished( | 667 void ServiceWorkerVersion::OnPushEventFinished( |
656 int request_id) { | 668 int request_id) { |
| 669 TRACE_EVENT1("ServiceWorker", |
| 670 "ServiceWorkerVersion::OnPushEventFinished", |
| 671 "Request id", request_id); |
657 StatusCallback* callback = push_callbacks_.Lookup(request_id); | 672 StatusCallback* callback = push_callbacks_.Lookup(request_id); |
658 if (!callback) { | 673 if (!callback) { |
659 NOTREACHED() << "Got unexpected message: " << request_id; | 674 NOTREACHED() << "Got unexpected message: " << request_id; |
660 return; | 675 return; |
661 } | 676 } |
662 | 677 |
663 scoped_refptr<ServiceWorkerVersion> protect(this); | 678 scoped_refptr<ServiceWorkerVersion> protect(this); |
664 callback->Run(SERVICE_WORKER_OK); | 679 callback->Run(SERVICE_WORKER_OK); |
665 push_callbacks_.Remove(request_id); | 680 push_callbacks_.Remove(request_id); |
666 } | 681 } |
667 | 682 |
668 void ServiceWorkerVersion::OnPostMessageToDocument( | 683 void ServiceWorkerVersion::OnPostMessageToDocument( |
669 int client_id, | 684 int client_id, |
670 const base::string16& message, | 685 const base::string16& message, |
671 const std::vector<int>& sent_message_port_ids) { | 686 const std::vector<int>& sent_message_port_ids) { |
| 687 TRACE_EVENT1("ServiceWorker", |
| 688 "ServiceWorkerVersion::OnPostMessageToDocument", |
| 689 "Client id", client_id); |
672 ServiceWorkerProviderHost* provider_host = | 690 ServiceWorkerProviderHost* provider_host = |
673 controllee_by_id_.Lookup(client_id); | 691 controllee_by_id_.Lookup(client_id); |
674 if (!provider_host) { | 692 if (!provider_host) { |
675 // The client may already have been closed, just ignore. | 693 // The client may already have been closed, just ignore. |
676 return; | 694 return; |
677 } | 695 } |
678 provider_host->PostMessage(message, sent_message_port_ids); | 696 provider_host->PostMessage(message, sent_message_port_ids); |
679 } | 697 } |
680 | 698 |
681 void ServiceWorkerVersion::ScheduleStopWorker() { | 699 void ServiceWorkerVersion::ScheduleStopWorker() { |
(...skipping 15 matching lines...) Expand all Loading... |
697 SetStatus(REDUNDANT); | 715 SetStatus(REDUNDANT); |
698 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 716 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
699 if (!context_) | 717 if (!context_) |
700 return; | 718 return; |
701 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; | 719 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; |
702 script_cache_map_.GetResources(&resources); | 720 script_cache_map_.GetResources(&resources); |
703 context_->storage()->PurgeResources(resources); | 721 context_->storage()->PurgeResources(resources); |
704 } | 722 } |
705 | 723 |
706 } // namespace content | 724 } // namespace content |
OLD | NEW |