| 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 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 if (running_status() == EmbeddedWorkerStatus::RUNNING) { | 556 if (running_status() == EmbeddedWorkerStatus::RUNNING) { |
| 557 DCHECK(start_callbacks_.empty()); | 557 DCHECK(start_callbacks_.empty()); |
| 558 task.Run(); | 558 task.Run(); |
| 559 return; | 559 return; |
| 560 } | 560 } |
| 561 StartWorker(purpose, | 561 StartWorker(purpose, |
| 562 base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), | 562 base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), |
| 563 error_callback, task)); | 563 error_callback, task)); |
| 564 } | 564 } |
| 565 | 565 |
| 566 void ServiceWorkerVersion::DispatchEvent(const std::vector<int>& request_ids, |
| 567 const IPC::Message& message) { |
| 568 DCHECK_EQ(EmbeddedWorkerStatus::RUNNING, running_status()); |
| 569 |
| 570 const ServiceWorkerStatusCode status = embedded_worker_->SendMessage(message); |
| 571 |
| 572 for (int request_id : request_ids) { |
| 573 PendingRequest<StatusCallback>* request = |
| 574 custom_requests_.Lookup(request_id); |
| 575 DCHECK(request) << "Invalid request id"; |
| 576 DCHECK(!request->is_dispatched) |
| 577 << "Request already dispatched an IPC event"; |
| 578 if (status != SERVICE_WORKER_OK) { |
| 579 RunSoon(base::Bind(request->callback, status)); |
| 580 custom_requests_.Remove(request_id); |
| 581 } else { |
| 582 request->is_dispatched = true; |
| 583 } |
| 584 } |
| 585 } |
| 586 |
| 566 void ServiceWorkerVersion::AddControllee( | 587 void ServiceWorkerVersion::AddControllee( |
| 567 ServiceWorkerProviderHost* provider_host) { | 588 ServiceWorkerProviderHost* provider_host) { |
| 568 const std::string& uuid = provider_host->client_uuid(); | 589 const std::string& uuid = provider_host->client_uuid(); |
| 569 CHECK(!provider_host->client_uuid().empty()); | 590 CHECK(!provider_host->client_uuid().empty()); |
| 570 DCHECK(!ContainsKey(controllee_map_, uuid)); | 591 DCHECK(!ContainsKey(controllee_map_, uuid)); |
| 571 controllee_map_[uuid] = provider_host; | 592 controllee_map_[uuid] = provider_host; |
| 572 // Keep the worker alive a bit longer right after a new controllee is added. | 593 // Keep the worker alive a bit longer right after a new controllee is added. |
| 573 RestartTick(&idle_time_); | 594 RestartTick(&idle_time_); |
| 574 FOR_EACH_OBSERVER(Listener, listeners_, | 595 FOR_EACH_OBSERVER(Listener, listeners_, |
| 575 OnControlleeAdded(this, provider_host)); | 596 OnControlleeAdded(this, provider_host)); |
| (...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1712 if (should_exclude_from_uma_ || | 1733 if (should_exclude_from_uma_ || |
| 1713 running_status() != EmbeddedWorkerStatus::RUNNING || | 1734 running_status() != EmbeddedWorkerStatus::RUNNING || |
| 1714 idle_time_.is_null()) { | 1735 idle_time_.is_null()) { |
| 1715 return; | 1736 return; |
| 1716 } | 1737 } |
| 1717 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - | 1738 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - |
| 1718 idle_time_); | 1739 idle_time_); |
| 1719 } | 1740 } |
| 1720 | 1741 |
| 1721 } // namespace content | 1742 } // namespace content |
| OLD | NEW |