| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project 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 "test/inspector/inspector-impl.h" | 5 #include "test/inspector/inspector-impl.h" |
| 6 | 6 |
| 7 #include "include/v8.h" | 7 #include "include/v8.h" |
| 8 | 8 |
| 9 #include "src/vector.h" | 9 #include "src/vector.h" |
| 10 | 10 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 if (ready_semaphore_) ready_semaphore_->Signal(); | 122 if (ready_semaphore_) ready_semaphore_->Signal(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 private: | 125 private: |
| 126 InspectorClientImpl* client_; | 126 InspectorClientImpl* client_; |
| 127 v8::base::Semaphore* ready_semaphore_; | 127 v8::base::Semaphore* ready_semaphore_; |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 class DisconnectTask : public TaskRunner::Task { | 130 class DisconnectTask : public TaskRunner::Task { |
| 131 public: | 131 public: |
| 132 explicit DisconnectTask(InspectorClientImpl* client) : client_(client) {} | 132 explicit DisconnectTask(InspectorClientImpl* client, bool reset_inspector, |
| 133 v8::base::Semaphore* ready_semaphore) |
| 134 : client_(client), |
| 135 reset_inspector_(reset_inspector), |
| 136 ready_semaphore_(ready_semaphore) {} |
| 133 virtual ~DisconnectTask() = default; | 137 virtual ~DisconnectTask() = default; |
| 134 | 138 |
| 135 bool is_inspector_task() final { return true; } | 139 bool is_inspector_task() final { return true; } |
| 136 | 140 |
| 137 void Run(v8::Isolate* isolate, | 141 void Run(v8::Isolate* isolate, |
| 138 const v8::Global<v8::Context>& global_context) { | 142 const v8::Global<v8::Context>& global_context) { |
| 139 client_->disconnect(); | 143 client_->disconnect(reset_inspector_); |
| 144 if (ready_semaphore_) ready_semaphore_->Signal(); |
| 140 } | 145 } |
| 141 | 146 |
| 142 private: | 147 private: |
| 143 InspectorClientImpl* client_; | 148 InspectorClientImpl* client_; |
| 149 bool reset_inspector_; |
| 150 v8::base::Semaphore* ready_semaphore_; |
| 144 }; | 151 }; |
| 145 | 152 |
| 146 class CreateContextGroupTask : public TaskRunner::Task { | 153 class CreateContextGroupTask : public TaskRunner::Task { |
| 147 public: | 154 public: |
| 148 CreateContextGroupTask(InspectorClientImpl* client, | 155 CreateContextGroupTask(InspectorClientImpl* client, |
| 149 TaskRunner::SetupGlobalTasks setup_global_tasks, | 156 TaskRunner::SetupGlobalTasks setup_global_tasks, |
| 150 v8::base::Semaphore* ready_semaphore, | 157 v8::base::Semaphore* ready_semaphore, |
| 151 int* context_group_id) | 158 int* context_group_id) |
| 152 : client_(client), | 159 : client_(client), |
| 153 setup_global_tasks_(std::move(setup_global_tasks)), | 160 setup_global_tasks_(std::move(setup_global_tasks)), |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 v8_inspector::StringView()); | 217 v8_inspector::StringView()); |
| 211 info.hasMemoryOnConsole = true; | 218 info.hasMemoryOnConsole = true; |
| 212 inspector_->contextCreated(info); | 219 inspector_->contextCreated(info); |
| 213 } | 220 } |
| 214 } | 221 } |
| 215 states_.clear(); | 222 states_.clear(); |
| 216 } | 223 } |
| 217 | 224 |
| 218 void InspectorClientImpl::scheduleReconnect( | 225 void InspectorClientImpl::scheduleReconnect( |
| 219 v8::base::Semaphore* ready_semaphore) { | 226 v8::base::Semaphore* ready_semaphore) { |
| 220 task_runner_->Append(new DisconnectTask(this)); | 227 task_runner_->Append( |
| 228 new DisconnectTask(this, /* reset_inspector */ true, nullptr)); |
| 221 task_runner_->Append(new ConnectTask(this, ready_semaphore)); | 229 task_runner_->Append(new ConnectTask(this, ready_semaphore)); |
| 222 } | 230 } |
| 223 | 231 |
| 224 void InspectorClientImpl::disconnect() { | 232 void InspectorClientImpl::scheduleDisconnect( |
| 233 v8::base::Semaphore* ready_semaphore) { |
| 234 task_runner_->Append( |
| 235 new DisconnectTask(this, /* reset_inspector */ false, ready_semaphore)); |
| 236 } |
| 237 |
| 238 void InspectorClientImpl::disconnect(bool reset_inspector) { |
| 225 for (const auto& it : sessions_) { | 239 for (const auto& it : sessions_) { |
| 226 states_[it.first] = it.second->stateJSON(); | 240 states_[it.first] = it.second->stateJSON(); |
| 227 } | 241 } |
| 228 sessions_.clear(); | 242 sessions_.clear(); |
| 229 inspector_.reset(); | 243 if (reset_inspector) inspector_.reset(); |
| 230 } | 244 } |
| 231 | 245 |
| 232 void InspectorClientImpl::scheduleCreateContextGroup( | 246 void InspectorClientImpl::scheduleCreateContextGroup( |
| 233 TaskRunner::SetupGlobalTasks setup_global_tasks, | 247 TaskRunner::SetupGlobalTasks setup_global_tasks, |
| 234 v8::base::Semaphore* ready_semaphore, int* context_group_id) { | 248 v8::base::Semaphore* ready_semaphore, int* context_group_id) { |
| 235 task_runner_->Append(new CreateContextGroupTask( | 249 task_runner_->Append(new CreateContextGroupTask( |
| 236 this, std::move(setup_global_tasks), ready_semaphore, context_group_id)); | 250 this, std::move(setup_global_tasks), ready_semaphore, context_group_id)); |
| 237 } | 251 } |
| 238 | 252 |
| 239 int InspectorClientImpl::createContextGroup( | 253 int InspectorClientImpl::createContextGroup( |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 { | 366 { |
| 353 v8::HandleScope handle_scope(isolate); | 367 v8::HandleScope handle_scope(isolate); |
| 354 v8::Local<v8::Context> context = global_context.Get(isolate); | 368 v8::Local<v8::Context> context = global_context.Get(isolate); |
| 355 if (!context_group_id_) { | 369 if (!context_group_id_) { |
| 356 session = InspectorClientImpl::SessionFromContext(context); | 370 session = InspectorClientImpl::SessionFromContext(context); |
| 357 } else { | 371 } else { |
| 358 session = InspectorClientFromContext(context) | 372 session = InspectorClientFromContext(context) |
| 359 ->sessions_[context_group_id_] | 373 ->sessions_[context_group_id_] |
| 360 .get(); | 374 .get(); |
| 361 } | 375 } |
| 362 CHECK(session); | 376 if (!session) return; |
| 363 } | 377 } |
| 364 v8_inspector::StringView message_view(message_.start(), message_.length()); | 378 v8_inspector::StringView message_view(message_.start(), message_.length()); |
| 365 session->dispatchProtocolMessage(message_view); | 379 session->dispatchProtocolMessage(message_view); |
| 366 } | 380 } |
| 367 | 381 |
| 368 private: | 382 private: |
| 369 v8::internal::Vector<uint16_t> message_; | 383 v8::internal::Vector<uint16_t> message_; |
| 370 int context_group_id_; | 384 int context_group_id_; |
| 371 }; | 385 }; |
| 372 | 386 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 383 } | 397 } |
| 384 | 398 |
| 385 void SendMessageToBackendExtension::SendMessageToBackend( | 399 void SendMessageToBackendExtension::SendMessageToBackend( |
| 386 const v8::FunctionCallbackInfo<v8::Value>& args) { | 400 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 387 CHECK(backend_task_runner_); | 401 CHECK(backend_task_runner_); |
| 388 CHECK(args.Length() == 2 && args[0]->IsString() && args[1]->IsInt32()); | 402 CHECK(args.Length() == 2 && args[0]->IsString() && args[1]->IsInt32()); |
| 389 v8::Local<v8::String> message = args[0].As<v8::String>(); | 403 v8::Local<v8::String> message = args[0].As<v8::String>(); |
| 390 backend_task_runner_->Append(new SendMessageToBackendTask( | 404 backend_task_runner_->Append(new SendMessageToBackendTask( |
| 391 ToVector(message), args[1].As<v8::Int32>()->Value())); | 405 ToVector(message), args[1].As<v8::Int32>()->Value())); |
| 392 } | 406 } |
| OLD | NEW |