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" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 : service_worker_context_(other.service_worker_context_), | 55 : service_worker_context_(other.service_worker_context_), |
| 56 service_worker_version_id_(other.service_worker_version_id_) { | 56 service_worker_version_id_(other.service_worker_version_id_) { |
| 57 } | 57 } |
| 58 | 58 |
| 59 bool EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::Matches( | 59 bool EmbeddedWorkerDevToolsManager::ServiceWorkerIdentifier::Matches( |
| 60 const ServiceWorkerIdentifier& other) const { | 60 const ServiceWorkerIdentifier& other) const { |
| 61 return service_worker_context_ == other.service_worker_context_ && | 61 return service_worker_context_ == other.service_worker_context_ && |
| 62 service_worker_version_id_ == other.service_worker_version_id_; | 62 service_worker_version_id_ == other.service_worker_version_id_; |
| 63 } | 63 } |
| 64 | 64 |
| 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 | 65 class EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsAgentHost |
| 97 : public IPCDevToolsAgentHost, | 66 : public IPCDevToolsAgentHost, |
| 98 public IPC::Listener { | 67 public IPC::Listener { |
| 99 public: | 68 public: |
| 100 explicit EmbeddedWorkerDevToolsAgentHost(WorkerId worker_id) | 69 EmbeddedWorkerDevToolsAgentHost( |
| 101 : worker_id_(worker_id), worker_attached_(false) { | 70 WorkerId worker_id, |
| 102 AttachToWorker(); | 71 const SharedWorkerInstance& shared_worker) |
| 72 : shared_worker_(new SharedWorkerInstance(shared_worker)), | |
| 73 state_(WORKER_UNINSPECTED), | |
| 74 worker_id_(worker_id), | |
| 75 worker_attached_(false) { | |
| 76 WorkerCreated(); | |
| 77 } | |
| 78 | |
| 79 EmbeddedWorkerDevToolsAgentHost( | |
| 80 WorkerId worker_id, | |
| 81 const ServiceWorkerIdentifier& service_worker) | |
| 82 : service_worker_(new ServiceWorkerIdentifier(service_worker)), | |
| 83 state_(WORKER_UNINSPECTED), | |
| 84 worker_id_(worker_id), | |
| 85 worker_attached_(false) { | |
| 86 WorkerCreated(); | |
| 103 } | 87 } |
| 104 | 88 |
| 105 // DevToolsAgentHost override. | 89 // DevToolsAgentHost override. |
| 106 virtual bool IsWorker() const OVERRIDE { return true; } | 90 virtual bool IsWorker() const OVERRIDE { return true; } |
| 107 | 91 |
| 108 // IPCDevToolsAgentHost implementation. | 92 // IPCDevToolsAgentHost implementation. |
| 109 virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE { | 93 virtual void SendMessageToAgent(IPC::Message* message) OVERRIDE { |
| 110 if (worker_attached_) | 94 if (worker_attached_) |
| 111 SendMessageToWorker(worker_id_, message); | 95 SendMessageToWorker(worker_id_, message); |
| 112 else | 96 else |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 132 IPC_END_MESSAGE_MAP() | 116 IPC_END_MESSAGE_MAP() |
| 133 return handled; | 117 return handled; |
| 134 } | 118 } |
| 135 | 119 |
| 136 void ReattachToWorker(WorkerId worker_id) { | 120 void ReattachToWorker(WorkerId worker_id) { |
| 137 CHECK(!worker_attached_); | 121 CHECK(!worker_attached_); |
| 138 worker_id_ = worker_id; | 122 worker_id_ = worker_id; |
| 139 if (!IsAttached()) | 123 if (!IsAttached()) |
| 140 return; | 124 return; |
| 141 AttachToWorker(); | 125 AttachToWorker(); |
| 142 Reattach(state_); | 126 Reattach(saved_state_); |
| 143 } | 127 } |
| 144 | 128 |
| 145 void DetachFromWorker() { | 129 void DetachFromWorker() { |
| 146 if (!worker_attached_) | 130 if (!worker_attached_) |
| 147 return; | 131 return; |
| 148 worker_attached_ = false; | 132 worker_attached_ = false; |
| 149 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | 133 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) |
| 150 host->RemoveRoute(worker_id_.second); | 134 host->RemoveRoute(worker_id_.second); |
| 135 } | |
| 136 | |
| 137 void WorkerCreated() { | |
| 138 AddRef(); | |
| 139 } | |
| 140 | |
| 141 void WorkerDestroyed() { | |
| 151 Release(); | 142 Release(); |
| 152 } | 143 } |
| 153 | 144 |
| 154 WorkerId worker_id() const { return worker_id_; } | 145 WorkerId worker_id() const { return worker_id_; } |
| 146 WorkerState state() const { return state_; } | |
| 147 void set_worker_id(WorkerId worker_id) { worker_id_ = worker_id; } | |
| 148 void set_state(WorkerState state) { state_ = state; }; | |
| 149 | |
| 150 bool Matches(const SharedWorkerInstance& other) { | |
| 151 return shared_worker_ && shared_worker_->Matches(other); | |
| 152 } | |
| 153 | |
| 154 bool Matches(const ServiceWorkerIdentifier& other) { | |
| 155 return service_worker_ && service_worker_->Matches(other); | |
| 156 } | |
| 155 | 157 |
| 156 private: | 158 private: |
| 157 virtual ~EmbeddedWorkerDevToolsAgentHost() { | 159 virtual ~EmbeddedWorkerDevToolsAgentHost() { |
| 158 CHECK(!worker_attached_); | 160 CHECK(!worker_attached_); |
| 159 EmbeddedWorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData( | 161 EmbeddedWorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData( |
| 160 this); | 162 this); |
| 161 } | 163 } |
| 162 | 164 |
| 163 void OnDispatchOnInspectorFrontend(const std::string& message) { | 165 void OnDispatchOnInspectorFrontend(const std::string& message) { |
| 164 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(this, | 166 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend(this, |
| 165 message); | 167 message); |
| 166 } | 168 } |
| 167 | 169 |
| 168 void OnSaveAgentRuntimeState(const std::string& state) { state_ = state; } | 170 void OnSaveAgentRuntimeState(const std::string& state) { |
| 171 saved_state_ = state; | |
| 172 } | |
| 169 | 173 |
| 170 void AttachToWorker() { | 174 void AttachToWorker() { |
| 171 if (worker_attached_) | 175 if (worker_attached_) |
| 172 return; | 176 return; |
| 173 worker_attached_ = true; | 177 worker_attached_ = true; |
| 174 AddRef(); | 178 set_state(WORKER_INSPECTED); |
| 175 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | 179 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) |
| 176 host->AddRoute(worker_id_.second, this); | 180 host->AddRoute(worker_id_.second, this); |
| 177 } | 181 } |
| 178 | 182 |
| 183 scoped_ptr<SharedWorkerInstance> shared_worker_; | |
| 184 scoped_ptr<ServiceWorkerIdentifier> service_worker_; | |
| 185 WorkerState state_; | |
| 179 WorkerId worker_id_; | 186 WorkerId worker_id_; |
| 180 bool worker_attached_; | 187 bool worker_attached_; |
| 181 std::string state_; | 188 std::string saved_state_; |
|
dgozman
2014/08/06 08:13:48
saved_agent_state_
vkuzkokov
2014/08/06 09:07:39
Done.
| |
| 182 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsAgentHost); | 189 DISALLOW_COPY_AND_ASSIGN(EmbeddedWorkerDevToolsAgentHost); |
| 183 }; | 190 }; |
| 184 | 191 |
| 185 // static | 192 // static |
| 186 EmbeddedWorkerDevToolsManager* EmbeddedWorkerDevToolsManager::GetInstance() { | 193 EmbeddedWorkerDevToolsManager* EmbeddedWorkerDevToolsManager::GetInstance() { |
| 187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 188 return Singleton<EmbeddedWorkerDevToolsManager>::get(); | 195 return Singleton<EmbeddedWorkerDevToolsManager>::get(); |
| 189 } | 196 } |
| 190 | 197 |
| 191 DevToolsAgentHost* EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForWorker( | 198 DevToolsAgentHost* EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForWorker( |
| 192 int worker_process_id, | 199 int worker_process_id, |
| 193 int worker_route_id) { | 200 int worker_route_id) { |
| 194 WorkerId id(worker_process_id, worker_route_id); | 201 WorkerInfoMap::iterator it = workers_.find( |
| 195 | 202 WorkerId(worker_process_id, worker_route_id)); |
| 196 WorkerInfoMap::iterator it = workers_.find(id); | 203 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 } | 204 } |
| 212 | 205 |
| 213 DevToolsAgentHost* | 206 DevToolsAgentHost* |
| 214 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker( | 207 EmbeddedWorkerDevToolsManager::GetDevToolsAgentHostForServiceWorker( |
| 215 const ServiceWorkerIdentifier& service_worker_id) { | 208 const ServiceWorkerIdentifier& service_worker_id) { |
| 216 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); | 209 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); |
| 217 if (it == workers_.end()) | 210 if (it == workers_.end()) |
| 218 return NULL; | 211 return NULL; |
| 219 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second); | 212 return GetDevToolsAgentHostForWorker(it->first.first, it->first.second); |
| 220 } | 213 } |
| 221 | 214 |
| 222 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager() | 215 EmbeddedWorkerDevToolsManager::EmbeddedWorkerDevToolsManager() |
| 223 : debug_service_worker_on_start_(false) { | 216 : debug_service_worker_on_start_(false) { |
| 224 } | 217 } |
| 225 | 218 |
| 226 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() { | 219 EmbeddedWorkerDevToolsManager::~EmbeddedWorkerDevToolsManager() { |
| 227 } | 220 } |
| 228 | 221 |
| 229 bool EmbeddedWorkerDevToolsManager::SharedWorkerCreated( | 222 bool EmbeddedWorkerDevToolsManager::SharedWorkerCreated( |
| 230 int worker_process_id, | 223 int worker_process_id, |
| 231 int worker_route_id, | 224 int worker_route_id, |
| 232 const SharedWorkerInstance& instance) { | 225 const SharedWorkerInstance& instance) { |
| 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 234 const WorkerId id(worker_process_id, worker_route_id); | 227 const WorkerId id(worker_process_id, worker_route_id); |
| 235 WorkerInfoMap::iterator it = FindExistingSharedWorkerInfo(instance); | 228 WorkerInfoMap::iterator it = FindExistingSharedWorkerInfo(instance); |
| 236 if (it == workers_.end()) { | 229 if (it == workers_.end()) { |
| 237 scoped_ptr<WorkerInfo> info(new WorkerInfo(instance)); | 230 EmbeddedWorkerDevToolsAgentHost* agent = |
| 238 workers_.set(id, info.Pass()); | 231 new EmbeddedWorkerDevToolsAgentHost(id, instance); |
| 232 workers_[id] = agent; | |
| 239 return false; | 233 return false; |
| 240 } | 234 } |
| 241 MoveToPausedState(id, it); | 235 WorkerRestarted(id, it); |
| 242 return true; | 236 return true; |
| 243 } | 237 } |
| 244 | 238 |
| 245 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated( | 239 bool EmbeddedWorkerDevToolsManager::ServiceWorkerCreated( |
| 246 int worker_process_id, | 240 int worker_process_id, |
| 247 int worker_route_id, | 241 int worker_route_id, |
| 248 const ServiceWorkerIdentifier& service_worker_id) { | 242 const ServiceWorkerIdentifier& service_worker_id) { |
| 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 243 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 250 const WorkerId id(worker_process_id, worker_route_id); | 244 const WorkerId id(worker_process_id, worker_route_id); |
| 251 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); | 245 WorkerInfoMap::iterator it = FindExistingServiceWorkerInfo(service_worker_id); |
| 252 if (it == workers_.end()) { | 246 if (it == workers_.end()) { |
| 253 scoped_ptr<WorkerInfo> info(new WorkerInfo(service_worker_id)); | 247 EmbeddedWorkerDevToolsAgentHost* agent = |
| 248 new EmbeddedWorkerDevToolsAgentHost(id, service_worker_id); | |
| 254 if (debug_service_worker_on_start_) | 249 if (debug_service_worker_on_start_) |
| 255 info->set_state(WORKER_PAUSED_FOR_DEBUG_ON_START); | 250 agent->set_state(WORKER_PAUSED_FOR_DEBUG_ON_START); |
| 256 workers_.set(id, info.Pass()); | 251 workers_[id] = agent; |
| 257 return debug_service_worker_on_start_; | 252 return debug_service_worker_on_start_; |
| 258 } | 253 } |
| 259 MoveToPausedState(id, it); | 254 WorkerRestarted(id, it); |
| 260 return true; | 255 return true; |
| 261 } | 256 } |
| 262 | 257 |
| 263 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, | 258 void EmbeddedWorkerDevToolsManager::WorkerDestroyed(int worker_process_id, |
| 264 int worker_route_id) { | 259 int worker_route_id) { |
| 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 266 const WorkerId id(worker_process_id, worker_route_id); | 261 const WorkerId id(worker_process_id, worker_route_id); |
| 267 WorkerInfoMap::iterator it = workers_.find(id); | 262 WorkerInfoMap::iterator it = workers_.find(id); |
| 268 DCHECK(it != workers_.end()); | 263 DCHECK(it != workers_.end()); |
| 269 WorkerInfo* info = it->second; | 264 EmbeddedWorkerDevToolsAgentHost* agent = it->second; |
|
dgozman
2014/08/06 08:13:48
I'd prefer agent_host.
vkuzkokov
2014/08/06 09:07:39
Done.
| |
| 270 switch (info->state()) { | 265 switch (agent->state()) { |
| 271 case WORKER_UNINSPECTED: | 266 case WORKER_UNINSPECTED: |
| 272 case WORKER_PAUSED_FOR_DEBUG_ON_START: | 267 case WORKER_PAUSED_FOR_DEBUG_ON_START: |
| 273 workers_.erase(it); | 268 agent->set_state(WORKER_TERMINATED); |
|
dgozman
2014/08/06 08:13:48
You call set_state(WORKER_TERMINATED) in every cas
vkuzkokov
2014/08/06 09:07:39
Done.
| |
| 269 agent->DetachFromWorker(); | |
| 274 break; | 270 break; |
| 275 case WORKER_INSPECTED: { | 271 case WORKER_INSPECTED: { |
| 276 EmbeddedWorkerDevToolsAgentHost* agent_host = info->agent_host(); | 272 agent->set_state(WORKER_TERMINATED); |
| 277 info->set_state(WORKER_TERMINATED); | 273 if (agent->IsAttached()) { |
| 278 if (!agent_host->IsAttached()) { | 274 // Client host is debugging this worker agent host. |
| 279 agent_host->DetachFromWorker(); | 275 std::string notification = |
| 280 return; | 276 DevToolsProtocol::CreateNotification( |
| 277 devtools::Worker::disconnectedFromWorker::kName, NULL) | |
| 278 ->Serialize(); | |
| 279 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( | |
| 280 agent, notification); | |
| 281 } | 281 } |
| 282 // Client host is debugging this worker agent host. | 282 agent->DetachFromWorker(); |
| 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; | 283 break; |
| 291 } | 284 } |
| 292 case WORKER_TERMINATED: | 285 case WORKER_TERMINATED: |
| 293 NOTREACHED(); | 286 NOTREACHED(); |
| 294 break; | 287 break; |
| 295 case WORKER_PAUSED_FOR_REATTACH: { | 288 case WORKER_PAUSED_FOR_REATTACH: { |
| 296 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(it); | 289 workers_.erase(it); |
|
dgozman
2014/08/06 08:13:48
This could kill the agent host.
vkuzkokov
2014/08/06 09:07:38
workers_ stores raw pointers. This shouldn't have
| |
| 297 worker_info->set_state(WORKER_TERMINATED); | 290 agent->set_state(WORKER_TERMINATED); |
| 298 const WorkerId old_id = worker_info->agent_host()->worker_id(); | 291 workers_[agent->worker_id()] = agent; |
| 299 workers_.set(old_id, worker_info.Pass()); | |
| 300 break; | 292 break; |
| 301 } | 293 } |
| 302 } | 294 } |
| 295 agent->WorkerDestroyed(); | |
| 303 } | 296 } |
| 304 | 297 |
| 305 void EmbeddedWorkerDevToolsManager::WorkerContextStarted(int worker_process_id, | 298 void EmbeddedWorkerDevToolsManager::WorkerContextStarted(int worker_process_id, |
| 306 int worker_route_id) { | 299 int worker_route_id) { |
| 307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 308 const WorkerId id(worker_process_id, worker_route_id); | 301 const WorkerId id(worker_process_id, worker_route_id); |
| 309 WorkerInfoMap::iterator it = workers_.find(id); | 302 WorkerInfoMap::iterator it = workers_.find(id); |
| 310 DCHECK(it != workers_.end()); | 303 DCHECK(it != workers_.end()); |
| 311 WorkerInfo* info = it->second; | 304 EmbeddedWorkerDevToolsAgentHost* agent = it->second; |
| 312 if (info->state() == WORKER_PAUSED_FOR_DEBUG_ON_START) { | 305 if (agent->state() == WORKER_PAUSED_FOR_DEBUG_ON_START) { |
| 313 RenderProcessHost* rph = RenderProcessHost::FromID(worker_process_id); | 306 RenderProcessHost* rph = RenderProcessHost::FromID(worker_process_id); |
| 314 scoped_refptr<DevToolsAgentHost> agent_host( | 307 DevToolsManagerImpl::GetInstance()->Inspect( |
| 315 GetDevToolsAgentHostForWorker(worker_process_id, worker_route_id)); | 308 rph->GetBrowserContext(), agent); |
| 316 DevToolsManagerImpl::GetInstance()->Inspect(rph->GetBrowserContext(), | 309 } else if (agent->state() == WORKER_PAUSED_FOR_REATTACH) { |
| 317 agent_host.get()); | 310 agent->ReattachToWorker(id); |
| 318 } else if (info->state() == WORKER_PAUSED_FOR_REATTACH) { | |
| 319 info->agent_host()->ReattachToWorker(id); | |
| 320 info->set_state(WORKER_INSPECTED); | |
| 321 } | 311 } |
| 322 } | 312 } |
| 323 | 313 |
| 324 void EmbeddedWorkerDevToolsManager::RemoveInspectedWorkerData( | 314 void EmbeddedWorkerDevToolsManager::RemoveInspectedWorkerData( |
| 325 EmbeddedWorkerDevToolsAgentHost* agent_host) { | 315 EmbeddedWorkerDevToolsAgentHost* agent_host) { |
| 326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 327 const WorkerId id(agent_host->worker_id()); | 317 const WorkerId id(agent_host->worker_id()); |
| 328 scoped_ptr<WorkerInfo> worker_info = workers_.take_and_erase(id); | 318 WorkerInfoMap::iterator it = workers_.find(id); |
| 329 if (worker_info) { | 319 if (it != workers_.end()) { |
|
dgozman
2014/08/06 08:13:48
How is it possible to not find agent host in the m
vkuzkokov
2014/08/06 09:07:39
It used to be possible (see case WORKER_PAUSED_FOR
| |
| 330 DCHECK_EQ(worker_info->agent_host(), agent_host); | 320 DCHECK_EQ(it->second, agent_host); |
| 331 if (worker_info->state() == WORKER_TERMINATED) | 321 workers_.erase(it); |
| 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; | 322 return; |
| 338 } | 323 } |
| 339 for (WorkerInfoMap::iterator it = workers_.begin(); it != workers_.end(); | 324 for (WorkerInfoMap::iterator it = workers_.begin(); it != workers_.end(); |
| 340 ++it) { | 325 ++it) { |
| 341 if (it->second->agent_host() == agent_host) { | 326 if (it->second == agent_host) { |
| 342 DCHECK_EQ(WORKER_PAUSED_FOR_REATTACH, it->second->state()); | 327 DCHECK_EQ(WORKER_PAUSED_FOR_REATTACH, it->second->state()); |
| 343 SendMessageToWorker( | 328 SendMessageToWorker( |
| 344 it->first, | 329 it->first, |
| 345 new DevToolsAgentMsg_ResumeWorkerContext(it->first.second)); | 330 new DevToolsAgentMsg_ResumeWorkerContext(it->first.second)); |
| 346 it->second->set_agent_host(NULL); | 331 workers_.erase(it); |
| 347 it->second->set_state(WORKER_UNINSPECTED); | |
| 348 return; | 332 return; |
| 349 } | 333 } |
| 350 } | 334 } |
| 351 } | 335 } |
| 352 | 336 |
| 353 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator | 337 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator |
| 354 EmbeddedWorkerDevToolsManager::FindExistingSharedWorkerInfo( | 338 EmbeddedWorkerDevToolsManager::FindExistingSharedWorkerInfo( |
|
dgozman
2014/08/06 08:13:48
This is about AgentHost, not WorkerInfo now.
vkuzkokov
2014/08/06 09:07:39
Renamed
| |
| 355 const SharedWorkerInstance& instance) { | 339 const SharedWorkerInstance& instance) { |
| 356 WorkerInfoMap::iterator it = workers_.begin(); | 340 WorkerInfoMap::iterator it = workers_.begin(); |
| 357 for (; it != workers_.end(); ++it) { | 341 for (; it != workers_.end(); ++it) { |
| 358 if (it->second->Matches(instance)) | 342 if (it->second->Matches(instance)) |
| 359 break; | 343 break; |
| 360 } | 344 } |
| 361 return it; | 345 return it; |
| 362 } | 346 } |
| 363 | 347 |
| 364 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator | 348 EmbeddedWorkerDevToolsManager::WorkerInfoMap::iterator |
| 365 EmbeddedWorkerDevToolsManager::FindExistingServiceWorkerInfo( | 349 EmbeddedWorkerDevToolsManager::FindExistingServiceWorkerInfo( |
|
dgozman
2014/08/06 08:13:48
This is about AgentHost, not WorkerInfo now.
vkuzkokov
2014/08/06 09:07:39
Renamed
| |
| 366 const ServiceWorkerIdentifier& service_worker_id) { | 350 const ServiceWorkerIdentifier& service_worker_id) { |
| 367 WorkerInfoMap::iterator it = workers_.begin(); | 351 WorkerInfoMap::iterator it = workers_.begin(); |
| 368 for (; it != workers_.end(); ++it) { | 352 for (; it != workers_.end(); ++it) { |
| 369 if (it->second->Matches(service_worker_id)) | 353 if (it->second->Matches(service_worker_id)) |
| 370 break; | 354 break; |
| 371 } | 355 } |
| 372 return it; | 356 return it; |
| 373 } | 357 } |
| 374 | 358 |
| 375 void EmbeddedWorkerDevToolsManager::MoveToPausedState( | 359 void EmbeddedWorkerDevToolsManager::WorkerRestarted( |
| 376 const WorkerId& id, | 360 const WorkerId& id, |
| 377 const WorkerInfoMap::iterator& it) { | 361 const WorkerInfoMap::iterator& it) { |
| 378 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); | 362 DCHECK_EQ(WORKER_TERMINATED, it->second->state()); |
| 379 scoped_ptr<WorkerInfo> info = workers_.take_and_erase(it); | 363 EmbeddedWorkerDevToolsAgentHost* agent = it->second; |
| 380 info->set_state(WORKER_PAUSED_FOR_REATTACH); | 364 agent->set_state(WORKER_PAUSED_FOR_REATTACH); |
| 381 workers_.set(id, info.Pass()); | 365 agent->set_worker_id(id); |
| 366 agent->WorkerCreated(); | |
| 367 workers_.erase(it); | |
| 368 workers_[id] = agent; | |
| 382 } | 369 } |
| 383 | 370 |
| 384 void EmbeddedWorkerDevToolsManager::ResetForTesting() { | 371 void EmbeddedWorkerDevToolsManager::ResetForTesting() { |
| 385 workers_.clear(); | 372 workers_.clear(); |
| 386 } | 373 } |
| 387 | 374 |
| 388 } // namespace content | 375 } // namespace content |
| OLD | NEW |