Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: test/inspector/inspector-impl.cc

Issue 2885253002: [inspector] Extract IsolateData out of TaskRunner (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/inspector/inspector-impl.h ('k') | test/inspector/inspector-test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 public: 110 public:
111 ConnectTask(InspectorClientImpl* client, v8::base::Semaphore* ready_semaphore) 111 ConnectTask(InspectorClientImpl* client, v8::base::Semaphore* ready_semaphore)
112 : client_(client), ready_semaphore_(ready_semaphore) {} 112 : client_(client), ready_semaphore_(ready_semaphore) {}
113 virtual ~ConnectTask() = default; 113 virtual ~ConnectTask() = default;
114 114
115 bool is_inspector_task() final { return true; } 115 bool is_inspector_task() final { return true; }
116 116
117 private: 117 private:
118 void Run() override { 118 void Run() override {
119 v8::HandleScope handle_scope(isolate()); 119 v8::HandleScope handle_scope(isolate());
120 client_->connect(default_context()); 120 client_->connect();
121 if (ready_semaphore_) ready_semaphore_->Signal(); 121 if (ready_semaphore_) ready_semaphore_->Signal();
122 } 122 }
123 123
124 InspectorClientImpl* client_; 124 InspectorClientImpl* client_;
125 v8::base::Semaphore* ready_semaphore_; 125 v8::base::Semaphore* ready_semaphore_;
126 }; 126 };
127 127
128 class DisconnectTask : public TaskRunner::Task { 128 class DisconnectTask : public TaskRunner::Task {
129 public: 129 public:
130 explicit DisconnectTask(InspectorClientImpl* client, bool reset_inspector, 130 explicit DisconnectTask(InspectorClientImpl* client, bool reset_inspector,
(...skipping 12 matching lines...) Expand all
143 } 143 }
144 144
145 InspectorClientImpl* client_; 145 InspectorClientImpl* client_;
146 bool reset_inspector_; 146 bool reset_inspector_;
147 v8::base::Semaphore* ready_semaphore_; 147 v8::base::Semaphore* ready_semaphore_;
148 }; 148 };
149 149
150 class CreateContextGroupTask : public TaskRunner::Task { 150 class CreateContextGroupTask : public TaskRunner::Task {
151 public: 151 public:
152 CreateContextGroupTask(InspectorClientImpl* client, 152 CreateContextGroupTask(InspectorClientImpl* client,
153 TaskRunner::SetupGlobalTasks setup_global_tasks, 153 IsolateData::SetupGlobalTasks setup_global_tasks,
154 v8::base::Semaphore* ready_semaphore, 154 v8::base::Semaphore* ready_semaphore,
155 int* context_group_id) 155 int* context_group_id)
156 : client_(client), 156 : client_(client),
157 setup_global_tasks_(std::move(setup_global_tasks)), 157 setup_global_tasks_(std::move(setup_global_tasks)),
158 ready_semaphore_(ready_semaphore), 158 ready_semaphore_(ready_semaphore),
159 context_group_id_(context_group_id) {} 159 context_group_id_(context_group_id) {}
160 virtual ~CreateContextGroupTask() = default; 160 virtual ~CreateContextGroupTask() = default;
161 161
162 bool is_inspector_task() final { return true; } 162 bool is_inspector_task() final { return true; }
163 163
164 private: 164 private:
165 void Run() override { 165 void Run() override {
166 *context_group_id_ = client_->createContextGroup(setup_global_tasks_); 166 *context_group_id_ = client_->createContextGroup(setup_global_tasks_);
167 if (ready_semaphore_) ready_semaphore_->Signal(); 167 if (ready_semaphore_) ready_semaphore_->Signal();
168 } 168 }
169 169
170 InspectorClientImpl* client_; 170 InspectorClientImpl* client_;
171 TaskRunner::SetupGlobalTasks setup_global_tasks_; 171 IsolateData::SetupGlobalTasks setup_global_tasks_;
172 v8::base::Semaphore* ready_semaphore_; 172 v8::base::Semaphore* ready_semaphore_;
173 int* context_group_id_; 173 int* context_group_id_;
174 }; 174 };
175 175
176 InspectorClientImpl::InspectorClientImpl(TaskRunner* task_runner, 176 InspectorClientImpl::InspectorClientImpl(TaskRunner* task_runner,
177 FrontendChannel* frontend_channel, 177 FrontendChannel* frontend_channel,
178 v8::base::Semaphore* ready_semaphore) 178 v8::base::Semaphore* ready_semaphore)
179 : isolate_(nullptr), 179 : isolate_(nullptr),
180 task_runner_(task_runner), 180 task_runner_(task_runner),
181 frontend_channel_(frontend_channel) { 181 frontend_channel_(frontend_channel) {
182 task_runner_->Append(new ConnectTask(this, ready_semaphore)); 182 task_runner_->Append(new ConnectTask(this, ready_semaphore));
183 } 183 }
184 184
185 InspectorClientImpl::~InspectorClientImpl() {} 185 InspectorClientImpl::~InspectorClientImpl() {}
186 186
187 void InspectorClientImpl::connect(v8::Local<v8::Context> context) { 187 void InspectorClientImpl::connect() {
188 isolate_ = context->GetIsolate(); 188 isolate_ = task_runner_->data()->isolate();
189 isolate_->AddMessageListener(MessageHandler); 189 isolate_->AddMessageListener(MessageHandler);
190 channel_.reset(new ChannelImpl(frontend_channel_)); 190 channel_.reset(new ChannelImpl(frontend_channel_));
191 inspector_ = v8_inspector::V8Inspector::create(isolate_, this); 191 inspector_ = v8_inspector::V8Inspector::create(isolate_, this);
192 192
193 if (states_.empty()) { 193 if (states_.empty()) {
194 int context_group_id = TaskRunner::GetContextGroupId(context); 194 ConnectToContextGroup(task_runner_->default_context_group_id(),
195 v8_inspector::StringView state; 195 v8_inspector::StringView());
196 sessions_[context_group_id] =
197 inspector_->connect(context_group_id, channel_.get(), state);
198 context->SetAlignedPointerInEmbedderData(kInspectorClientIndex, this);
199 v8_inspector::V8ContextInfo info(context, context_group_id,
200 v8_inspector::StringView());
201 info.hasMemoryOnConsole = true;
202 inspector_->contextCreated(info);
203 } else { 196 } else {
204 for (const auto& it : states_) { 197 for (const auto& it : states_)
205 int context_group_id = it.first; 198 ConnectToContextGroup(it.first, it.second->string());
206 v8::Local<v8::Context> context =
207 task_runner_->GetContext(context_group_id);
208 v8_inspector::StringView state = it.second->string();
209 sessions_[context_group_id] =
210 inspector_->connect(context_group_id, channel_.get(), state);
211 context->SetAlignedPointerInEmbedderData(kInspectorClientIndex, this);
212 v8_inspector::V8ContextInfo info(context, context_group_id,
213 v8_inspector::StringView());
214 info.hasMemoryOnConsole = true;
215 inspector_->contextCreated(info);
216 }
217 } 199 }
218 states_.clear(); 200 states_.clear();
219 } 201 }
220 202
203 void InspectorClientImpl::ConnectToContextGroup(
204 int context_group_id, v8_inspector::StringView state) {
205 v8::Local<v8::Context> context =
206 task_runner_->data()->GetContext(context_group_id);
207 sessions_[context_group_id] =
208 inspector_->connect(context_group_id, channel_.get(), state);
209 context->SetAlignedPointerInEmbedderData(kInspectorClientIndex, this);
210 v8_inspector::V8ContextInfo info(context, context_group_id,
211 v8_inspector::StringView());
212 info.hasMemoryOnConsole = true;
213 inspector_->contextCreated(info);
214 }
215
221 void InspectorClientImpl::scheduleReconnect( 216 void InspectorClientImpl::scheduleReconnect(
222 v8::base::Semaphore* ready_semaphore) { 217 v8::base::Semaphore* ready_semaphore) {
223 task_runner_->Append( 218 task_runner_->Append(
224 new DisconnectTask(this, /* reset_inspector */ true, nullptr)); 219 new DisconnectTask(this, /* reset_inspector */ true, nullptr));
225 task_runner_->Append(new ConnectTask(this, ready_semaphore)); 220 task_runner_->Append(new ConnectTask(this, ready_semaphore));
226 } 221 }
227 222
228 void InspectorClientImpl::scheduleDisconnect( 223 void InspectorClientImpl::scheduleDisconnect(
229 v8::base::Semaphore* ready_semaphore) { 224 v8::base::Semaphore* ready_semaphore) {
230 task_runner_->Append( 225 task_runner_->Append(
231 new DisconnectTask(this, /* reset_inspector */ false, ready_semaphore)); 226 new DisconnectTask(this, /* reset_inspector */ false, ready_semaphore));
232 } 227 }
233 228
234 void InspectorClientImpl::disconnect(bool reset_inspector) { 229 void InspectorClientImpl::disconnect(bool reset_inspector) {
235 for (const auto& it : sessions_) { 230 for (const auto& it : sessions_) {
236 states_[it.first] = it.second->stateJSON(); 231 states_[it.first] = it.second->stateJSON();
237 } 232 }
238 sessions_.clear(); 233 sessions_.clear();
239 if (reset_inspector) inspector_.reset(); 234 if (reset_inspector) inspector_.reset();
240 } 235 }
241 236
242 void InspectorClientImpl::scheduleCreateContextGroup( 237 void InspectorClientImpl::scheduleCreateContextGroup(
243 TaskRunner::SetupGlobalTasks setup_global_tasks, 238 IsolateData::SetupGlobalTasks setup_global_tasks,
244 v8::base::Semaphore* ready_semaphore, int* context_group_id) { 239 v8::base::Semaphore* ready_semaphore, int* context_group_id) {
245 task_runner_->Append(new CreateContextGroupTask( 240 task_runner_->Append(new CreateContextGroupTask(
246 this, std::move(setup_global_tasks), ready_semaphore, context_group_id)); 241 this, std::move(setup_global_tasks), ready_semaphore, context_group_id));
247 } 242 }
248 243
249 int InspectorClientImpl::createContextGroup( 244 int InspectorClientImpl::createContextGroup(
250 const TaskRunner::SetupGlobalTasks& setup_global_tasks) { 245 const IsolateData::SetupGlobalTasks& setup_global_tasks) {
251 v8::HandleScope handle_scope(isolate_); 246 v8::HandleScope handle_scope(isolate_);
247 int context_group_id = task_runner_->data()->CreateContextGroup();
252 v8::Local<v8::Context> context = 248 v8::Local<v8::Context> context =
253 task_runner_->NewContextGroup(setup_global_tasks); 249 task_runner_->data()->GetContext(context_group_id);
254 context->SetAlignedPointerInEmbedderData(kInspectorClientIndex, this); 250 context->SetAlignedPointerInEmbedderData(kInspectorClientIndex, this);
255 int context_group_id = TaskRunner::GetContextGroupId(context);
256 v8_inspector::StringView state; 251 v8_inspector::StringView state;
257 sessions_[context_group_id] = 252 sessions_[context_group_id] =
258 inspector_->connect(context_group_id, channel_.get(), state); 253 inspector_->connect(context_group_id, channel_.get(), state);
259 inspector_->contextCreated(v8_inspector::V8ContextInfo( 254 inspector_->contextCreated(v8_inspector::V8ContextInfo(
260 context, context_group_id, v8_inspector::StringView())); 255 context, context_group_id, v8_inspector::StringView()));
261 return context_group_id; 256 return context_group_id;
262 } 257 }
263 258
264 bool InspectorClientImpl::formatAccessorsAsProperties( 259 bool InspectorClientImpl::formatAccessorsAsProperties(
265 v8::Local<v8::Value> object) { 260 v8::Local<v8::Value> object) {
266 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 261 v8::Isolate* isolate = v8::Isolate::GetCurrent();
267 v8::Local<v8::Context> context = isolate->GetCurrentContext(); 262 v8::Local<v8::Context> context = isolate->GetCurrentContext();
268 v8::Local<v8::Private> shouldFormatAccessorsPrivate = v8::Private::ForApi( 263 v8::Local<v8::Private> shouldFormatAccessorsPrivate = v8::Private::ForApi(
269 isolate, v8::String::NewFromUtf8(isolate, "allowAccessorFormatting", 264 isolate, v8::String::NewFromUtf8(isolate, "allowAccessorFormatting",
270 v8::NewStringType::kNormal) 265 v8::NewStringType::kNormal)
271 .ToLocalChecked()); 266 .ToLocalChecked());
272 CHECK(object->IsObject()); 267 CHECK(object->IsObject());
273 return object.As<v8::Object>() 268 return object.As<v8::Object>()
274 ->HasPrivate(context, shouldFormatAccessorsPrivate) 269 ->HasPrivate(context, shouldFormatAccessorsPrivate)
275 .FromMaybe(false); 270 .FromMaybe(false);
276 } 271 }
277 272
278 v8::Local<v8::Context> InspectorClientImpl::ensureDefaultContextInGroup( 273 v8::Local<v8::Context> InspectorClientImpl::ensureDefaultContextInGroup(
279 int context_group_id) { 274 int context_group_id) {
280 CHECK(isolate_); 275 CHECK(isolate_);
281 return task_runner_->GetContext(context_group_id); 276 return task_runner_->data()->GetContext(context_group_id);
282 } 277 }
283 278
284 void InspectorClientImpl::setCurrentTimeMSForTest(double time) { 279 void InspectorClientImpl::setCurrentTimeMSForTest(double time) {
285 current_time_ = time; 280 current_time_ = time;
286 current_time_set_for_test_ = true; 281 current_time_set_for_test_ = true;
287 } 282 }
288 283
289 double InspectorClientImpl::currentTimeMS() { 284 double InspectorClientImpl::currentTimeMS() {
290 if (current_time_set_for_test_) return current_time_; 285 if (current_time_set_for_test_) return current_time_;
291 return v8::base::OS::TimeCurrentMillis(); 286 return v8::base::OS::TimeCurrentMillis();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 fprintf(stdout, "\n"); 323 fprintf(stdout, "\n");
329 } 324 }
330 325
331 v8_inspector::V8Inspector* InspectorClientImpl::InspectorFromContext( 326 v8_inspector::V8Inspector* InspectorClientImpl::InspectorFromContext(
332 v8::Local<v8::Context> context) { 327 v8::Local<v8::Context> context) {
333 return InspectorClientFromContext(context)->inspector_.get(); 328 return InspectorClientFromContext(context)->inspector_.get();
334 } 329 }
335 330
336 v8_inspector::V8InspectorSession* InspectorClientImpl::SessionFromContext( 331 v8_inspector::V8InspectorSession* InspectorClientImpl::SessionFromContext(
337 v8::Local<v8::Context> context) { 332 v8::Local<v8::Context> context) {
338 int context_group_id = TaskRunner::GetContextGroupId(context); 333 InspectorClientImpl* client = InspectorClientFromContext(context);
339 return InspectorClientFromContext(context)->sessions_[context_group_id].get(); 334 for (auto& it : client->sessions_) {
335 if (client->task_runner_->data()->GetContext(it.first) == context)
336 return it.second.get();
337 }
338 return nullptr;
340 } 339 }
341 340
342 v8_inspector::V8InspectorSession* InspectorClientImpl::session( 341 v8_inspector::V8InspectorSession* InspectorClientImpl::session(
343 int context_group_id) { 342 int context_group_id) {
344 if (context_group_id) { 343 if (context_group_id) {
345 return sessions_[context_group_id].get(); 344 return sessions_[context_group_id].get();
346 } else { 345 } else {
347 return sessions_.begin()->second.get(); 346 return sessions_.begin()->second.get();
348 } 347 }
349 } 348 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 } 390 }
392 391
393 void SendMessageToBackendExtension::SendMessageToBackend( 392 void SendMessageToBackendExtension::SendMessageToBackend(
394 const v8::FunctionCallbackInfo<v8::Value>& args) { 393 const v8::FunctionCallbackInfo<v8::Value>& args) {
395 CHECK(backend_task_runner_); 394 CHECK(backend_task_runner_);
396 CHECK(args.Length() == 2 && args[0]->IsString() && args[1]->IsInt32()); 395 CHECK(args.Length() == 2 && args[0]->IsString() && args[1]->IsInt32());
397 v8::Local<v8::String> message = args[0].As<v8::String>(); 396 v8::Local<v8::String> message = args[0].As<v8::String>();
398 backend_task_runner_->Append(new SendMessageToBackendTask( 397 backend_task_runner_->Append(new SendMessageToBackendTask(
399 ToVector(message), args[1].As<v8::Int32>()->Value())); 398 ToVector(message), args[1].As<v8::Int32>()->Value()));
400 } 399 }
OLDNEW
« no previous file with comments | « test/inspector/inspector-impl.h ('k') | test/inspector/inspector-test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698