Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: content/browser/service_worker/service_worker_version.cc

Issue 2034663002: ServiceWorker: Keep the worker alive until FetchEvent.waitUntil settles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add an inline comment Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 RunSoon(base::Bind(request->callback, status));
586 custom_requests_.Remove(request_id);
587 } else {
588 request->is_dispatched = true;
589 }
590 }
591 }
592
572 void ServiceWorkerVersion::AddControllee( 593 void ServiceWorkerVersion::AddControllee(
573 ServiceWorkerProviderHost* provider_host) { 594 ServiceWorkerProviderHost* provider_host) {
574 const std::string& uuid = provider_host->client_uuid(); 595 const std::string& uuid = provider_host->client_uuid();
575 CHECK(!provider_host->client_uuid().empty()); 596 CHECK(!provider_host->client_uuid().empty());
576 DCHECK(!ContainsKey(controllee_map_, uuid)); 597 DCHECK(!ContainsKey(controllee_map_, uuid));
577 controllee_map_[uuid] = provider_host; 598 controllee_map_[uuid] = provider_host;
578 // Keep the worker alive a bit longer right after a new controllee is added. 599 // Keep the worker alive a bit longer right after a new controllee is added.
579 RestartTick(&idle_time_); 600 RestartTick(&idle_time_);
580 FOR_EACH_OBSERVER(Listener, listeners_, 601 FOR_EACH_OBSERVER(Listener, listeners_,
581 OnControlleeAdded(this, provider_host)); 602 OnControlleeAdded(this, provider_host));
(...skipping 1138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1720 if (should_exclude_from_uma_ || 1741 if (should_exclude_from_uma_ ||
1721 running_status() != EmbeddedWorkerStatus::RUNNING || 1742 running_status() != EmbeddedWorkerStatus::RUNNING ||
1722 idle_time_.is_null()) { 1743 idle_time_.is_null()) {
1723 return; 1744 return;
1724 } 1745 }
1725 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - 1746 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() -
1726 idle_time_); 1747 idle_time_);
1727 } 1748 }
1728 1749
1729 } // namespace content 1750 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698