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/renderer/service_worker/embedded_worker_dispatcher.h" | 5 #include "content/renderer/service_worker/embedded_worker_dispatcher.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
10 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
12 #include "content/child/child_process.h" | 13 #include "content/child/child_process.h" |
13 #include "content/child/thread_safe_sender.h" | 14 #include "content/child/thread_safe_sender.h" |
14 #include "content/child/worker_thread_registry.h" | 15 #include "content/child/worker_thread_registry.h" |
15 #include "content/common/devtools_messages.h" | 16 #include "content/common/devtools_messages.h" |
16 #include "content/common/service_worker/embedded_worker_messages.h" | 17 #include "content/common/service_worker/embedded_worker_messages.h" |
17 #include "content/public/common/content_client.h" | 18 #include "content/public/common/content_client.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 ? blink::WebEmbeddedWorkerStartData::PauseAfterDownload | 151 ? blink::WebEmbeddedWorkerStartData::PauseAfterDownload |
151 : blink::WebEmbeddedWorkerStartData::DontPauseAfterDownload; | 152 : blink::WebEmbeddedWorkerStartData::DontPauseAfterDownload; |
152 | 153 |
153 wrapper->worker()->startWorkerContext(start_data); | 154 wrapper->worker()->startWorkerContext(start_data); |
154 return wrapper; | 155 return wrapper; |
155 } | 156 } |
156 | 157 |
157 void EmbeddedWorkerDispatcher::RegisterWorker( | 158 void EmbeddedWorkerDispatcher::RegisterWorker( |
158 int embedded_worker_id, | 159 int embedded_worker_id, |
159 std::unique_ptr<WorkerWrapper> wrapper) { | 160 std::unique_ptr<WorkerWrapper> wrapper) { |
160 workers_.AddWithID(wrapper.release(), embedded_worker_id); | 161 workers_.AddWithID(std::move(wrapper), embedded_worker_id); |
161 } | 162 } |
162 | 163 |
163 void EmbeddedWorkerDispatcher::UnregisterWorker(int embedded_worker_id) { | 164 void EmbeddedWorkerDispatcher::UnregisterWorker(int embedded_worker_id) { |
164 if (ContainsKey(stop_worker_times_, embedded_worker_id)) { | 165 if (ContainsKey(stop_worker_times_, embedded_worker_id)) { |
165 base::TimeTicks stop_time = stop_worker_times_[embedded_worker_id]; | 166 base::TimeTicks stop_time = stop_worker_times_[embedded_worker_id]; |
166 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.TerminateThread.Time", | 167 UMA_HISTOGRAM_MEDIUM_TIMES("ServiceWorker.TerminateThread.Time", |
167 base::TimeTicks::Now() - stop_time); | 168 base::TimeTicks::Now() - stop_time); |
168 stop_worker_times_.erase(embedded_worker_id); | 169 stop_worker_times_.erase(embedded_worker_id); |
169 } | 170 } |
170 workers_.Remove(embedded_worker_id); | 171 workers_.Remove(embedded_worker_id); |
171 } | 172 } |
172 | 173 |
173 void EmbeddedWorkerDispatcher::RecordStopWorkerTimer(int embedded_worker_id) { | 174 void EmbeddedWorkerDispatcher::RecordStopWorkerTimer(int embedded_worker_id) { |
174 WorkerWrapper* wrapper = workers_.Lookup(embedded_worker_id); | 175 WorkerWrapper* wrapper = workers_.Lookup(embedded_worker_id); |
175 DCHECK(wrapper); | 176 DCHECK(wrapper); |
176 // This should eventually call WorkerContextDestroyed. (We may need to post | 177 // This should eventually call WorkerContextDestroyed. (We may need to post |
177 // a delayed task to forcibly abort the worker context if we find it | 178 // a delayed task to forcibly abort the worker context if we find it |
178 // necessary) | 179 // necessary) |
179 stop_worker_times_[embedded_worker_id] = base::TimeTicks::Now(); | 180 stop_worker_times_[embedded_worker_id] = base::TimeTicks::Now(); |
180 } | 181 } |
181 | 182 |
182 } // namespace content | 183 } // namespace content |
OLD | NEW |