Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(576)

Side by Side Diff: content/browser/service_worker/embedded_worker_instance.cc

Issue 761923004: Keep alive ServiceWorkers when devtools is attached (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ASSERT_TRUE -> DCHECK :( Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 16 matching lines...) Expand all
27 struct SecondGreater { 27 struct SecondGreater {
28 template <typename Value> 28 template <typename Value>
29 bool operator()(const Value& lhs, const Value& rhs) { 29 bool operator()(const Value& lhs, const Value& rhs) {
30 return lhs.second > rhs.second; 30 return lhs.second > rhs.second;
31 } 31 }
32 }; 32 };
33 33
34 void NotifyWorkerReadyForInspection(int worker_process_id, 34 void NotifyWorkerReadyForInspection(int worker_process_id,
35 int worker_route_id) { 35 int worker_route_id) {
36 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 36 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
37 BrowserThread::PostTask(BrowserThread::UI, 38 BrowserThread::PostTask(BrowserThread::UI,
38 FROM_HERE, 39 FROM_HERE,
39 base::Bind(NotifyWorkerReadyForInspection, 40 base::Bind(NotifyWorkerReadyForInspection,
40 worker_process_id, 41 worker_process_id,
41 worker_route_id)); 42 worker_route_id));
42 return; 43 return;
43 } 44 }
44 EmbeddedWorkerDevToolsManager::GetInstance()->WorkerReadyForInspection( 45 EmbeddedWorkerDevToolsManager::GetInstance()->WorkerReadyForInspection(
45 worker_process_id, worker_route_id); 46 worker_process_id, worker_route_id);
46 } 47 }
47 48
48 void NotifyWorkerDestroyed(int worker_process_id, int worker_route_id) { 49 void NotifyWorkerDestroyed(int worker_process_id, int worker_route_id) {
49 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 50 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
50 BrowserThread::PostTask( 52 BrowserThread::PostTask(
51 BrowserThread::UI, 53 BrowserThread::UI,
52 FROM_HERE, 54 FROM_HERE,
53 base::Bind(NotifyWorkerDestroyed, worker_process_id, worker_route_id)); 55 base::Bind(NotifyWorkerDestroyed, worker_process_id, worker_route_id));
54 return; 56 return;
55 } 57 }
56 EmbeddedWorkerDevToolsManager::GetInstance()->WorkerDestroyed( 58 EmbeddedWorkerDevToolsManager::GetInstance()->WorkerDestroyed(
57 worker_process_id, worker_route_id); 59 worker_process_id, worker_route_id);
58 } 60 }
59 61
62 void NotifyWorkerStopIgnored(int worker_process_id, int worker_route_id) {
63 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
65 BrowserThread::PostTask(BrowserThread::UI,
66 FROM_HERE,
67 base::Bind(NotifyWorkerStopIgnored,
68 worker_process_id,
69 worker_route_id));
70 return;
71 }
72 EmbeddedWorkerDevToolsManager::GetInstance()->WorkerStopIgnored(
73 worker_process_id, worker_route_id);
74 }
75
76
60 void RegisterToWorkerDevToolsManager( 77 void RegisterToWorkerDevToolsManager(
61 int process_id, 78 int process_id,
62 const ServiceWorkerContextCore* service_worker_context, 79 const ServiceWorkerContextCore* service_worker_context,
63 base::WeakPtr<ServiceWorkerContextCore> service_worker_context_weak, 80 base::WeakPtr<ServiceWorkerContextCore> service_worker_context_weak,
64 int64 service_worker_version_id, 81 int64 service_worker_version_id,
65 const GURL& url, 82 const GURL& url,
66 const base::Callback<void(int worker_devtools_agent_route_id, 83 const base::Callback<void(int worker_devtools_agent_route_id,
67 bool wait_for_debugger)>& callback) { 84 bool wait_for_debugger)>& callback) {
68 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 85 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
69 BrowserThread::PostTask(BrowserThread::UI, 87 BrowserThread::PostTask(BrowserThread::UI,
70 FROM_HERE, 88 FROM_HERE,
71 base::Bind(RegisterToWorkerDevToolsManager, 89 base::Bind(RegisterToWorkerDevToolsManager,
72 process_id, 90 process_id,
73 service_worker_context, 91 service_worker_context,
74 service_worker_context_weak, 92 service_worker_context_weak,
75 service_worker_version_id, 93 service_worker_version_id,
76 url, 94 url,
77 callback)); 95 callback));
78 return; 96 return;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 166
149 ServiceWorkerStatusCode EmbeddedWorkerInstance::Stop() { 167 ServiceWorkerStatusCode EmbeddedWorkerInstance::Stop() {
150 DCHECK(status_ == STARTING || status_ == RUNNING); 168 DCHECK(status_ == STARTING || status_ == RUNNING);
151 ServiceWorkerStatusCode status = 169 ServiceWorkerStatusCode status =
152 registry_->StopWorker(process_id_, embedded_worker_id_); 170 registry_->StopWorker(process_id_, embedded_worker_id_);
153 if (status == SERVICE_WORKER_OK) 171 if (status == SERVICE_WORKER_OK)
154 status_ = STOPPING; 172 status_ = STOPPING;
155 return status; 173 return status;
156 } 174 }
157 175
176 void EmbeddedWorkerInstance::StopIfIdle() {
177 if (devtools_attached_) {
178 NotifyWorkerStopIgnored(process_id_, worker_devtools_agent_route_id_);
179 return;
180 }
181 Stop();
182 }
183
158 void EmbeddedWorkerInstance::ResumeAfterDownload() { 184 void EmbeddedWorkerInstance::ResumeAfterDownload() {
159 DCHECK_EQ(STARTING, status_); 185 DCHECK_EQ(STARTING, status_);
160 registry_->Send( 186 registry_->Send(
161 process_id_, 187 process_id_,
162 new EmbeddedWorkerMsg_ResumeAfterDownload(embedded_worker_id_)); 188 new EmbeddedWorkerMsg_ResumeAfterDownload(embedded_worker_id_));
163 } 189 }
164 190
165 ServiceWorkerStatusCode EmbeddedWorkerInstance::SendMessage( 191 ServiceWorkerStatusCode EmbeddedWorkerInstance::SendMessage(
166 const IPC::Message& message) { 192 const IPC::Message& message) {
167 DCHECK_NE(kInvalidEmbeddedWorkerThreadId, thread_id_); 193 DCHECK_NE(kInvalidEmbeddedWorkerThreadId, thread_id_);
168 if (status_ != RUNNING && status_ != STARTING) 194 if (status_ != RUNNING && status_ != STARTING)
169 return SERVICE_WORKER_ERROR_IPC_FAILED; 195 return SERVICE_WORKER_ERROR_IPC_FAILED;
170 return registry_->Send(process_id_, 196 return registry_->Send(process_id_,
171 new EmbeddedWorkerContextMsg_MessageToWorker( 197 new EmbeddedWorkerContextMsg_MessageToWorker(
172 thread_id_, embedded_worker_id_, message)); 198 thread_id_, embedded_worker_id_, message));
173 } 199 }
174 200
175 EmbeddedWorkerInstance::EmbeddedWorkerInstance( 201 EmbeddedWorkerInstance::EmbeddedWorkerInstance(
176 base::WeakPtr<ServiceWorkerContextCore> context, 202 base::WeakPtr<ServiceWorkerContextCore> context,
177 int embedded_worker_id) 203 int embedded_worker_id)
178 : context_(context), 204 : context_(context),
179 registry_(context->embedded_worker_registry()), 205 registry_(context->embedded_worker_registry()),
180 embedded_worker_id_(embedded_worker_id), 206 embedded_worker_id_(embedded_worker_id),
181 status_(STOPPED), 207 status_(STOPPED),
182 process_id_(-1), 208 process_id_(-1),
183 thread_id_(kInvalidEmbeddedWorkerThreadId), 209 thread_id_(kInvalidEmbeddedWorkerThreadId),
184 worker_devtools_agent_route_id_(MSG_ROUTING_NONE), 210 worker_devtools_agent_route_id_(MSG_ROUTING_NONE),
211 devtools_attached_(false),
185 weak_factory_(this) { 212 weak_factory_(this) {
186 } 213 }
187 214
188 // static 215 // static
189 void EmbeddedWorkerInstance::RunProcessAllocated( 216 void EmbeddedWorkerInstance::RunProcessAllocated(
190 base::WeakPtr<EmbeddedWorkerInstance> instance, 217 base::WeakPtr<EmbeddedWorkerInstance> instance,
191 base::WeakPtr<ServiceWorkerContextCore> context, 218 base::WeakPtr<ServiceWorkerContextCore> context,
192 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params, 219 scoped_ptr<EmbeddedWorkerMsg_StartWorker_Params> params,
193 const EmbeddedWorkerInstance::StatusCallback& callback, 220 const EmbeddedWorkerInstance::StatusCallback& callback,
194 ServiceWorkerStatusCode status, 221 ServiceWorkerStatusCode status,
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 375
349 void EmbeddedWorkerInstance::AddListener(Listener* listener) { 376 void EmbeddedWorkerInstance::AddListener(Listener* listener) {
350 listener_list_.AddObserver(listener); 377 listener_list_.AddObserver(listener);
351 } 378 }
352 379
353 void EmbeddedWorkerInstance::RemoveListener(Listener* listener) { 380 void EmbeddedWorkerInstance::RemoveListener(Listener* listener) {
354 listener_list_.RemoveObserver(listener); 381 listener_list_.RemoveObserver(listener);
355 } 382 }
356 383
357 } // namespace content 384 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698