| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 const StatusCallback& callback) { | 140 const StatusCallback& callback) { |
| 141 if (!context_) { | 141 if (!context_) { |
| 142 callback.Run(SERVICE_WORKER_ERROR_ABORT); | 142 callback.Run(SERVICE_WORKER_ERROR_ABORT); |
| 143 return; | 143 return; |
| 144 } | 144 } |
| 145 DCHECK(status_ == STOPPED); | 145 DCHECK(status_ == STOPPED); |
| 146 start_timing_ = base::TimeTicks::Now(); | 146 start_timing_ = base::TimeTicks::Now(); |
| 147 status_ = STARTING; | 147 status_ = STARTING; |
| 148 starting_phase_ = ALLOCATING_PROCESS; | 148 starting_phase_ = ALLOCATING_PROCESS; |
| 149 network_accessed_for_script_ = false; | 149 network_accessed_for_script_ = false; |
| 150 FOR_EACH_OBSERVER(Listener, listener_list_, OnStarting()); |
| 150 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params( | 151 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params( |
| 151 new EmbeddedWorkerMsg_StartWorker_Params()); | 152 new EmbeddedWorkerMsg_StartWorker_Params()); |
| 152 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", | 153 TRACE_EVENT_ASYNC_BEGIN2("ServiceWorker", |
| 153 "EmbeddedWorkerInstance::ProcessAllocate", | 154 "EmbeddedWorkerInstance::ProcessAllocate", |
| 154 params.get(), | 155 params.get(), |
| 155 "Scope", scope.spec(), | 156 "Scope", scope.spec(), |
| 156 "Script URL", script_url.spec()); | 157 "Script URL", script_url.spec()); |
| 157 params->embedded_worker_id = embedded_worker_id_; | 158 params->embedded_worker_id = embedded_worker_id_; |
| 158 params->service_worker_version_id = service_worker_version_id; | 159 params->service_worker_version_id = service_worker_version_id; |
| 159 params->scope = scope; | 160 params->scope = scope; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 170 weak_factory_.GetWeakPtr(), | 171 weak_factory_.GetWeakPtr(), |
| 171 context_, | 172 context_, |
| 172 base::Passed(¶ms), | 173 base::Passed(¶ms), |
| 173 callback)); | 174 callback)); |
| 174 } | 175 } |
| 175 | 176 |
| 176 ServiceWorkerStatusCode EmbeddedWorkerInstance::Stop() { | 177 ServiceWorkerStatusCode EmbeddedWorkerInstance::Stop() { |
| 177 DCHECK(status_ == STARTING || status_ == RUNNING) << status_; | 178 DCHECK(status_ == STARTING || status_ == RUNNING) << status_; |
| 178 ServiceWorkerStatusCode status = | 179 ServiceWorkerStatusCode status = |
| 179 registry_->StopWorker(process_id_, embedded_worker_id_); | 180 registry_->StopWorker(process_id_, embedded_worker_id_); |
| 180 if (status == SERVICE_WORKER_OK) | 181 if (status == SERVICE_WORKER_OK) { |
| 181 status_ = STOPPING; | 182 status_ = STOPPING; |
| 183 FOR_EACH_OBSERVER(Listener, listener_list_, OnStopping()); |
| 184 } |
| 182 return status; | 185 return status; |
| 183 } | 186 } |
| 184 | 187 |
| 185 void EmbeddedWorkerInstance::StopIfIdle() { | 188 void EmbeddedWorkerInstance::StopIfIdle() { |
| 186 if (devtools_attached_) { | 189 if (devtools_attached_) { |
| 187 if (devtools_proxy_) | 190 if (devtools_proxy_) |
| 188 devtools_proxy_->NotifyWorkerStopIgnored(); | 191 devtools_proxy_->NotifyWorkerStopIgnored(); |
| 189 return; | 192 return; |
| 190 } | 193 } |
| 191 Stop(); | 194 Stop(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, | 254 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, |
| 252 const StatusCallback& callback, | 255 const StatusCallback& callback, |
| 253 int process_id, | 256 int process_id, |
| 254 ServiceWorkerStatusCode status) { | 257 ServiceWorkerStatusCode status) { |
| 255 DCHECK_EQ(process_id_, -1); | 258 DCHECK_EQ(process_id_, -1); |
| 256 TRACE_EVENT_ASYNC_END1("ServiceWorker", | 259 TRACE_EVENT_ASYNC_END1("ServiceWorker", |
| 257 "EmbeddedWorkerInstance::ProcessAllocate", | 260 "EmbeddedWorkerInstance::ProcessAllocate", |
| 258 params.get(), | 261 params.get(), |
| 259 "Status", status); | 262 "Status", status); |
| 260 if (status != SERVICE_WORKER_OK) { | 263 if (status != SERVICE_WORKER_OK) { |
| 264 Status old_status = status_; |
| 261 status_ = STOPPED; | 265 status_ = STOPPED; |
| 262 callback.Run(status); | 266 callback.Run(status); |
| 267 FOR_EACH_OBSERVER(Listener, listener_list_, OnStopped(old_status)); |
| 263 return; | 268 return; |
| 264 } | 269 } |
| 265 const int64 service_worker_version_id = params->service_worker_version_id; | 270 const int64 service_worker_version_id = params->service_worker_version_id; |
| 266 process_id_ = process_id; | 271 process_id_ = process_id; |
| 267 GURL script_url(params->script_url); | 272 GURL script_url(params->script_url); |
| 268 | 273 |
| 269 // Register this worker to DevToolsManager on UI thread, then continue to | 274 // Register this worker to DevToolsManager on UI thread, then continue to |
| 270 // call SendStartWorker on IO thread. | 275 // call SendStartWorker on IO thread. |
| 271 starting_phase_ = REGISTERING_TO_DEVTOOLS; | 276 starting_phase_ = REGISTERING_TO_DEVTOOLS; |
| 272 BrowserThread::PostTask( | 277 BrowserThread::PostTask( |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 case SCRIPT_EVALUATED: | 484 case SCRIPT_EVALUATED: |
| 480 return "Script evaluated"; | 485 return "Script evaluated"; |
| 481 case STARTING_PHASE_MAX_VALUE: | 486 case STARTING_PHASE_MAX_VALUE: |
| 482 NOTREACHED(); | 487 NOTREACHED(); |
| 483 } | 488 } |
| 484 NOTREACHED() << phase; | 489 NOTREACHED() << phase; |
| 485 return std::string(); | 490 return std::string(); |
| 486 } | 491 } |
| 487 | 492 |
| 488 } // namespace content | 493 } // namespace content |
| OLD | NEW |