Chromium Code Reviews| OLD | NEW |
|---|---|
| 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_manager.h" | 5 #include "content/browser/devtools/embedded_worker_devtools_manager.h" |
| 6 | 6 |
| 7 #include "content/browser/devtools/devtools_manager_impl.h" | 7 #include "content/browser/devtools/devtools_manager_impl.h" |
| 8 #include "content/browser/devtools/devtools_protocol.h" | 8 #include "content/browser/devtools/devtools_protocol.h" |
| 9 #include "content/browser/devtools/devtools_protocol_constants.h" | 9 #include "content/browser/devtools/devtools_protocol_constants.h" |
| 10 #include "content/browser/devtools/ipc_devtools_agent_host.h" | 10 #include "content/browser/devtools/ipc_devtools_agent_host.h" |
| 11 #include "content/browser/service_worker/service_worker_context_core.h" | |
| 12 #include "content/browser/service_worker/service_worker_version.h" | |
| 11 #include "content/browser/shared_worker/shared_worker_instance.h" | 13 #include "content/browser/shared_worker/shared_worker_instance.h" |
| 12 #include "content/common/devtools_messages.h" | 14 #include "content/common/devtools_messages.h" |
| 13 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/devtools_target.h" | |
| 14 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
| 15 #include "content/public/browser/worker_service.h" | 18 #include "content/public/browser/worker_service.h" |
| 16 #include "ipc/ipc_listener.h" | 19 #include "ipc/ipc_listener.h" |
| 17 | 20 |
| 18 namespace content { | 21 namespace content { |
| 19 | 22 |
| 20 namespace { | 23 namespace { |
| 21 | 24 |
| 22 bool SendMessageToWorker( | 25 bool SendMessageToWorker( |
| 23 const EmbeddedWorkerDevToolsManager::WorkerId& worker_id, | 26 const EmbeddedWorkerDevToolsManager::WorkerId& worker_id, |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | 169 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) |
| 167 host->AddRoute(worker_id_.second, this); | 170 host->AddRoute(worker_id_.second, this); |
| 168 } | 171 } |
| 169 | 172 |
| 170 WorkerId worker_id_; | 173 WorkerId worker_id_; |
| 171 bool worker_attached_; | 174 bool worker_attached_; |
| 172 std::string state_; | 175 std::string state_; |
| 173 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsAgentHost); | 176 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsAgentHost); |
| 174 }; | 177 }; |
| 175 | 178 |
| 179 class EmbeddedWorkerDevToolsManager::ServiceWorkerTarget | |
| 180 : public DevToolsTarget { | |
| 181 public: | |
|
pfeldman
2014/06/30 16:37:21
We can't implement DevToolsTarget in content. It i
vkuzkokov
2014/07/04 16:06:47
That would require a new interface which would mir
pfeldman
2014/07/05 20:17:09
Can we migrate to DTAH for everything instead?
| |
| 182 ServiceWorkerTarget( | |
| 183 scoped_refptr<EmbeddedWorkerDevToolsAgentHost> agent_host) | |
| 184 : agent_host_(agent_host) { | |
| 185 } | |
| 186 | |
| 187 virtual ~ServiceWorkerTarget() { | |
| 188 } | |
| 189 | |
| 190 virtual std::string GetId() const OVERRIDE { | |
| 191 return agent_host_->GetId(); | |
| 192 } | |
| 193 | |
| 194 virtual std::string GetParentId() const OVERRIDE { | |
| 195 return ""; | |
| 196 } | |
| 197 | |
| 198 virtual std::string GetType() const OVERRIDE { | |
| 199 return "worker"; | |
| 200 } | |
| 201 | |
| 202 virtual std::string GetTitle() const OVERRIDE { | |
| 203 return "Service Worker"; | |
| 204 } | |
| 205 | |
| 206 virtual std::string GetDescription() const OVERRIDE { | |
| 207 return "Service Worker"; | |
| 208 } | |
| 209 | |
| 210 virtual GURL GetURL() const OVERRIDE { | |
| 211 return GURL(); | |
| 212 } | |
| 213 | |
| 214 virtual GURL GetFaviconURL() const OVERRIDE { | |
| 215 return GURL(); | |
| 216 } | |
| 217 | |
| 218 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { | |
| 219 return base::TimeTicks(); | |
| 220 } | |
| 221 | |
| 222 virtual bool IsAttached() const OVERRIDE { | |
| 223 return agent_host_->IsAttached(); | |
| 224 } | |
| 225 | |
| 226 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { | |
| 227 return agent_host_; | |
| 228 } | |
| 229 | |
| 230 virtual bool Activate() const OVERRIDE { | |
| 231 return false; | |
| 232 } | |
| 233 | |
| 234 virtual bool Close() const OVERRIDE { | |
| 235 return EmbeddedWorkerDevToolsManager::GetInstance()->CloseServiceWorker( | |
| 236 agent_host_->worker_id()); | |
| 237 } | |
| 238 | |
| 239 private: | |
| 240 scoped_refptr<EmbeddedWorkerDevToolsAgentHost> agent_host_; | |
| 241 ServiceWorkerIdentifier* worker_id_; | |
| 242 }; | |
| 243 | |
| 176 // static | 244 // static |
| 177 EmbeddedWorkerDevToolsManager* EmbeddedWorkerDevToolsManager::GetInstance() { | 245 EmbeddedWorkerDevToolsManager* EmbeddedWorkerDevToolsManager::GetInstance() { |
| 178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 246 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 179 return Singleton<EmbeddedWorkerDevToolsManager>::get(); | 247 return Singleton<EmbeddedWorkerDevToolsManager>::get(); |
| 180 } | 248 } |
| 181 | 249 |
| 182 DevToolsAgentHost* EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForWorker( | 250 DevToolsAgentHost* |
| 251 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForWorker( | |
| 252 int worker_process_id, | |
| 253 int worker_route_id) { | |
| 254 return GetOrCreateAgentHost(worker_process_id, worker_route_id); | |
| 255 } | |
| 256 | |
| 257 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost* | |
| 258 EmbeddedWorkerDevToolsManager::GetOrCreateAgentHost( | |
| 183 int worker_process_id, | 259 int worker_process_id, |
| 184 int worker_route_id) { | 260 int worker_route_id) { |
| 185 WorkerId id(worker_process_id, worker_route_id); | 261 WorkerId id(worker_process_id, worker_route_id); |
| 186 | 262 |
| 187 WorkerInfoMap::iterator it = workers_.find(id); | 263 WorkerInfoMap::iterator it = workers_.find(id); |
| 188 if (it == workers_.end()) | 264 if (it == workers_.end()) |
| 189 return NULL; | 265 return NULL; |
| 190 | 266 |
| 191 WorkerInfo* info = it->second; | 267 WorkerInfo* info = it->second; |
| 192 if (info->state() != WORKER_UNINSPECTED && | 268 if (info->state() != WORKER_UNINSPECTED && |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 203 | 279 |
| 204 DevToolsAgentHost* | 280 DevToolsAgentHost* |
| 205 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker( | 281 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker( |
| 206 const ServiceWorkerIdentifier& service_worker_id) { | 282 const ServiceWorkerIdentifier& service_worker_id) { |
| 207 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); | 283 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); |
| 208 if (it == workers_.end()) | 284 if (it == workers_.end()) |
| 209 return NULL; | 285 return NULL; |
| 210 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second); | 286 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second); |
| 211 } | 287 } |
| 212 | 288 |
| 289 std::vector<DevToolsTarget*> | |
| 290 EmbeddedWorkerDevToolsManager::GetAllServiceWorkerTargets() { | |
| 291 std::vector<DevToolsTarget*> targets; | |
| 292 for (WorkerInfoMap::iterator it = workers_.begin(); | |
| 293 it != workers_.end(); ++it) { | |
| 294 ServiceWorkerIdentifier* worker_id = it->second->service_worker_id(); | |
| 295 if (!worker_id) | |
| 296 continue; | |
| 297 targets.push_back(new ServiceWorkerTarget( | |
| 298 GetOrCreateAgentHost(it->first.first, it->first.second))); | |
| 299 } | |
| 300 return targets; | |
| 301 } | |
| 302 | |
| 213 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager() | 303 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager() |
| 214 : debug_service_worker_on_start_(false) { | 304 : debug_service_worker_on_start_(false) { |
| 215 } | 305 } |
| 216 | 306 |
| 217 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() { | 307 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() { |
| 218 } | 308 } |
| 219 | 309 |
| 220 bool EmbeddedWorkerDevToolsManager::SharedWorkerCreated( | 310 bool EmbeddedWorkerDevToolsManager::SharedWorkerCreated( |
| 221 int worker_process_id, | 311 int worker_process_id, |
| 222 int worker_route_id, | 312 int worker_route_id, |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 | 455 |
| 366 void EmbeddedWorkerDevToolsManager::MoveToPausedState( | 456 void EmbeddedWorkerDevToolsManager::MoveToPausedState( |
| 367 const WorkerId& id, | 457 const WorkerId& id, |
| 368 const WorkerInfoMap::iterator& it) { | 458 const WorkerInfoMap::iterator& it) { |
| 369 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); | 459 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); |
| 370 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); | 460 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); |
| 371 info->set_state(WORKER_PAUSED_FOR_REATTACH); | 461 info->set_state(WORKER_PAUSED_FOR_REATTACH); |
| 372 workers_.set(id, info.Pass()); | 462 workers_.set(id, info.Pass()); |
| 373 } | 463 } |
| 374 | 464 |
| 465 bool EmbeddedWorkerDevToolsManager::CloseServiceWorker(const WorkerId& id) { | |
| 466 return false; | |
| 467 //WorkerInfoMap::iterator it = workers_.find(id); | |
| 468 //if (it == workers_.end()); | |
|
pfeldman
2014/06/30 16:37:21
Cleanup.
vkuzkokov
2014/07/04 16:06:47
Uncommented and finished
| |
| 469 // return false; | |
| 470 //ServiceWorkerIdentifier* service_worker = it->second->service_worker_id(); | |
| 471 //if (!service_worker) | |
| 472 // return false; | |
| 473 //ServiceWorkerVersion* version = | |
| 474 // service_worker->service_worker_context_->GetLiveVersion( | |
| 475 // service_worker->service_worker_version_id_); | |
| 476 //if (!version) | |
| 477 // return false; | |
| 478 //version->StopWorker(ServiceWorkerVersion::StatusCallback()); | |
| 479 //return true; | |
| 480 } | |
| 481 | |
| 375 void EmbeddedWorkerDevToolsManager::ResetForTesting() { | 482 void EmbeddedWorkerDevToolsManager::ResetForTesting() { |
| 376 workers_.clear(); | 483 workers_.clear(); |
| 377 } | 484 } |
| 378 | 485 |
| 379 } // namespace content | 486 } // namespace content |
| OLD | NEW |