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_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 "content/browser/devtools/devtools_manager_impl.h" | 8 #include "content/browser/devtools/devtools_manager_impl.h" |
| 8 #include "content/browser/devtools/devtools_protocol.h" | 9 #include "content/browser/devtools/devtools_protocol.h" |
| 9 #include "content/browser/devtools/devtools_protocol_constants.h" | 10 #include "content/browser/devtools/devtools_protocol_constants.h" |
| 10 #include "content/browser/service_worker/service_worker_context_core.h" | 11 #include "content/browser/service_worker/service_worker_context_core.h" |
| 11 #include "content/browser/service_worker/service_worker_version.h" | 12 #include "content/browser/service_worker/service_worker_version.h" |
| 12 #include "content/browser/shared_worker/shared_worker_service_impl.h" | 13 #include "content/browser/shared_worker/shared_worker_service_impl.h" |
| 13 #include "content/common/devtools_messages.h" | 14 #include "content/common/devtools_messages.h" |
| 14 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
| 16 | 17 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 worker_id_(worker_id) { | 57 worker_id_(worker_id) { |
| 57 if (debug_service_worker_on_start) | 58 if (debug_service_worker_on_start) |
| 58 state_ = WORKER_PAUSED_FOR_DEBUG_ON_START; | 59 state_ = WORKER_PAUSED_FOR_DEBUG_ON_START; |
| 59 WorkerCreated(); | 60 WorkerCreated(); |
| 60 } | 61 } |
| 61 | 62 |
| 62 bool EmbeddedWorkerDevToolsAgentHost::IsWorker() const { | 63 bool EmbeddedWorkerDevToolsAgentHost::IsWorker() const { |
| 63 return true; | 64 return true; |
| 64 } | 65 } |
| 65 | 66 |
| 67 DevToolsAgentHost::Type EmbeddedWorkerDevToolsAgentHost::GetType() { | |
| 68 return shared_worker_ ? AGENT_HOST_SHARED_WORKER | |
| 69 : AGENT_HOST_SERVICE_WORKER; | |
| 70 } | |
| 71 | |
| 72 std::string EmbeddedWorkerDevToolsAgentHost::GetTitle() { | |
| 73 return shared_worker_ ? base::UTF16ToUTF8(shared_worker_->name()) : ""; | |
| 74 } | |
| 75 | |
| 66 GURL EmbeddedWorkerDevToolsAgentHost::GetURL() { | 76 GURL EmbeddedWorkerDevToolsAgentHost::GetURL() { |
| 67 if (shared_worker_) | 77 if (shared_worker_) |
| 68 return shared_worker_->url(); | 78 return shared_worker_->url(); |
| 69 if (service_worker_) | 79 if (service_worker_) |
| 70 return service_worker_->url(); | 80 return service_worker_->url(); |
| 71 return GURL(); | 81 return GURL(); |
| 72 } | 82 } |
| 73 | 83 |
| 84 bool EmbeddedWorkerDevToolsAgentHost::Activate() { | |
| 85 return false; | |
| 86 } | |
| 87 | |
| 74 bool EmbeddedWorkerDevToolsAgentHost::Close() { | 88 bool EmbeddedWorkerDevToolsAgentHost::Close() { |
| 75 if (shared_worker_) { | 89 if (shared_worker_) { |
| 76 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 90 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 77 base::Bind(&TerminateSharedWorkerOnIO, worker_id_)); | 91 base::Bind(&TerminateSharedWorkerOnIO, worker_id_)); |
| 78 return true; | 92 return true; |
| 79 } | 93 } |
| 80 if (service_worker_) { | 94 if (service_worker_) { |
| 81 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 95 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 82 base::Bind(&TerminateServiceWorkerOnIO, | 96 base::Bind(&TerminateServiceWorkerOnIO, |
| 83 service_worker_->context_weak(), | 97 service_worker_->context_weak(), |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 | 164 |
| 151 void EmbeddedWorkerDevToolsAgentHost::WorkerDestroyed() { | 165 void EmbeddedWorkerDevToolsAgentHost::WorkerDestroyed() { |
| 152 DCHECK_NE(WORKER_TERMINATED, state_); | 166 DCHECK_NE(WORKER_TERMINATED, state_); |
| 153 if (state_ == WORKER_INSPECTED) { | 167 if (state_ == WORKER_INSPECTED) { |
| 154 DCHECK(IsAttached()); | 168 DCHECK(IsAttached()); |
| 155 // Client host is debugging this worker agent host. | 169 // Client host is debugging this worker agent host. |
| 156 std::string notification = | 170 std::string notification = |
| 157 DevToolsProtocol::CreateNotification( | 171 DevToolsProtocol::CreateNotification( |
| 158 devtools::Worker::disconnectedFromWorker::kName, NULL)->Serialize(); | 172 devtools::Worker::disconnectedFromWorker::kName, NULL)->Serialize(); |
| 159 SendMessageToClient(notification); | 173 SendMessageToClient(notification); |
| 174 HostClosed(); | |
|
dgozman
2014/08/22 08:38:28
This should go to a separate patch.
vkuzkokov
2014/08/22 11:01:48
Done.
| |
| 160 DetachFromWorker(); | 175 DetachFromWorker(); |
| 161 } | 176 } |
| 162 state_ = WORKER_TERMINATED; | 177 state_ = WORKER_TERMINATED; |
| 163 Release(); // Balanced in WorkerCreated() | 178 Release(); // Balanced in WorkerCreated() |
| 164 } | 179 } |
| 165 | 180 |
| 166 bool EmbeddedWorkerDevToolsAgentHost::Matches( | 181 bool EmbeddedWorkerDevToolsAgentHost::Matches( |
| 167 const SharedWorkerInstance& other) { | 182 const SharedWorkerInstance& other) { |
| 168 return shared_worker_ && shared_worker_->Matches(other); | 183 return shared_worker_ && shared_worker_->Matches(other); |
| 169 } | 184 } |
| 170 | 185 |
| 171 bool EmbeddedWorkerDevToolsAgentHost::Matches( | 186 bool EmbeddedWorkerDevToolsAgentHost::Matches( |
| 172 const ServiceWorkerIdentifier& other) { | 187 const ServiceWorkerIdentifier& other) { |
| 173 return service_worker_ && service_worker_->Matches(other); | 188 return service_worker_ && service_worker_->Matches(other); |
| 174 } | 189 } |
| 175 | 190 |
| 191 bool EmbeddedWorkerDevToolsAgentHost::IsTerminated() { | |
| 192 return state_ == WORKER_TERMINATED; | |
| 193 } | |
| 194 | |
| 176 EmbeddedWorkerDevToolsAgentHost::~EmbeddedWorkerDevToolsAgentHost() { | 195 EmbeddedWorkerDevToolsAgentHost::~EmbeddedWorkerDevToolsAgentHost() { |
| 177 DCHECK_EQ(WORKER_TERMINATED, state_); | 196 DCHECK_EQ(WORKER_TERMINATED, state_); |
| 178 EmbeddedWorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData( | 197 EmbeddedWorkerDevToolsManager::GetInstance()->RemoveInspectedWorkerData( |
| 179 worker_id_); | 198 worker_id_); |
| 180 } | 199 } |
| 181 | 200 |
| 182 void EmbeddedWorkerDevToolsAgentHost::AttachToWorker() { | 201 void EmbeddedWorkerDevToolsAgentHost::AttachToWorker() { |
| 183 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) | 202 if (RenderProcessHost* host = RenderProcessHost::FromID(worker_id_.first)) |
| 184 host->AddRoute(worker_id_.second, this); | 203 host->AddRoute(worker_id_.second, this); |
| 185 } | 204 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 197 const std::string& message) { | 216 const std::string& message) { |
| 198 SendMessageToClient(message); | 217 SendMessageToClient(message); |
| 199 } | 218 } |
| 200 | 219 |
| 201 void EmbeddedWorkerDevToolsAgentHost::OnSaveAgentRuntimeState( | 220 void EmbeddedWorkerDevToolsAgentHost::OnSaveAgentRuntimeState( |
| 202 const std::string& state) { | 221 const std::string& state) { |
| 203 saved_agent_state_ = state; | 222 saved_agent_state_ = state; |
| 204 } | 223 } |
| 205 | 224 |
| 206 } // namespace content | 225 } // namespace content |
| OLD | NEW |