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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <map> | 10 #include <map> |
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
487 weak_factory_.GetWeakPtr(), purpose, status_, | 487 weak_factory_.GetWeakPtr(), purpose, status_, |
488 is_browser_startup_complete, callback)); | 488 is_browser_startup_complete, callback)); |
489 } | 489 } |
490 | 490 |
491 void ServiceWorkerVersion::StopWorker(const StatusCallback& callback) { | 491 void ServiceWorkerVersion::StopWorker(const StatusCallback& callback) { |
492 TRACE_EVENT_INSTANT2("ServiceWorker", | 492 TRACE_EVENT_INSTANT2("ServiceWorker", |
493 "ServiceWorkerVersion::StopWorker (instant)", | 493 "ServiceWorkerVersion::StopWorker (instant)", |
494 TRACE_EVENT_SCOPE_THREAD, "Script", script_url_.spec(), | 494 TRACE_EVENT_SCOPE_THREAD, "Script", script_url_.spec(), |
495 "Status", VersionStatusToString(status_)); | 495 "Status", VersionStatusToString(status_)); |
496 | 496 |
497 if (running_status() == EmbeddedWorkerStatus::STOPPED) { | 497 switch (running_status()) { |
498 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); | 498 case EmbeddedWorkerStatus::STARTING: |
499 return; | 499 case EmbeddedWorkerStatus::RUNNING: |
| 500 // Stop() returns false when it's called before StartWorker message hasn't |
| 501 // been sent to the renderer process even though EmbeddedWorkerInstance is |
| 502 // stopped properly. |
| 503 // TODO(shimazu): Remove this check after Stop() hides the IPC behavior. |
| 504 // See also a TODO on EmbeddedWorkerInstance::Stop. |
| 505 if (!embedded_worker_->Stop()) { |
| 506 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_IPC_FAILED)); |
| 507 return; |
| 508 } |
| 509 stop_callbacks_.push_back(callback); |
| 510 return; |
| 511 case EmbeddedWorkerStatus::STOPPING: |
| 512 stop_callbacks_.push_back(callback); |
| 513 return; |
| 514 case EmbeddedWorkerStatus::STOPPED: |
| 515 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); |
| 516 return; |
500 } | 517 } |
501 | |
502 if (stop_callbacks_.empty()) { | |
503 ServiceWorkerStatusCode status = embedded_worker_->Stop(); | |
504 if (status != SERVICE_WORKER_OK) { | |
505 RunSoon(base::Bind(callback, status)); | |
506 return; | |
507 } | |
508 } | |
509 stop_callbacks_.push_back(callback); | |
510 } | 518 } |
511 | 519 |
512 void ServiceWorkerVersion::ScheduleUpdate() { | 520 void ServiceWorkerVersion::ScheduleUpdate() { |
513 if (!context_) | 521 if (!context_) |
514 return; | 522 return; |
515 if (update_timer_.IsRunning()) { | 523 if (update_timer_.IsRunning()) { |
516 update_timer_.Reset(); | 524 update_timer_.Reset(); |
517 return; | 525 return; |
518 } | 526 } |
519 if (is_update_scheduled_) | 527 if (is_update_scheduled_) |
(...skipping 1396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1916 | 1924 |
1917 void ServiceWorkerVersion::CleanUpExternalRequest( | 1925 void ServiceWorkerVersion::CleanUpExternalRequest( |
1918 const std::string& request_uuid, | 1926 const std::string& request_uuid, |
1919 ServiceWorkerStatusCode status) { | 1927 ServiceWorkerStatusCode status) { |
1920 if (status == SERVICE_WORKER_OK) | 1928 if (status == SERVICE_WORKER_OK) |
1921 return; | 1929 return; |
1922 external_request_uuid_to_request_id_.erase(request_uuid); | 1930 external_request_uuid_to_request_id_.erase(request_uuid); |
1923 } | 1931 } |
1924 | 1932 |
1925 } // namespace content | 1933 } // namespace content |
OLD | NEW |