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 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 121 return ServiceWorkerVersionInfo(status(), |
| 122 embedded_worker()->process_id(), |
| 123 embedded_worker()->thread_id()); |
| 124 } |
| 125 |
118 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { | 126 void ServiceWorkerVersion::StartWorker(const StatusCallback& callback) { |
119 DCHECK(!is_shutdown_); | 127 DCHECK(!is_shutdown_); |
120 DCHECK(embedded_worker_); | 128 DCHECK(embedded_worker_); |
121 DCHECK(registration_); | 129 DCHECK(registration_); |
122 if (status() == RUNNING) { | 130 if (status() == RUNNING) { |
123 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); | 131 RunSoon(base::Bind(callback, SERVICE_WORKER_OK)); |
124 return; | 132 return; |
125 } | 133 } |
126 if (status() == STOPPING) { | 134 if (status() == STOPPING) { |
127 RunSoon(base::Bind(callback, SERVICE_WORKER_ERROR_START_WORKER_FAILED)); | 135 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) { | 266 if (callback) { |
259 callback->Run(SERVICE_WORKER_OK, message); | 267 callback->Run(SERVICE_WORKER_OK, message); |
260 message_callbacks_.Remove(request_id); | 268 message_callbacks_.Remove(request_id); |
261 return; | 269 return; |
262 } | 270 } |
263 NOTREACHED() << "Got unexpected message: " << request_id | 271 NOTREACHED() << "Got unexpected message: " << request_id |
264 << " " << message.type(); | 272 << " " << message.type(); |
265 } | 273 } |
266 | 274 |
267 } // namespace content | 275 } // namespace content |
OLD | NEW |