| 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 "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 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 int request_id = cross_origin_connect_callbacks_.Add( | 584 int request_id = cross_origin_connect_callbacks_.Add( |
| 585 new CrossOriginConnectCallback(callback)); | 585 new CrossOriginConnectCallback(callback)); |
| 586 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( | 586 ServiceWorkerStatusCode status = embedded_worker_->SendMessage( |
| 587 ServiceWorkerMsg_CrossOriginConnectEvent(request_id, client)); | 587 ServiceWorkerMsg_CrossOriginConnectEvent(request_id, client)); |
| 588 if (status != SERVICE_WORKER_OK) { | 588 if (status != SERVICE_WORKER_OK) { |
| 589 cross_origin_connect_callbacks_.Remove(request_id); | 589 cross_origin_connect_callbacks_.Remove(request_id); |
| 590 RunSoon(base::Bind(callback, status, false)); | 590 RunSoon(base::Bind(callback, status, false)); |
| 591 } | 591 } |
| 592 } | 592 } |
| 593 | 593 |
| 594 void ServiceWorkerVersion::DispatchCrossOriginMessageEvent( |
| 595 const CrossOriginServiceWorkerClient& client, |
| 596 const base::string16& message, |
| 597 const std::vector<int>& sent_message_port_ids, |
| 598 const StatusCallback& callback) { |
| 599 // Unlike in the case of DispatchMessageEvent, here the caller is assumed to |
| 600 // have already put all the sent message ports on hold. So no need to do that |
| 601 // here again. |
| 602 |
| 603 if (running_status() != RUNNING) { |
| 604 // Schedule calling this method after starting the worker. |
| 605 StartWorker(base::Bind( |
| 606 &RunTaskAfterStartWorker, weak_factory_.GetWeakPtr(), callback, |
| 607 base::Bind(&self::DispatchCrossOriginMessageEvent, |
| 608 weak_factory_.GetWeakPtr(), client, message, |
| 609 sent_message_port_ids, callback))); |
| 610 return; |
| 611 } |
| 612 |
| 613 MessagePortMessageFilter* filter = |
| 614 embedded_worker_->message_port_message_filter(); |
| 615 std::vector<int> new_routing_ids; |
| 616 filter->UpdateMessagePortsWithNewRoutes(sent_message_port_ids, |
| 617 &new_routing_ids); |
| 618 ServiceWorkerStatusCode status = |
| 619 embedded_worker_->SendMessage(ServiceWorkerMsg_CrossOriginMessageToWorker( |
| 620 client, message, sent_message_port_ids, new_routing_ids)); |
| 621 RunSoon(base::Bind(callback, status)); |
| 622 } |
| 594 void ServiceWorkerVersion::AddControllee( | 623 void ServiceWorkerVersion::AddControllee( |
| 595 ServiceWorkerProviderHost* provider_host) { | 624 ServiceWorkerProviderHost* provider_host) { |
| 596 DCHECK(!ContainsKey(controllee_map_, provider_host)); | 625 DCHECK(!ContainsKey(controllee_map_, provider_host)); |
| 597 int controllee_id = controllee_by_id_.Add(provider_host); | 626 int controllee_id = controllee_by_id_.Add(provider_host); |
| 598 controllee_map_[provider_host] = controllee_id; | 627 controllee_map_[provider_host] = controllee_id; |
| 599 // Reset the timer if it's running (so that it's kept alive a bit longer | 628 // Reset the timer if it's running (so that it's kept alive a bit longer |
| 600 // right after a new controllee is added). | 629 // right after a new controllee is added). |
| 601 ScheduleStopWorker(); | 630 ScheduleStopWorker(); |
| 602 } | 631 } |
| 603 | 632 |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 SetStatus(REDUNDANT); | 1137 SetStatus(REDUNDANT); |
| 1109 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); | 1138 StopWorker(base::Bind(&ServiceWorkerUtils::NoOpStatusCallback)); |
| 1110 if (!context_) | 1139 if (!context_) |
| 1111 return; | 1140 return; |
| 1112 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; | 1141 std::vector<ServiceWorkerDatabase::ResourceRecord> resources; |
| 1113 script_cache_map_.GetResources(&resources); | 1142 script_cache_map_.GetResources(&resources); |
| 1114 context_->storage()->PurgeResources(resources); | 1143 context_->storage()->PurgeResources(resources); |
| 1115 } | 1144 } |
| 1116 | 1145 |
| 1117 } // namespace content | 1146 } // namespace content |
| OLD | NEW |