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

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: Fix the name of variables and comments 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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 if (running_status() == RUNNING) { 559 if (running_status() == RUNNING) {
560 DCHECK(start_callbacks_.empty()); 560 DCHECK(start_callbacks_.empty());
561 task.Run(); 561 task.Run();
562 return; 562 return;
563 } 563 }
564 StartWorker(purpose, 564 StartWorker(purpose,
565 base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), 565 base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(),
566 error_callback, task)); 566 error_callback, task));
567 } 567 }
568 568
569 void ServiceWorkerVersion::DispatchEvent(const std::vector<int>& request_ids,
570 const IPC::Message& message) {
571 DCHECK_EQ(RUNNING, running_status());
572
573 const ServiceWorkerStatusCode status = embedded_worker_->SendMessage(message);
574
575 for (int request_id : request_ids) {
576 PendingRequest<StatusCallback>* request =
577 custom_requests_.Lookup(request_id);
578 DCHECK(request) << "Invalid request id";
579 DCHECK(!request->is_dispatched)
580 << "Request already dispatched an IPC event";
581 if (status != SERVICE_WORKER_OK) {
582 base::ThreadTaskRunnerHandle::Get()->PostTask(
Marijn Kruisselbrink 2016/06/15 12:37:07 Now this code is in the .cc file you could use Run
shimazu 2016/06/21 02:43:38 Done.
583 FROM_HERE, base::Bind(request->callback, status));
584 custom_requests_.Remove(request_id);
585 } else {
586 request->is_dispatched = true;
587 }
588 }
589 }
590
569 void ServiceWorkerVersion::AddControllee( 591 void ServiceWorkerVersion::AddControllee(
570 ServiceWorkerProviderHost* provider_host) { 592 ServiceWorkerProviderHost* provider_host) {
571 const std::string& uuid = provider_host->client_uuid(); 593 const std::string& uuid = provider_host->client_uuid();
572 CHECK(!provider_host->client_uuid().empty()); 594 CHECK(!provider_host->client_uuid().empty());
573 DCHECK(!ContainsKey(controllee_map_, uuid)); 595 DCHECK(!ContainsKey(controllee_map_, uuid));
574 controllee_map_[uuid] = provider_host; 596 controllee_map_[uuid] = provider_host;
575 // Keep the worker alive a bit longer right after a new controllee is added. 597 // Keep the worker alive a bit longer right after a new controllee is added.
576 RestartTick(&idle_time_); 598 RestartTick(&idle_time_);
577 FOR_EACH_OBSERVER(Listener, listeners_, 599 FOR_EACH_OBSERVER(Listener, listeners_,
578 OnControlleeAdded(this, provider_host)); 600 OnControlleeAdded(this, provider_host));
(...skipping 1125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 void ServiceWorkerVersion::OnBeginEvent() { 1726 void ServiceWorkerVersion::OnBeginEvent() {
1705 if (should_exclude_from_uma_ || running_status() != RUNNING || 1727 if (should_exclude_from_uma_ || running_status() != RUNNING ||
1706 idle_time_.is_null()) { 1728 idle_time_.is_null()) {
1707 return; 1729 return;
1708 } 1730 }
1709 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() - 1731 ServiceWorkerMetrics::RecordTimeBetweenEvents(base::TimeTicks::Now() -
1710 idle_time_); 1732 idle_time_);
1711 } 1733 }
1712 1734
1713 } // namespace content 1735 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698