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/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "content/browser/service_worker/embedded_worker_instance.h" | 8 #include "content/browser/service_worker/embedded_worker_instance.h" |
9 #include "content/browser/service_worker/embedded_worker_registry.h" | 9 #include "content/browser/service_worker/embedded_worker_registry.h" |
10 #include "content/browser/service_worker/service_worker_context_core.h" | 10 #include "content/browser/service_worker/service_worker_context_core.h" |
11 #include "content/browser/service_worker/service_worker_registration.h" | 11 #include "content/browser/service_worker/service_worker_registration.h" |
12 #include "content/common/service_worker/service_worker_messages.h" | 12 #include "content/common/service_worker/service_worker_messages.h" |
| 13 #include "content/public/browser/browser_thread.h" |
13 | 14 |
14 namespace content { | 15 namespace content { |
15 | 16 |
16 typedef ServiceWorkerVersion::StatusCallback StatusCallback; | 17 typedef ServiceWorkerVersion::StatusCallback StatusCallback; |
17 typedef ServiceWorkerVersion::MessageCallback MessageCallback; | 18 typedef ServiceWorkerVersion::MessageCallback MessageCallback; |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 void RunSoon(const base::Closure& callback) { | 22 void RunSoon(const base::Closure& callback) { |
22 if (!callback.is_null()) | 23 if (!callback.is_null()) |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 113 |
113 void ServiceWorkerVersion::Shutdown() { | 114 void ServiceWorkerVersion::Shutdown() { |
114 is_shutdown_ = true; | 115 is_shutdown_ = true; |
115 registration_ = NULL; | 116 registration_ = NULL; |
116 if (embedded_worker_) { | 117 if (embedded_worker_) { |
117 embedded_worker_->RemoveObserver(this); | 118 embedded_worker_->RemoveObserver(this); |
118 embedded_worker_.reset(); | 119 embedded_worker_.reset(); |
119 } | 120 } |
120 } | 121 } |
121 | 122 |
| 123 ServiceWorkerVersionInfo ServiceWorkerVersion::GetInfo() { |
| 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 125 return ServiceWorkerVersionInfo(running_status(), |
| 126 status(), |
| 127 embedded_worker()->process_id(), |
| 128 embedded_worker()->thread_id()); |
| 129 } |
| 130 |
122 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { | 131 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { |
123 DCHECK(!is_shutdown_); | 132 DCHECK(!is_shutdown_); |
124 DCHECK(embedded_worker_); | 133 DCHECK(embedded_worker_); |
125 DCHECK(registration_); | 134 DCHECK(registration_); |
126 if (running_status() == RUNNING) { | 135 if (running_status() == RUNNING) { |
127 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); | 136 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); |
128 return; | 137 return; |
129 } | 138 } |
130 if (running_status() == STOPPING) { | 139 if (running_status() == STOPPING) { |
131 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED)); | 140 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED)); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 if (callback) { | 285 if (callback) { |
277 callback->Run(SERVICE_WORKER_OK, message); | 286 callback->Run(SERVICE_WORKER_OK, message); |
278 message_callbacks_.Remove(request_id); | 287 message_callbacks_.Remove(request_id); |
279 return; | 288 return; |
280 } | 289 } |
281 NOTREACHED() << "Got unexpected message: " << request_id | 290 NOTREACHED() << "Got unexpected message: " << request_id |
282 << " " << message.type(); | 291 << " " << message.type(); |
283 } | 292 } |
284 | 293 |
285 } // namespace content | 294 } // namespace content |
OLD | NEW |