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

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

Issue 1013423002: ServiceWorker: Make claim() uses living matching registrations instead of fetching from DB. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 9 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
« no previous file with comments | « content/browser/service_worker/service_worker_version.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 if (pending_skip_waiting_requests_.size() == 1) 1385 if (pending_skip_waiting_requests_.size() == 1)
1386 registration->ActivateWaitingVersionWhenReady(); 1386 registration->ActivateWaitingVersionWhenReady();
1387 } 1387 }
1388 1388
1389 void ServiceWorkerVersion::DidSkipWaiting(int request_id) { 1389 void ServiceWorkerVersion::DidSkipWaiting(int request_id) {
1390 if (running_status() == STARTING || running_status() == RUNNING) 1390 if (running_status() == STARTING || running_status() == RUNNING)
1391 embedded_worker_->SendMessage(ServiceWorkerMsg_DidSkipWaiting(request_id)); 1391 embedded_worker_->SendMessage(ServiceWorkerMsg_DidSkipWaiting(request_id));
1392 } 1392 }
1393 1393
1394 void ServiceWorkerVersion::OnClaimClients(int request_id) { 1394 void ServiceWorkerVersion::OnClaimClients(int request_id) {
1395 StatusCallback callback = base::Bind(&ServiceWorkerVersion::DidClaimClients,
1396 weak_factory_.GetWeakPtr(), request_id);
1397 if (status_ != ACTIVATING && status_ != ACTIVATED) { 1395 if (status_ != ACTIVATING && status_ != ACTIVATED) {
1398 callback.Run(SERVICE_WORKER_ERROR_STATE); 1396 embedded_worker_->SendMessage(ServiceWorkerMsg_ClaimClientsError(
1397 request_id, blink::WebServiceWorkerError::ErrorTypeState,
1398 base::ASCIIToUTF16(kClaimClientsStateErrorMesage)));
1399 return; 1399 return;
1400 } 1400 }
1401 if (!context_) { 1401 if (context_) {
1402 callback.Run(SERVICE_WORKER_ERROR_ABORT); 1402 if (ServiceWorkerRegistration* registration =
1403 return; 1403 context_->GetLiveRegistration(registration_id_)) {
falken 2015/03/23 00:38:57 (unrelated to this patch) I think there might be a
michaeln 2015/03/23 20:02:26 Good question. I think the answer is 'yes', hiroki
xiang 2015/03/24 07:32:51 Thanks for the clarification, yes, the Registratio
1404 registration->ClaimClients();
1405 embedded_worker_->SendMessage(
1406 ServiceWorkerMsg_DidClaimClients(request_id));
1407 return;
1408 }
1404 } 1409 }
1405 1410
1406 ServiceWorkerRegistration* registration = 1411 embedded_worker_->SendMessage(ServiceWorkerMsg_ClaimClientsError(
1407 context_->GetLiveRegistration(registration_id_); 1412 request_id, blink::WebServiceWorkerError::ErrorTypeAbort,
1408 if (!registration) { 1413 base::ASCIIToUTF16(kClaimClientsShutdownErrorMesage)));
1409 callback.Run(SERVICE_WORKER_ERROR_ABORT); 1414 return;
michaeln 2015/03/20 19:25:21 this return statement is not needed
xiang 2015/03/24 07:32:51 Done.
1410 return;
1411 }
1412 registration->ClaimClients(callback);
1413 } 1415 }
1414 1416
1415 void ServiceWorkerVersion::OnPongFromWorker() { 1417 void ServiceWorkerVersion::OnPongFromWorker() {
1416 ClearTick(&ping_time_); 1418 ClearTick(&ping_time_);
1417 } 1419 }
1418 1420
1419 void ServiceWorkerVersion::DidEnsureLiveRegistrationForStartWorker( 1421 void ServiceWorkerVersion::DidEnsureLiveRegistrationForStartWorker(
1420 bool pause_after_download, 1422 bool pause_after_download,
1421 const StatusCallback& callback, 1423 const StatusCallback& callback,
1422 ServiceWorkerStatusCode status, 1424 ServiceWorkerStatusCode status,
(...skipping 20 matching lines...) Expand all
1443 cache_listener_.reset(new ServiceWorkerCacheListener(this, context_)); 1445 cache_listener_.reset(new ServiceWorkerCacheListener(this, context_));
1444 embedded_worker_->Start( 1446 embedded_worker_->Start(
1445 version_id_, scope_, script_url_, pause_after_download, 1447 version_id_, scope_, script_url_, pause_after_download,
1446 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated, 1448 base::Bind(&ServiceWorkerVersion::OnStartSentAndScriptEvaluated,
1447 weak_factory_.GetWeakPtr())); 1449 weak_factory_.GetWeakPtr()));
1448 } 1450 }
1449 return; 1451 return;
1450 } 1452 }
1451 } 1453 }
1452 1454
1453 void ServiceWorkerVersion::DidClaimClients(
1454 int request_id, ServiceWorkerStatusCode status) {
1455 if (status == SERVICE_WORKER_ERROR_STATE) {
1456 embedded_worker_->SendMessage(ServiceWorkerMsg_ClaimClientsError(
1457 request_id, blink::WebServiceWorkerError::ErrorTypeState,
1458 base::ASCIIToUTF16(kClaimClientsStateErrorMesage)));
1459 return;
1460 }
1461 if (status == SERVICE_WORKER_ERROR_ABORT) {
1462 embedded_worker_->SendMessage(ServiceWorkerMsg_ClaimClientsError(
1463 request_id, blink::WebServiceWorkerError::ErrorTypeAbort,
1464 base::ASCIIToUTF16(kClaimClientsShutdownErrorMesage)));
1465 return;
1466 }
1467 DCHECK(status == SERVICE_WORKER_OK);
1468 embedded_worker_->SendMessage(ServiceWorkerMsg_DidClaimClients(request_id));
1469 }
1470
1471 void ServiceWorkerVersion::DidGetClients( 1455 void ServiceWorkerVersion::DidGetClients(
1472 int request_id, 1456 int request_id,
1473 const std::vector<ServiceWorkerClientInfo>& clients) { 1457 const std::vector<ServiceWorkerClientInfo>& clients) {
1474 DCHECK_CURRENTLY_ON(BrowserThread::IO); 1458 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1475 if (running_status() != RUNNING) 1459 if (running_status() != RUNNING)
1476 return; 1460 return;
1477 1461
1478 embedded_worker_->SendMessage( 1462 embedded_worker_->SendMessage(
1479 ServiceWorkerMsg_DidGetClients(request_id, clients)); 1463 ServiceWorkerMsg_DidGetClients(request_id, clients));
1480 } 1464 }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 int request_id) { 1636 int request_id) {
1653 callbacks->Remove(request_id); 1637 callbacks->Remove(request_id);
1654 if (is_doomed_) { 1638 if (is_doomed_) {
1655 // The stop should be already scheduled, but try to stop immediately, in 1639 // The stop should be already scheduled, but try to stop immediately, in
1656 // order to release worker resources soon. 1640 // order to release worker resources soon.
1657 StopWorkerIfIdle(); 1641 StopWorkerIfIdle();
1658 } 1642 }
1659 } 1643 }
1660 1644
1661 } // namespace content 1645 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_version.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698