| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 if (running_status() == EmbeddedWorkerStatus::RUNNING) { | 562 if (running_status() == EmbeddedWorkerStatus::RUNNING) { |
| 563 DCHECK(start_callbacks_.empty()); | 563 DCHECK(start_callbacks_.empty()); |
| 564 task.Run(); | 564 task.Run(); |
| 565 return; | 565 return; |
| 566 } | 566 } |
| 567 StartWorker(purpose, | 567 StartWorker(purpose, |
| 568 base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), | 568 base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), |
| 569 error_callback, task)); | 569 error_callback, task)); |
| 570 } | 570 } |
| 571 | 571 |
| 572 void ServiceWorkerVersion::DispatchEvent(const std::vector<int>& request_ids, |
| 573 const IPC::Message& message) { |
| 574 DCHECK_EQ(EmbeddedWorkerStatus::RUNNING, running_status()); |
| 575 |
| 576 const ServiceWorkerStatusCode status = embedded_worker_->SendMessage(message); |
| 577 |
| 578 for (int request_id : request_ids) { |
| 579 PendingRequest<StatusCallback>* request = |
| 580 custom_requests_.Lookup(request_id); |
| 581 DCHECK(request) << "Invalid request id"; |
| 582 DCHECK(!request->is_dispatched) |
| 583 << "Request already dispatched an IPC event"; |
| 584 if (status != SERVICE_WORKER_OK) { |
| 585 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 586 FROM_HERE, base::Bind(request->callback, status)); |
| 587 custom_requests_.Remove(request_id); |
| 588 } else { |
| 589 request->is_dispatched = true; |
| 590 } |
| 591 } |
| 592 } |
| 593 |
| 572 void ServiceWorkerVersion::AddControllee( | 594 void ServiceWorkerVersion::AddControllee( |
| 573 ServiceWorkerProviderHost* provider_host) { | 595 ServiceWorkerProviderHost* provider_host) { |
| 574 const std::string& uuid = provider_host->client_uuid(); | 596 const std::string& uuid = provider_host->client_uuid(); |
| 575 CHECK(!provider_host->client_uuid().empty()); | 597 CHECK(!provider_host->client_uuid().empty()); |
| 576 DCHECK(!ContainsKey(controllee_map_, uuid)); | 598 DCHECK(!ContainsKey(controllee_map_, uuid)); |
| 577 controllee_map_[uuid] = provider_host; | 599 controllee_map_[uuid] = provider_host; |
| 578 // Keep the worker alive a bit longer right after a new controllee is added. | 600 // Keep the worker alive a bit longer right after a new controllee is added. |
| 579 RestartTick(&idle_time_); | 601 RestartTick(&idle_time_); |
| 580 FOR_EACH_OBSERVER(Listener, listeners_, | 602 FOR_EACH_OBSERVER(Listener, listeners_, |
| 581 OnControlleeAdded(this, provider_host)); | 603 OnControlleeAdded(this, provider_host)); |
| (...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1720 if (should_exclude_from_uma_ || | 1742 if (should_exclude_from_uma_ || |
| 1721 running_status() != EmbeddedWorkerStatus::RUNNING || | 1743 running_status() != EmbeddedWorkerStatus::RUNNING || |
| 1722 idle_time_.is_null()) { | 1744 idle_time_.is_null()) { |
| 1723 return; | 1745 return; |
| 1724 } | 1746 } |
| 1725 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - | 1747 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - |
| 1726 idle_time_); | 1748 idle_time_); |
| 1727 } | 1749 } |
| 1728 | 1750 |
| 1729 } // namespace content | 1751 } // namespace content |
| OLD | NEW |