| 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/embedded_worker_devtools_agent_host.h" |
| 10 #include "content/browser/devtools/ipc_devtools_agent_host.h" | 11 #include "content/browser/devtools/ipc_devtools_agent_host.h" |
| 11 #include "content/browser/shared_worker/shared_worker_instance.h" | 12 #include "content/browser/shared_worker/shared_worker_instance.h" |
| 12 #include "content/common/devtools_messages.h" | 13 #include "content/common/devtools_messages.h" |
| 13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
| 15 #include "content/public/browser/worker_service.h" | 16 #include "content/public/browser/worker_service.h" |
| 16 #include "ipc/ipc_listener.h" | 17 #include "ipc/ipc_listener.h" |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 | 20 |
| 20 // Called on the UI thread. | 21 // Called on the UI thread. |
| 21 // static | 22 // static |
| 22 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForWorker( | 23 scoped_refptr<DevToolsAgentHost> DevToolsAgentHost::GetForWorker( |
| 23 int worker_process_id, | 24 int worker_process_id, |
| 24 int worker_route_id) { | 25 int worker_route_id) { |
| 25 return EmbeddedWorkerDevToolsManager::GetInstance() | 26 return EmbeddedWorkerDevToolsManager::GetInstance() |
| 26 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id); | 27 ->GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id); |
| 27 } | 28 } |
| 28 | 29 |
| 29 namespace { | |
| 30 | |
| 31 bool SendMessageToWorker( | |
| 32 const EmbeddedWorkerDevToolsManager::WorkerId& worker_id, | |
| 33 IPC::Message* message) { | |
| 34 RenderProcessHost* host = RenderProcessHost::FromID(worker_id.first); | |
| 35 if (!host) { | |
| 36 delete message; | |
| 37 return false; | |
| 38 } | |
| 39 message->set_routing_id(worker_id.second); | |
| 40 host->Send(message); | |
| 41 return true; | |
| 42 } | |
| 43 | |
| 44 } // namespace | |
| 45 | |
| 46 EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::ServiceWorkerIdentifier( | 30 EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::ServiceWorkerIdentifier( |
| 47 const ServiceWorkerContextCore* const service_worker_context, | 31 const ServiceWorkerContextCore* const service_worker_context, |
| 48 int64 service_worker_version_id) | 32 int64 service_worker_version_id) |
| 49 : service_worker_context_(service_worker_context), | 33 : service_worker_context_(service_worker_context), |
| 50 service_worker_version_id_(service_worker_version_id) { | 34 service_worker_version_id_(service_worker_version_id) { |
| 51 } | 35 } |
| 52 | 36 |
| 53 EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::ServiceWorkerIdentifier( | 37 EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::ServiceWorkerIdentifier( |
| 54 const ServiceWorkerIdentifier& other) | 38 const ServiceWorkerIdentifier& other) |
| 55 : service_worker_context_(other.service_worker_context_), | 39 : service_worker_context_(other.service_worker_context_), |
| 56 service_worker_version_id_(other.service_worker_version_id_) { | 40 service_worker_version_id_(other.service_worker_version_id_) { |
| 57 } | 41 } |
| 58 | 42 |
| 59 bool EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::Matches( | 43 bool EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::Matches( |
| 60 const ServiceWorkerIdentifier& other) const { | 44 const ServiceWorkerIdentifier& other) const { |
| 61 return service_worker_context_ == other.service_worker_context_ && | 45 return service_worker_context_ == other.service_worker_context_ && |
| 62 service_worker_version_id_ == other.service_worker_version_id_; | 46 service_worker_version_id_ == other.service_worker_version_id_; |
| 63 } | 47 } |
| 64 | 48 |
| 65 EmbeddedWorkerDevToolsManager::WorkerInfo::WorkerInfo( | |
| 66 const SharedWorkerInstance& instance) | |
| 67 : shared_worker_instance_(new SharedWorkerInstance(instance)), | |
| 68 state_(WORKER_UNINSPECTED), | |
| 69 agent_host_(NULL) { | |
| 70 } | |
| 71 | |
| 72 EmbeddedWorkerDevToolsManager::WorkerInfo::WorkerInfo( | |
| 73 const ServiceWorkerIdentifier& service_worker_id) | |
| 74 : service_worker_id_(new ServiceWorkerIdentifier(service_worker_id)), | |
| 75 state_(WORKER_UNINSPECTED), | |
| 76 agent_host_(NULL) { | |
| 77 } | |
| 78 | |
| 79 bool EmbeddedWorkerDevToolsManager::WorkerInfo::Matches( | |
| 80 const SharedWorkerInstance& other) { | |
| 81 if (!shared_worker_instance_) | |
| 82 return false; | |
| 83 return shared_worker_instance_->Matches(other); | |
| 84 } | |
| 85 | |
| 86 bool EmbeddedWorkerDevToolsManager::WorkerInfo::Matches( | |
| 87 const ServiceWorkerIdentifier& other) { | |
| 88 if (!service_worker_id_) | |
| 89 return false; | |
| 90 return service_worker_id_->Matches(other); | |
| 91 } | |
| 92 | |
| 93 EmbeddedWorkerDevToolsManager::WorkerInfo::~WorkerInfo() { | |
| 94 } | |
| 95 | |
| 96 class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost | |
| 97 : public IPCDevToolsAgentHost, | |
| 98 public IPC::Listener { | |
| 99 public: | |
| 100 explicit EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id) | |
| 101 : worker_id_(worker_id), worker_attached_(false) { | |
| 102 AttachToWorker(); | |
| 103 } | |
| 104 | |
| 105 // DevToolsAgentHost override. | |
| 106 virtual bool IsWorker() const OVERRIDE { return true; } | |
| 107 | |
| 108 // IPCDevToolsAgentHost implementation. | |
| 109 virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE { | |
| 110 if (worker_attached_) | |
| 111 SendMessageToWorker(worker_id_, message); | |
| 112 else | |
| 113 delete message; | |
| 114 } | |
| 115 virtual void Attach() OVERRIDE { | |
| 116 AttachToWorker(); | |
| 117 IPCDevToolsAgentHost::Attach(); | |
| 118 } | |
| 119 virtual void OnClientAttached() OVERRIDE {} | |
| 120 virtual void OnClientDetached() OVERRIDE { DetachFromWorker(); } | |
| 121 | |
| 122 // IPC::Listener implementation. | |
| 123 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE { | |
| 124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 125 bool handled = true; | |
| 126 IPC_BEGIN_MESSAGE_MAP(EmbeddedWorkerDevToolsAgentHost, msg) | |
| 127 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, | |
| 128 OnDispatchOnInspectorFrontend) | |
| 129 IPC_MESSAGE_HANDLER(DevToolsHostMsg_SaveAgentRuntimeState, | |
| 130 OnSaveAgentRuntimeState) | |
| 131 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 132 IPC_END_MESSAGE_MAP() | |
| 133 return handled; | |
| 134 } | |
| 135 | |
| 136 void ReattachToWorker(WorkerId worker_id) { | |
| 137 CHECK(!worker_attached_); | |
| 138 worker_id_ = worker_id; | |
| 139 if (!IsAttached()) | |
| 140 return; | |
| 141 AttachToWorker(); | |
| 142 Reattach(state_); | |
| 143 } | |
| 144 | |
| 145 void DetachFromWorker() { | |
| 146 if (!worker_attached_) | |
| 147 return; | |
| 148 worker_attached_ = false; | |
| 149 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | |
| 150 host->RemoveRoute(worker_id_.second); | |
| 151 Release(); | |
| 152 } | |
| 153 | |
| 154 WorkerId worker_id() const { return worker_id_; } | |
| 155 | |
| 156 private: | |
| 157 virtual ~EmbeddedWorkerDevToolsAgentHost() { | |
| 158 CHECK(!worker_attached_); | |
| 159 EmbeddedWorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData( | |
| 160 this); | |
| 161 } | |
| 162 | |
| 163 void OnDispatchOnInspectorFrontend(const std::string& message) { | |
| 164 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(this, | |
| 165 message); | |
| 166 } | |
| 167 | |
| 168 void OnSaveAgentRuntimeState(const std::string& state) { state_ = state; } | |
| 169 | |
| 170 void AttachToWorker() { | |
| 171 if (worker_attached_) | |
| 172 return; | |
| 173 worker_attached_ = true; | |
| 174 AddRef(); | |
| 175 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | |
| 176 host->AddRoute(worker_id_.second, this); | |
| 177 } | |
| 178 | |
| 179 WorkerId worker_id_; | |
| 180 bool worker_attached_; | |
| 181 std::string state_; | |
| 182 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsAgentHost); | |
| 183 }; | |
| 184 | |
| 185 // static | 49 // static |
| 186 EmbeddedWorkerDevToolsManager* EmbeddedWorkerDevToolsManager::GetInstance() { | 50 EmbeddedWorkerDevToolsManager* EmbeddedWorkerDevToolsManager::GetInstance() { |
| 187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 188 return Singleton<EmbeddedWorkerDevToolsManager>::get(); | 52 return Singleton<EmbeddedWorkerDevToolsManager>::get(); |
| 189 } | 53 } |
| 190 | 54 |
| 191 DevToolsAgentHost* EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForWorker( | 55 DevToolsAgentHost* EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForWorker( |
| 192 int worker_process_id, | 56 int worker_process_id, |
| 193 int worker_route_id) { | 57 int worker_route_id) { |
| 194 WorkerId id(worker_process_id, worker_route_id); | 58 AgentHostMap::iterator it = workers_.find( |
| 195 | 59 WorkerId(worker_process_id, worker_route_id)); |
| 196 WorkerInfoMap::iterator it = workers_.find(id); | 60 return it == workers_.end() ? NULL : it->second; |
| 197 if (it == workers_.end()) | |
| 198 return NULL; | |
| 199 | |
| 200 WorkerInfo* info = it->second; | |
| 201 if (info->state() != WORKER_UNINSPECTED && | |
| 202 info->state() != WORKER_PAUSED_FOR_DEBUG_ON_START) { | |
| 203 return info->agent_host(); | |
| 204 } | |
| 205 | |
| 206 EmbeddedWorkerDevToolsAgentHost* agent_host = | |
| 207 new EmbeddedWorkerDevToolsAgentHost(id); | |
| 208 info->set_agent_host(agent_host); | |
| 209 info->set_state(WORKER_INSPECTED); | |
| 210 return agent_host; | |
| 211 } | 61 } |
| 212 | 62 |
| 213 DevToolsAgentHost* | 63 DevToolsAgentHost* |
| 214 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker( | 64 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker( |
| 215 const ServiceWorkerIdentifier& service_worker_id) { | 65 const ServiceWorkerIdentifier& service_worker_id) { |
| 216 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); | 66 AgentHostMap::iterator it = |
| 67 FindExistingServiceWorkerAgentHost(service_worker_id); |
| 217 if (it == workers_.end()) | 68 if (it == workers_.end()) |
| 218 return NULL; | 69 return NULL; |
| 219 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second); | 70 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second); |
| 220 } | 71 } |
| 221 | 72 |
| 222 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager() | 73 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager() |
| 223 : debug_service_worker_on_start_(false) { | 74 : debug_service_worker_on_start_(false) { |
| 224 } | 75 } |
| 225 | 76 |
| 226 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() { | 77 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() { |
| 227 } | 78 } |
| 228 | 79 |
| 229 bool EmbeddedWorkerDevToolsManager::SharedWorkerCreated( | 80 bool EmbeddedWorkerDevToolsManager::SharedWorkerCreated( |
| 230 int worker_process_id, | 81 int worker_process_id, |
| 231 int worker_route_id, | 82 int worker_route_id, |
| 232 const SharedWorkerInstance& instance) { | 83 const SharedWorkerInstance& instance) { |
| 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 234 const WorkerId id(worker_process_id, worker_route_id); | 85 const WorkerId id(worker_process_id, worker_route_id); |
| 235 WorkerInfoMap::iterator it = FindExistingSharedWorkerInfo(instance); | 86 AgentHostMap::iterator it = FindExistingSharedWorkerAgentHost(instance); |
| 236 if (it == workers_.end()) { | 87 if (it == workers_.end()) { |
| 237 scoped_ptr<WorkerInfo> info(new WorkerInfo(instance)); | 88 workers_[id] = new EmbeddedWorkerDevToolsAgentHost(id, instance); |
| 238 workers_.set(id, info.Pass()); | |
| 239 return false; | 89 return false; |
| 240 } | 90 } |
| 241 MoveToPausedState(id, it); | 91 WorkerRestarted(id, it); |
| 242 return true; | 92 return true; |
| 243 } | 93 } |
| 244 | 94 |
| 245 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated( | 95 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated( |
| 246 int worker_process_id, | 96 int worker_process_id, |
| 247 int worker_route_id, | 97 int worker_route_id, |
| 248 const ServiceWorkerIdentifier& service_worker_id) { | 98 const ServiceWorkerIdentifier& service_worker_id) { |
| 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 250 const WorkerId id(worker_process_id, worker_route_id); | 100 const WorkerId id(worker_process_id, worker_route_id); |
| 251 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); | 101 AgentHostMap::iterator it = |
| 102 FindExistingServiceWorkerAgentHost(service_worker_id); |
| 252 if (it == workers_.end()) { | 103 if (it == workers_.end()) { |
| 253 scoped_ptr<WorkerInfo> info(new WorkerInfo(service_worker_id)); | 104 workers_[id] = new EmbeddedWorkerDevToolsAgentHost( |
| 254 if (debug_service_worker_on_start_) | 105 id, service_worker_id, debug_service_worker_on_start_); |
| 255 info->set_state(WORKER_PAUSED_FOR_DEBUG_ON_START); | |
| 256 workers_.set(id, info.Pass()); | |
| 257 return debug_service_worker_on_start_; | 106 return debug_service_worker_on_start_; |
| 258 } | 107 } |
| 259 MoveToPausedState(id, it); | 108 WorkerRestarted(id, it); |
| 260 return true; | 109 return true; |
| 261 } | 110 } |
| 262 | 111 |
| 263 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, | 112 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, |
| 264 int worker_route_id) { | 113 int worker_route_id) { |
| 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 114 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 266 const WorkerId id(worker_process_id, worker_route_id); | 115 const WorkerId id(worker_process_id, worker_route_id); |
| 267 WorkerInfoMap::iterator it = workers_.find(id); | 116 AgentHostMap::iterator it = workers_.find(id); |
| 268 DCHECK(it != workers_.end()); | 117 DCHECK(it != workers_.end()); |
| 269 WorkerInfo* info = it->second; | 118 it->second->WorkerDestroyed(); |
| 270 switch (info->state()) { | |
| 271 case WORKER_UNINSPECTED: | |
| 272 case WORKER_PAUSED_FOR_DEBUG_ON_START: | |
| 273 workers_.erase(it); | |
| 274 break; | |
| 275 case WORKER_INSPECTED: { | |
| 276 EmbeddedWorkerDevToolsAgentHost* agent_host = info->agent_host(); | |
| 277 info->set_state(WORKER_TERMINATED); | |
| 278 if (!agent_host->IsAttached()) { | |
| 279 agent_host->DetachFromWorker(); | |
| 280 return; | |
| 281 } | |
| 282 // Client host is debugging this worker agent host. | |
| 283 std::string notification = | |
| 284 DevToolsProtocol::CreateNotification( | |
| 285 devtools::Worker::disconnectedFromWorker::kName, NULL) | |
| 286 ->Serialize(); | |
| 287 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( | |
| 288 agent_host, notification); | |
| 289 agent_host->DetachFromWorker(); | |
| 290 break; | |
| 291 } | |
| 292 case WORKER_TERMINATED: | |
| 293 NOTREACHED(); | |
| 294 break; | |
| 295 case WORKER_PAUSED_FOR_REATTACH: { | |
| 296 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(it); | |
| 297 worker_info->set_state(WORKER_TERMINATED); | |
| 298 const WorkerId old_id = worker_info->agent_host()->worker_id(); | |
| 299 workers_.set(old_id, worker_info.Pass()); | |
| 300 break; | |
| 301 } | |
| 302 } | |
| 303 } | 119 } |
| 304 | 120 |
| 305 void EmbeddedWorkerDevToolsManager::WorkerContextStarted(int worker_process_id, | 121 void EmbeddedWorkerDevToolsManager::WorkerContextStarted(int worker_process_id, |
| 306 int worker_route_id) { | 122 int worker_route_id) { |
| 307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 308 const WorkerId id(worker_process_id, worker_route_id); | 124 const WorkerId id(worker_process_id, worker_route_id); |
| 309 WorkerInfoMap::iterator it = workers_.find(id); | 125 AgentHostMap::iterator it = workers_.find(id); |
| 310 DCHECK(it != workers_.end()); | 126 DCHECK(it != workers_.end()); |
| 311 WorkerInfo* info = it->second; | 127 it->second->WorkerContextStarted(); |
| 312 if (info->state() == WORKER_PAUSED_FOR_DEBUG_ON_START) { | |
| 313 RenderProcessHost* rph = RenderProcessHost::FromID(worker_process_id); | |
| 314 scoped_refptr<DevToolsAgentHost> agent_host( | |
| 315 GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id)); | |
| 316 DevToolsManagerImpl::GetInstance()->Inspect(rph->GetBrowserContext(), | |
| 317 agent_host.get()); | |
| 318 } else if (info->state() == WORKER_PAUSED_FOR_REATTACH) { | |
| 319 info->agent_host()->ReattachToWorker(id); | |
| 320 info->set_state(WORKER_INSPECTED); | |
| 321 } | |
| 322 } | 128 } |
| 323 | 129 |
| 324 void EmbeddedWorkerDevToolsManager::RemoveInspectedWorkerData( | 130 void EmbeddedWorkerDevToolsManager::RemoveInspectedWorkerData(WorkerId id) { |
| 325 EmbeddedWorkerDevToolsAgentHost* agent_host) { | |
| 326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 327 const WorkerId id(agent_host->worker_id()); | 132 workers_.erase(id); |
| 328 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(id); | |
| 329 if (worker_info) { | |
| 330 DCHECK_EQ(worker_info->agent_host(), agent_host); | |
| 331 if (worker_info->state() == WORKER_TERMINATED) | |
| 332 return; | |
| 333 DCHECK_EQ(worker_info->state(), WORKER_INSPECTED); | |
| 334 worker_info->set_agent_host(NULL); | |
| 335 worker_info->set_state(WORKER_UNINSPECTED); | |
| 336 workers_.set(id, worker_info.Pass()); | |
| 337 return; | |
| 338 } | |
| 339 for (WorkerInfoMap::iterator it = workers_.begin(); it != workers_.end(); | |
| 340 ++it) { | |
| 341 if (it->second->agent_host() == agent_host) { | |
| 342 DCHECK_EQ(WORKER_PAUSED_FOR_REATTACH, it->second->state()); | |
| 343 SendMessageToWorker( | |
| 344 it->first, | |
| 345 new DevToolsAgentMsg_ResumeWorkerContext(it->first.second)); | |
| 346 it->second->set_agent_host(NULL); | |
| 347 it->second->set_state(WORKER_UNINSPECTED); | |
| 348 return; | |
| 349 } | |
| 350 } | |
| 351 } | 133 } |
| 352 | 134 |
| 353 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator | 135 EmbeddedWorkerDevToolsManager::AgentHostMap::iterator |
| 354 EmbeddedWorkerDevToolsManager::FindExistingSharedWorkerInfo( | 136 EmbeddedWorkerDevToolsManager::FindExistingSharedWorkerAgentHost( |
| 355 const SharedWorkerInstance& instance) { | 137 const SharedWorkerInstance& instance) { |
| 356 WorkerInfoMap::iterator it = workers_.begin(); | 138 AgentHostMap::iterator it = workers_.begin(); |
| 357 for (; it != workers_.end(); ++it) { | 139 for (; it != workers_.end(); ++it) { |
| 358 if (it->second->Matches(instance)) | 140 if (it->second->Matches(instance)) |
| 359 break; | 141 break; |
| 360 } | 142 } |
| 361 return it; | 143 return it; |
| 362 } | 144 } |
| 363 | 145 |
| 364 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator | 146 EmbeddedWorkerDevToolsManager::AgentHostMap::iterator |
| 365 EmbeddedWorkerDevToolsManager::FindExistingServiceWorkerInfo( | 147 EmbeddedWorkerDevToolsManager::FindExistingServiceWorkerAgentHost( |
| 366 const ServiceWorkerIdentifier& service_worker_id) { | 148 const ServiceWorkerIdentifier& service_worker_id) { |
| 367 WorkerInfoMap::iterator it = workers_.begin(); | 149 AgentHostMap::iterator it = workers_.begin(); |
| 368 for (; it != workers_.end(); ++it) { | 150 for (; it != workers_.end(); ++it) { |
| 369 if (it->second->Matches(service_worker_id)) | 151 if (it->second->Matches(service_worker_id)) |
| 370 break; | 152 break; |
| 371 } | 153 } |
| 372 return it; | 154 return it; |
| 373 } | 155 } |
| 374 | 156 |
| 375 void EmbeddedWorkerDevToolsManager::MoveToPausedState( | 157 void EmbeddedWorkerDevToolsManager::WorkerRestarted( |
| 376 const WorkerId& id, | 158 const WorkerId& id, |
| 377 const WorkerInfoMap::iterator& it) { | 159 const AgentHostMap::iterator& it) { |
| 378 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); | 160 EmbeddedWorkerDevToolsAgentHost* agent_host = it->second; |
| 379 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); | 161 agent_host->WorkerRestarted(id); |
| 380 info->set_state(WORKER_PAUSED_FOR_REATTACH); | 162 workers_.erase(it); |
| 381 workers_.set(id, info.Pass()); | 163 workers_[id] = agent_host; |
| 382 } | 164 } |
| 383 | 165 |
| 384 void EmbeddedWorkerDevToolsManager::ResetForTesting() { | 166 void EmbeddedWorkerDevToolsManager::ResetForTesting() { |
| 385 workers_.clear(); | 167 workers_.clear(); |
| 386 } | 168 } |
| 387 | 169 |
| 388 } // namespace content | 170 } // namespace content |
| OLD | NEW |