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

Side by Side Diff: content/browser/devtools/embedded_worker_devtools_agent_host.cc

Issue 761923004: Keep alive ServiceWorkers when devtools is attached (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/devtools/embedded_worker_devtools_agent_host.h" 5 #include "content/browser/devtools/embedded_worker_devtools_agent_host.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "content/browser/devtools/protocol/devtools_protocol_handler_impl.h" 8 #include "content/browser/devtools/protocol/devtools_protocol_handler_impl.h"
9 #include "content/browser/service_worker/service_worker_context_core.h" 9 #include "content/browser/service_worker/service_worker_context_core.h"
10 #include "content/browser/service_worker/service_worker_version.h" 10 #include "content/browser/service_worker/service_worker_version.h"
(...skipping 17 matching lines...) Expand all
28 28
29 void TerminateServiceWorkerOnIO( 29 void TerminateServiceWorkerOnIO(
30 base::WeakPtr<ServiceWorkerContextCore> context_weak, 30 base::WeakPtr<ServiceWorkerContextCore> context_weak,
31 int64 version_id) { 31 int64 version_id) {
32 if (ServiceWorkerContextCore* context = context_weak.get()) { 32 if (ServiceWorkerContextCore* context = context_weak.get()) {
33 if (ServiceWorkerVersion* version = context->GetLiveVersion(version_id)) 33 if (ServiceWorkerVersion* version = context->GetLiveVersion(version_id))
34 version->StopWorker(base::Bind(&StatusNoOp)); 34 version->StopWorker(base::Bind(&StatusNoOp));
35 } 35 }
36 } 36 }
37 37
38 void SetDevToolsAttachedOnIO(
39 base::WeakPtr<ServiceWorkerContextCore> context_weak,
40 int64 version_id,
41 bool attached) {
42 if (ServiceWorkerContextCore* context = context_weak.get()) {
43 if (ServiceWorkerVersion* version = context->GetLiveVersion(version_id))
44 version->SetDevToolsAttached(attached);
45 }
38 } 46 }
39 47
48 } // namespace
49
40 EmbeddedWorkerDevToolsAgentHost::EmbeddedWorkerDevToolsAgentHost( 50 EmbeddedWorkerDevToolsAgentHost::EmbeddedWorkerDevToolsAgentHost(
41 WorkerId worker_id, 51 WorkerId worker_id,
42 const SharedWorkerInstance& shared_worker) 52 const SharedWorkerInstance& shared_worker)
43 : shared_worker_(new SharedWorkerInstance(shared_worker)), 53 : shared_worker_(new SharedWorkerInstance(shared_worker)),
44 state_(WORKER_UNINSPECTED), 54 state_(WORKER_UNINSPECTED),
45 worker_id_(worker_id) { 55 worker_id_(worker_id) {
46 WorkerCreated(); 56 WorkerCreated();
47 } 57 }
48 58
49 EmbeddedWorkerDevToolsAgentHost::EmbeddedWorkerDevToolsAgentHost( 59 EmbeddedWorkerDevToolsAgentHost::EmbeddedWorkerDevToolsAgentHost(
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 void EmbeddedWorkerDevToolsAgentHost::Attach() { 128 void EmbeddedWorkerDevToolsAgentHost::Attach() {
119 if (state_ != WORKER_INSPECTED) { 129 if (state_ != WORKER_INSPECTED) {
120 state_ = WORKER_INSPECTED; 130 state_ = WORKER_INSPECTED;
121 AttachToWorker(); 131 AttachToWorker();
122 } 132 }
123 IPCDevToolsAgentHost::Attach(); 133 IPCDevToolsAgentHost::Attach();
124 } 134 }
125 135
126 void EmbeddedWorkerDevToolsAgentHost::OnClientAttached() { 136 void EmbeddedWorkerDevToolsAgentHost::OnClientAttached() {
127 DevToolsAgentHostImpl::NotifyCallbacks(this, true); 137 DevToolsAgentHostImpl::NotifyCallbacks(this, true);
138 if (service_worker_) {
pfeldman 2014/12/15 06:11:08 Is this always true?
kinuko 2014/12/15 06:39:13 Looks like it's not, the same code is used for Sha
pfeldman 2014/12/15 07:05:04 Oh. I was not familiar with the code and did not r
139 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
140 base::Bind(&SetDevToolsAttachedOnIO,
141 service_worker_->context_weak(),
142 service_worker_->version_id(),
143 true));
144 }
128 } 145 }
129 146
130 void EmbeddedWorkerDevToolsAgentHost::OnClientDetached() { 147 void EmbeddedWorkerDevToolsAgentHost::OnClientDetached() {
131 if (state_ == WORKER_INSPECTED) { 148 if (state_ == WORKER_INSPECTED) {
132 state_ = WORKER_UNINSPECTED; 149 state_ = WORKER_UNINSPECTED;
133 DetachFromWorker(); 150 DetachFromWorker();
134 } else if (state_ == WORKER_PAUSED_FOR_REATTACH) { 151 } else if (state_ == WORKER_PAUSED_FOR_REATTACH) {
135 state_ = WORKER_UNINSPECTED; 152 state_ = WORKER_UNINSPECTED;
136 } 153 }
137 DevToolsAgentHostImpl::NotifyCallbacks(this, false); 154 DevToolsAgentHostImpl::NotifyCallbacks(this, false);
155 if (service_worker_) {
pfeldman 2014/12/15 06:11:08 ditto
156 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
157 base::Bind(&SetDevToolsAttachedOnIO,
158 service_worker_->context_weak(),
159 service_worker_->version_id(),
160 false));
161 }
138 } 162 }
139 163
140 bool EmbeddedWorkerDevToolsAgentHost::OnMessageReceived( 164 bool EmbeddedWorkerDevToolsAgentHost::OnMessageReceived(
141 const IPC::Message& msg) { 165 const IPC::Message& msg) {
142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
143 bool handled = true; 167 bool handled = true;
144 IPC_BEGIN_MESSAGE_MAP(EmbeddedWorkerDevToolsAgentHost, msg) 168 IPC_BEGIN_MESSAGE_MAP(EmbeddedWorkerDevToolsAgentHost, msg)
145 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, 169 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend,
146 OnDispatchOnInspectorFrontend) 170 OnDispatchOnInspectorFrontend)
147 IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAgentRuntimeState, 171 IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAgentRuntimeState,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 RenderProcessHost* rph = RenderProcessHost::FromID(worker_id_.first); 258 RenderProcessHost* rph = RenderProcessHost::FromID(worker_id_.first);
235 return rph ? rph->GetBrowserContext() : nullptr; 259 return rph ? rph->GetBrowserContext() : nullptr;
236 } 260 }
237 261
238 void EmbeddedWorkerDevToolsAgentHost::OnSaveAgentRuntimeState( 262 void EmbeddedWorkerDevToolsAgentHost::OnSaveAgentRuntimeState(
239 const std::string& state) { 263 const std::string& state) {
240 saved_agent_state_ = state; 264 saved_agent_state_ = state;
241 } 265 }
242 266
243 } // namespace content 267 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698