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/embedded_worker_instance.h" | 5 #include "content/browser/service_worker/embedded_worker_instance.h" |
6 | 6 |
7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
8 #include "content/browser/devtools/embedded_worker_devtools_manager.h" | 8 #include "content/browser/devtools/embedded_worker_devtools_manager.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" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 } | 86 } |
87 | 87 |
88 } // namespace | 88 } // namespace |
89 | 89 |
90 EmbeddedWorkerInstance::~EmbeddedWorkerInstance() { | 90 EmbeddedWorkerInstance::~EmbeddedWorkerInstance() { |
91 if (status_ == STARTING || status_ == RUNNING) | 91 if (status_ == STARTING || status_ == RUNNING) |
92 Stop(); | 92 Stop(); |
93 if (worker_devtools_agent_route_id_ != MSG_ROUTING_NONE) | 93 if (worker_devtools_agent_route_id_ != MSG_ROUTING_NONE) |
94 NotifyWorkerDestroyed(process_id_, worker_devtools_agent_route_id_); | 94 NotifyWorkerDestroyed(process_id_, worker_devtools_agent_route_id_); |
95 if (context_ && process_id_ != -1) | 95 if (context_ && process_id_ != -1) |
96 context_->process_manager()->ReleaseWorkerProcess(process_id_); | 96 context_->process_manager()->ReleaseWorkerProcess(embedded_worker_id_); |
97 registry_->RemoveWorker(process_id_, embedded_worker_id_); | 97 registry_->RemoveWorker(process_id_, embedded_worker_id_); |
98 } | 98 } |
99 | 99 |
100 void EmbeddedWorkerInstance::Start(int64 service_worker_version_id, | 100 void EmbeddedWorkerInstance::Start(int64 service_worker_version_id, |
101 const GURL& scope, | 101 const GURL& scope, |
102 const GURL& script_url, | 102 const GURL& script_url, |
103 const std::vector<int>& possible_process_ids, | 103 const std::vector<int>& possible_process_ids, |
104 const StatusCallback& callback) { | 104 const StatusCallback& callback) { |
105 if (!context_) { | 105 if (!context_) { |
106 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 106 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
107 return; | 107 return; |
108 } | 108 } |
109 DCHECK(status_ == STOPPED); | 109 DCHECK(status_ == STOPPED); |
110 status_ = STARTING; | 110 status_ = STARTING; |
111 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params( | 111 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params( |
112 new EmbeddedWorkerMsg_StartWorker_Params()); | 112 new EmbeddedWorkerMsg_StartWorker_Params()); |
113 params->embedded_worker_id = embedded_worker_id_; | 113 params->embedded_worker_id = embedded_worker_id_; |
114 params->service_worker_version_id = service_worker_version_id; | 114 params->service_worker_version_id = service_worker_version_id; |
115 params->scope = scope; | 115 params->scope = scope; |
116 params->script_url = script_url; | 116 params->script_url = script_url; |
117 params->worker_devtools_agent_route_id = MSG_ROUTING_NONE; | 117 params->worker_devtools_agent_route_id = MSG_ROUTING_NONE; |
118 params->pause_on_start = false; | 118 params->pause_on_start = false; |
119 context_->process_manager()->AllocateWorkerProcess( | 119 context_->process_manager()->AllocateWorkerProcess( |
| 120 embedded_worker_id_, |
120 SortProcesses(possible_process_ids), | 121 SortProcesses(possible_process_ids), |
121 script_url, | 122 script_url, |
122 base::Bind(&EmbeddedWorkerInstance::RunProcessAllocated, | 123 base::Bind(&EmbeddedWorkerInstance::RunProcessAllocated, |
123 weak_factory_.GetWeakPtr(), | 124 weak_factory_.GetWeakPtr(), |
124 context_, | 125 context_, |
125 base::Passed(¶ms), | 126 base::Passed(¶ms), |
126 callback)); | 127 callback)); |
127 } | 128 } |
128 | 129 |
129 ServiceWorkerStatusCode EmbeddedWorkerInstance::Stop() { | 130 ServiceWorkerStatusCode EmbeddedWorkerInstance::Stop() { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 base::WeakPtr<ServiceWorkerContextCore> context, | 180 base::WeakPtr<ServiceWorkerContextCore> context, |
180 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, | 181 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, |
181 const EmbeddedWorkerInstance::StatusCallback& callback, | 182 const EmbeddedWorkerInstance::StatusCallback& callback, |
182 ServiceWorkerStatusCode status, | 183 ServiceWorkerStatusCode status, |
183 int process_id) { | 184 int process_id) { |
184 if (!context) { | 185 if (!context) { |
185 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 186 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
186 return; | 187 return; |
187 } | 188 } |
188 if (!instance) { | 189 if (!instance) { |
189 context->process_manager()->ReleaseWorkerProcess(process_id); | 190 context->process_manager()->ReleaseWorkerProcess( |
| 191 instance->embedded_worker_id_); |
190 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 192 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
191 return; | 193 return; |
192 } | 194 } |
193 instance->ProcessAllocated(params.Pass(), callback, process_id, status); | 195 instance->ProcessAllocated(params.Pass(), callback, process_id, status); |
194 } | 196 } |
195 | 197 |
196 void EmbeddedWorkerInstance::ProcessAllocated( | 198 void EmbeddedWorkerInstance::ProcessAllocated( |
197 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, | 199 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, |
198 const StatusCallback& callback, | 200 const StatusCallback& callback, |
199 int process_id, | 201 int process_id, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 DCHECK(status_ == STARTING); | 244 DCHECK(status_ == STARTING); |
243 status_ = RUNNING; | 245 status_ = RUNNING; |
244 thread_id_ = thread_id; | 246 thread_id_ = thread_id; |
245 FOR_EACH_OBSERVER(Listener, listener_list_, OnStarted()); | 247 FOR_EACH_OBSERVER(Listener, listener_list_, OnStarted()); |
246 } | 248 } |
247 | 249 |
248 void EmbeddedWorkerInstance::OnStopped() { | 250 void EmbeddedWorkerInstance::OnStopped() { |
249 if (worker_devtools_agent_route_id_ != MSG_ROUTING_NONE) | 251 if (worker_devtools_agent_route_id_ != MSG_ROUTING_NONE) |
250 NotifyWorkerDestroyed(process_id_, worker_devtools_agent_route_id_); | 252 NotifyWorkerDestroyed(process_id_, worker_devtools_agent_route_id_); |
251 if (context_) | 253 if (context_) |
252 context_->process_manager()->ReleaseWorkerProcess(process_id_); | 254 context_->process_manager()->ReleaseWorkerProcess(embedded_worker_id_); |
253 status_ = STOPPED; | 255 status_ = STOPPED; |
254 process_id_ = -1; | 256 process_id_ = -1; |
255 thread_id_ = -1; | 257 thread_id_ = -1; |
256 worker_devtools_agent_route_id_ = MSG_ROUTING_NONE; | 258 worker_devtools_agent_route_id_ = MSG_ROUTING_NONE; |
257 FOR_EACH_OBSERVER(Listener, listener_list_, OnStopped()); | 259 FOR_EACH_OBSERVER(Listener, listener_list_, OnStopped()); |
258 } | 260 } |
259 | 261 |
260 bool EmbeddedWorkerInstance::OnMessageReceived(const IPC::Message& message) { | 262 bool EmbeddedWorkerInstance::OnMessageReceived(const IPC::Message& message) { |
261 ListenerList::Iterator it(listener_list_); | 263 ListenerList::Iterator it(listener_list_); |
262 while (Listener* listener = it.GetNext()) { | 264 while (Listener* listener = it.GetNext()) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 // Sort descending by the reference count. | 316 // Sort descending by the reference count. |
315 std::sort(counted.begin(), counted.end(), SecondGreater()); | 317 std::sort(counted.begin(), counted.end(), SecondGreater()); |
316 | 318 |
317 std::vector<int> result(counted.size()); | 319 std::vector<int> result(counted.size()); |
318 for (size_t i = 0; i < counted.size(); ++i) | 320 for (size_t i = 0; i < counted.size(); ++i) |
319 result[i] = counted[i].first; | 321 result[i] = counted[i].first; |
320 return result; | 322 return result; |
321 } | 323 } |
322 | 324 |
323 } // namespace content | 325 } // namespace content |
OLD | NEW |