| 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" |
| 11 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 11 #include "content/common/service_worker/embedded_worker_messages.h" | 12 #include "content/common/service_worker/embedded_worker_messages.h" |
| 12 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 13 #include "content/public/browser/render_process_host.h" | 14 #include "content/public/browser/render_process_host.h" |
| 14 #include "ipc/ipc_message.h" | 15 #include "ipc/ipc_message.h" |
| 15 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 16 | 17 |
| 17 namespace content { | 18 namespace content { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 base::Bind(callback, worker_devtools_agent_route_id, pause_on_start)); | 86 base::Bind(callback, worker_devtools_agent_route_id, pause_on_start)); |
| 86 } | 87 } |
| 87 | 88 |
| 88 } // namespace | 89 } // namespace |
| 89 | 90 |
| 90 EmbeddedWorkerInstance::~EmbeddedWorkerInstance() { | 91 EmbeddedWorkerInstance::~EmbeddedWorkerInstance() { |
| 91 if (status_ == STARTING || status_ == RUNNING) | 92 if (status_ == STARTING || status_ == RUNNING) |
| 92 Stop(); | 93 Stop(); |
| 93 if (worker_devtools_agent_route_id_ != MSG_ROUTING_NONE) | 94 if (worker_devtools_agent_route_id_ != MSG_ROUTING_NONE) |
| 94 NotifyWorkerDestroyed(process_id_, worker_devtools_agent_route_id_); | 95 NotifyWorkerDestroyed(process_id_, worker_devtools_agent_route_id_); |
| 95 if (context_ && process_id_ != -1) | 96 if (context_ && process_id_ != -1) { |
| 96 context_->process_manager()->ReleaseWorkerProcess(embedded_worker_id_); | 97 context_->wrapper()->process_manager()->ReleaseWorkerProcess( |
| 98 embedded_worker_id_); |
| 99 } |
| 97 registry_->RemoveWorker(process_id_, embedded_worker_id_); | 100 registry_->RemoveWorker(process_id_, embedded_worker_id_); |
| 98 } | 101 } |
| 99 | 102 |
| 100 void EmbeddedWorkerInstance::Start(int64 service_worker_version_id, | 103 void EmbeddedWorkerInstance::Start(int64 service_worker_version_id, |
| 101 const GURL& scope, | 104 const GURL& scope, |
| 102 const GURL& script_url, | 105 const GURL& script_url, |
| 103 const std::vector<int>& possible_process_ids, | 106 const std::vector<int>& possible_process_ids, |
| 104 const StatusCallback& callback) { | 107 const StatusCallback& callback) { |
| 105 if (!context_) { | 108 if (!context_) { |
| 106 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 109 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
| 107 return; | 110 return; |
| 108 } | 111 } |
| 109 DCHECK(status_ == STOPPED); | 112 DCHECK(status_ == STOPPED); |
| 110 status_ = STARTING; | 113 status_ = STARTING; |
| 111 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params( | 114 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params( |
| 112 new EmbeddedWorkerMsg_StartWorker_Params()); | 115 new EmbeddedWorkerMsg_StartWorker_Params()); |
| 113 params->embedded_worker_id = embedded_worker_id_; | 116 params->embedded_worker_id = embedded_worker_id_; |
| 114 params->service_worker_version_id = service_worker_version_id; | 117 params->service_worker_version_id = service_worker_version_id; |
| 115 params->scope = scope; | 118 params->scope = scope; |
| 116 params->script_url = script_url; | 119 params->script_url = script_url; |
| 117 params->worker_devtools_agent_route_id = MSG_ROUTING_NONE; | 120 params->worker_devtools_agent_route_id = MSG_ROUTING_NONE; |
| 118 params->pause_on_start = false; | 121 params->pause_on_start = false; |
| 119 context_->process_manager()->AllocateWorkerProcess( | 122 context_->wrapper()->process_manager()->AllocateWorkerProcess( |
| 120 embedded_worker_id_, | 123 embedded_worker_id_, |
| 121 SortProcesses(possible_process_ids), | 124 SortProcesses(possible_process_ids), |
| 122 script_url, | 125 script_url, |
| 123 base::Bind(&EmbeddedWorkerInstance::RunProcessAllocated, | 126 base::Bind(&EmbeddedWorkerInstance::RunProcessAllocated, |
| 124 weak_factory_.GetWeakPtr(), | 127 weak_factory_.GetWeakPtr(), |
| 125 context_, | 128 context_, |
| 126 base::Passed(¶ms), | 129 base::Passed(¶ms), |
| 127 callback)); | 130 callback)); |
| 128 } | 131 } |
| 129 | 132 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 const EmbeddedWorkerInstance::StatusCallback& callback, | 185 const EmbeddedWorkerInstance::StatusCallback& callback, |
| 183 ServiceWorkerStatusCode status, | 186 ServiceWorkerStatusCode status, |
| 184 int process_id) { | 187 int process_id) { |
| 185 if (!context) { | 188 if (!context) { |
| 186 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 189 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
| 187 return; | 190 return; |
| 188 } | 191 } |
| 189 if (!instance) { | 192 if (!instance) { |
| 190 if (status == SERVICE_WORKER_OK) { | 193 if (status == SERVICE_WORKER_OK) { |
| 191 // We only have a process allocated if the status is OK. | 194 // We only have a process allocated if the status is OK. |
| 192 context->process_manager()->ReleaseWorkerProcess( | 195 context->wrapper()->process_manager()->ReleaseWorkerProcess( |
| 193 params->embedded_worker_id); | 196 params->embedded_worker_id); |
| 194 } | 197 } |
| 195 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 198 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
| 196 return; | 199 return; |
| 197 } | 200 } |
| 198 instance->ProcessAllocated(params.Pass(), callback, process_id, status); | 201 instance->ProcessAllocated(params.Pass(), callback, process_id, status); |
| 199 } | 202 } |
| 200 | 203 |
| 201 void EmbeddedWorkerInstance::ProcessAllocated( | 204 void EmbeddedWorkerInstance::ProcessAllocated( |
| 202 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, | 205 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 return; | 249 return; |
| 247 DCHECK(status_ == STARTING); | 250 DCHECK(status_ == STARTING); |
| 248 status_ = RUNNING; | 251 status_ = RUNNING; |
| 249 thread_id_ = thread_id; | 252 thread_id_ = thread_id; |
| 250 FOR_EACH_OBSERVER(Listener, listener_list_, OnStarted()); | 253 FOR_EACH_OBSERVER(Listener, listener_list_, OnStarted()); |
| 251 } | 254 } |
| 252 | 255 |
| 253 void EmbeddedWorkerInstance::OnStopped() { | 256 void EmbeddedWorkerInstance::OnStopped() { |
| 254 if (worker_devtools_agent_route_id_ != MSG_ROUTING_NONE) | 257 if (worker_devtools_agent_route_id_ != MSG_ROUTING_NONE) |
| 255 NotifyWorkerDestroyed(process_id_, worker_devtools_agent_route_id_); | 258 NotifyWorkerDestroyed(process_id_, worker_devtools_agent_route_id_); |
| 256 if (context_) | 259 if (context_) { |
| 257 context_->process_manager()->ReleaseWorkerProcess(embedded_worker_id_); | 260 context_->wrapper()->process_manager()->ReleaseWorkerProcess( |
| 261 embedded_worker_id_); |
| 262 } |
| 258 status_ = STOPPED; | 263 status_ = STOPPED; |
| 259 process_id_ = -1; | 264 process_id_ = -1; |
| 260 thread_id_ = -1; | 265 thread_id_ = -1; |
| 261 worker_devtools_agent_route_id_ = MSG_ROUTING_NONE; | 266 worker_devtools_agent_route_id_ = MSG_ROUTING_NONE; |
| 262 FOR_EACH_OBSERVER(Listener, listener_list_, OnStopped()); | 267 FOR_EACH_OBSERVER(Listener, listener_list_, OnStopped()); |
| 263 } | 268 } |
| 264 | 269 |
| 265 bool EmbeddedWorkerInstance::OnMessageReceived(const IPC::Message& message) { | 270 bool EmbeddedWorkerInstance::OnMessageReceived(const IPC::Message& message) { |
| 266 ListenerList::Iterator it(listener_list_); | 271 ListenerList::Iterator it(listener_list_); |
| 267 while (Listener* listener = it.GetNext()) { | 272 while (Listener* listener = it.GetNext()) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 // Sort descending by the reference count. | 324 // Sort descending by the reference count. |
| 320 std::sort(counted.begin(), counted.end(), SecondGreater()); | 325 std::sort(counted.begin(), counted.end(), SecondGreater()); |
| 321 | 326 |
| 322 std::vector<int> result(counted.size()); | 327 std::vector<int> result(counted.size()); |
| 323 for (size_t i = 0; i < counted.size(); ++i) | 328 for (size_t i = 0; i < counted.size(); ++i) |
| 324 result[i] = counted[i].first; | 329 result[i] = counted[i].first; |
| 325 return result; | 330 return result; |
| 326 } | 331 } |
| 327 | 332 |
| 328 } // namespace content | 333 } // namespace content |
| OLD | NEW |