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 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 update_timer_.Stop(); | 419 update_timer_.Stop(); |
420 if (!context_) | 420 if (!context_) |
421 return; | 421 return; |
422 ServiceWorkerRegistration* registration = | 422 ServiceWorkerRegistration* registration = |
423 context_->GetLiveRegistration(registration_id_); | 423 context_->GetLiveRegistration(registration_id_); |
424 if (!registration || !registration->GetNewestVersion()) | 424 if (!registration || !registration->GetNewestVersion()) |
425 return; | 425 return; |
426 context_->UpdateServiceWorker(registration); | 426 context_->UpdateServiceWorker(registration); |
427 } | 427 } |
428 | 428 |
429 void ServiceWorkerVersion::SendMessage( | |
430 const IPC::Message& message, const StatusCallback& callback) { | |
431 if (running_status() != RUNNING) { | |
432 // Schedule calling this method after starting the worker. | |
433 StartWorker(base::Bind(&RunTaskAfterStartWorker, | |
434 weak_factory_.GetWeakPtr(), callback, | |
435 base::Bind(&self::SendMessage, | |
436 weak_factory_.GetWeakPtr(), | |
437 message, callback))); | |
438 return; | |
439 } | |
440 | |
441 ServiceWorkerStatusCode status = embedded_worker_->SendMessage(message); | |
442 RunSoon(base::Bind(callback, status)); | |
443 } | |
444 | |
445 void ServiceWorkerVersion::DispatchMessageEvent( | 429 void ServiceWorkerVersion::DispatchMessageEvent( |
446 const base::string16& message, | 430 const base::string16& message, |
447 const std::vector<TransferredMessagePort>& sent_message_ports, | 431 const std::vector<TransferredMessagePort>& sent_message_ports, |
448 const StatusCallback& callback) { | 432 const StatusCallback& callback) { |
449 for (const TransferredMessagePort& port : sent_message_ports) { | 433 for (const TransferredMessagePort& port : sent_message_ports) { |
450 MessagePortService::GetInstance()->HoldMessages(port.id); | 434 MessagePortService::GetInstance()->HoldMessages(port.id); |
451 } | 435 } |
452 | 436 |
453 DispatchMessageEventInternal(message, sent_message_ports, callback); | 437 DispatchMessageEventInternal(message, sent_message_ports, callback); |
454 } | 438 } |
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1517 int request_id) { | 1501 int request_id) { |
1518 callbacks->Remove(request_id); | 1502 callbacks->Remove(request_id); |
1519 if (is_doomed_) { | 1503 if (is_doomed_) { |
1520 // The stop should be already scheduled, but try to stop immediately, in | 1504 // The stop should be already scheduled, but try to stop immediately, in |
1521 // order to release worker resources soon. | 1505 // order to release worker resources soon. |
1522 StopWorkerIfIdle(); | 1506 StopWorkerIfIdle(); |
1523 } | 1507 } |
1524 } | 1508 } |
1525 | 1509 |
1526 } // namespace content | 1510 } // namespace content |
OLD | NEW |