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

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

Issue 861373002: Refactor navigator.connect code to make it more flexible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix typo Created 5 years, 10 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 "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/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 embedded_worker_->SendMessage(ServiceWorkerMsg_GeofencingEvent( 537 embedded_worker_->SendMessage(ServiceWorkerMsg_GeofencingEvent(
538 request_id, event_type, region_id, region)); 538 request_id, event_type, region_id, region));
539 if (status != SERVICE_WORKER_OK) { 539 if (status != SERVICE_WORKER_OK) {
540 geofencing_callbacks_.Remove(request_id); 540 geofencing_callbacks_.Remove(request_id);
541 RunSoon(base::Bind(callback, status)); 541 RunSoon(base::Bind(callback, status));
542 } 542 }
543 } 543 }
544 544
545 void ServiceWorkerVersion::DispatchCrossOriginConnectEvent( 545 void ServiceWorkerVersion::DispatchCrossOriginConnectEvent(
546 const CrossOriginConnectCallback& callback, 546 const CrossOriginConnectCallback& callback,
547 const CrossOriginServiceWorkerClient& client) { 547 const NavigatorConnectClient& client) {
548 DCHECK_EQ(ACTIVATED, status()) << status(); 548 DCHECK_EQ(ACTIVATED, status()) << status();
549 549
550 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 550 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
551 switches::kEnableExperimentalWebPlatformFeatures)) { 551 switches::kEnableExperimentalWebPlatformFeatures)) {
552 callback.Run(SERVICE_WORKER_ERROR_ABORT, false); 552 callback.Run(SERVICE_WORKER_ERROR_ABORT, false);
553 return; 553 return;
554 } 554 }
555 555
556 if (running_status() != RUNNING) { 556 if (running_status() != RUNNING) {
557 // Schedule calling this method after starting the worker. 557 // Schedule calling this method after starting the worker.
558 StartWorker( 558 StartWorker(
559 base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), 559 base::Bind(&RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(),
560 base::Bind(&RunErrorCrossOriginConnectCallback, callback), 560 base::Bind(&RunErrorCrossOriginConnectCallback, callback),
561 base::Bind(&self::DispatchCrossOriginConnectEvent, 561 base::Bind(&self::DispatchCrossOriginConnectEvent,
562 weak_factory_.GetWeakPtr(), callback, client))); 562 weak_factory_.GetWeakPtr(), callback, client)));
563 return; 563 return;
564 } 564 }
565 565
566 int request_id = cross_origin_connect_callbacks_.Add( 566 int request_id = cross_origin_connect_callbacks_.Add(
567 new CrossOriginConnectCallback(callback)); 567 new CrossOriginConnectCallback(callback));
568 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( 568 ServiceWorkerStatusCode status = embedded_worker_->SendMessage(
569 ServiceWorkerMsg_CrossOriginConnectEvent(request_id, client)); 569 ServiceWorkerMsg_CrossOriginConnectEvent(request_id, client));
570 if (status != SERVICE_WORKER_OK) { 570 if (status != SERVICE_WORKER_OK) {
571 cross_origin_connect_callbacks_.Remove(request_id); 571 cross_origin_connect_callbacks_.Remove(request_id);
572 RunSoon(base::Bind(callback, status, false)); 572 RunSoon(base::Bind(callback, status, false));
573 } 573 }
574 } 574 }
575 575
576 void ServiceWorkerVersion::DispatchCrossOriginMessageEvent( 576 void ServiceWorkerVersion::DispatchCrossOriginMessageEvent(
577 const CrossOriginServiceWorkerClient& client, 577 const NavigatorConnectClient& client,
578 const base::string16& message, 578 const base::string16& message,
579 const std::vector<int>& sent_message_port_ids, 579 const std::vector<int>& sent_message_port_ids,
580 const StatusCallback& callback) { 580 const StatusCallback& callback) {
581 // Unlike in the case of DispatchMessageEvent, here the caller is assumed to 581 // Unlike in the case of DispatchMessageEvent, here the caller is assumed to
582 // have already put all the sent message ports on hold. So no need to do that 582 // have already put all the sent message ports on hold. So no need to do that
583 // here again. 583 // here again.
584 584
585 if (running_status() != RUNNING) { 585 if (running_status() != RUNNING) {
586 // Schedule calling this method after starting the worker. 586 // Schedule calling this method after starting the worker.
587 StartWorker(base::Bind( 587 StartWorker(base::Bind(
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 int request_id) { 1172 int request_id) {
1173 callbacks->Remove(request_id); 1173 callbacks->Remove(request_id);
1174 if (is_doomed_) { 1174 if (is_doomed_) {
1175 // The stop should be already scheduled, but try to stop immediately, in 1175 // The stop should be already scheduled, but try to stop immediately, in
1176 // order to release worker resources soon. 1176 // order to release worker resources soon.
1177 StopWorkerIfIdle(); 1177 StopWorkerIfIdle();
1178 } 1178 }
1179 } 1179 }
1180 1180
1181 } // namespace content 1181 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_version.h ('k') | content/browser/storage_partition_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698