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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 109 |
109 void ServiceWorkerVersion::Shutdown() { | 110 void ServiceWorkerVersion::Shutdown() { |
110 is_shutdown_ = true; | 111 is_shutdown_ = true; |
111 registration_ = NULL; | 112 registration_ = NULL; |
112 if (embedded_worker_) { | 113 if (embedded_worker_) { |
113 embedded_worker_->RemoveObserver(this); | 114 embedded_worker_->RemoveObserver(this); |
114 embedded_worker_.reset(); | 115 embedded_worker_.reset(); |
115 } | 116 } |
116 } | 117 } |
117 | 118 |
| 119 ServiceWorkerVersionInfo ServiceWorkerVersion::GetInfo( |
| 120 const ServiceWorkerVersion* version) { |
| 121 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 122 if (!version) |
| 123 return ServiceWorkerVersionInfo(); |
| 124 return ServiceWorkerVersionInfo(version->status(), |
| 125 version->embedded_worker()->process_id(), |
| 126 version->embedded_worker()->thread_id()); |
| 127 } |
| 128 |
118 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { | 129 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { |
119 DCHECK(!is_shutdown_); | 130 DCHECK(!is_shutdown_); |
120 DCHECK(embedded_worker_); | 131 DCHECK(embedded_worker_); |
121 DCHECK(registration_); | 132 DCHECK(registration_); |
122 if (status() == RUNNING) { | 133 if (status() == RUNNING) { |
123 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); | 134 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); |
124 return; | 135 return; |
125 } | 136 } |
126 if (status() == STOPPING) { | 137 if (status() == STOPPING) { |
127 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED)); | 138 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED)); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 if (callback) { | 269 if (callback) { |
259 callback->Run(SERVICE_WORKER_OK, message); | 270 callback->Run(SERVICE_WORKER_OK, message); |
260 message_callbacks_.Remove(request_id); | 271 message_callbacks_.Remove(request_id); |
261 return; | 272 return; |
262 } | 273 } |
263 NOTREACHED() << "Got unexpected message: " << request_id | 274 NOTREACHED() << "Got unexpected message: " << request_id |
264 << " " << message.type(); | 275 << " " << message.type(); |
265 } | 276 } |
266 | 277 |
267 } // namespace content | 278 } // namespace content |
OLD | NEW |