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 "src/inspector/v8-console-message.h" | 5 #include "src/inspector/v8-console-message.h" |
6 | 6 |
7 #include "src/debug/debug-interface.h" | 7 #include "src/debug/debug-interface.h" |
8 #include "src/inspector/inspected-context.h" | 8 #include "src/inspector/inspected-context.h" |
9 #include "src/inspector/protocol/Protocol.h" | 9 #include "src/inspector/protocol/Protocol.h" |
10 #include "src/inspector/string-util.h" | 10 #include "src/inspector/string-util.h" |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 : m_inspector(inspector), m_contextGroupId(contextGroupId) {} | 452 : m_inspector(inspector), m_contextGroupId(contextGroupId) {} |
453 | 453 |
454 V8ConsoleMessageStorage::~V8ConsoleMessageStorage() { clear(); } | 454 V8ConsoleMessageStorage::~V8ConsoleMessageStorage() { clear(); } |
455 | 455 |
456 void V8ConsoleMessageStorage::addMessage( | 456 void V8ConsoleMessageStorage::addMessage( |
457 std::unique_ptr<V8ConsoleMessage> message) { | 457 std::unique_ptr<V8ConsoleMessage> message) { |
458 int contextGroupId = m_contextGroupId; | 458 int contextGroupId = m_contextGroupId; |
459 V8InspectorImpl* inspector = m_inspector; | 459 V8InspectorImpl* inspector = m_inspector; |
460 if (message->type() == ConsoleAPIType::kClear) clear(); | 460 if (message->type() == ConsoleAPIType::kClear) clear(); |
461 | 461 |
462 V8InspectorSessionImpl* session = | 462 inspector->forEachSession( |
463 inspector->sessionForContextGroup(contextGroupId); | 463 contextGroupId, [&message](V8InspectorSessionImpl* session) { |
464 if (session) { | 464 if (message->origin() == V8MessageOrigin::kConsole) |
465 if (message->origin() == V8MessageOrigin::kConsole) | 465 session->consoleAgent()->messageAdded(message.get()); |
466 session->consoleAgent()->messageAdded(message.get()); | 466 session->runtimeAgent()->messageAdded(message.get()); |
467 session->runtimeAgent()->messageAdded(message.get()); | 467 }); |
468 } | |
469 if (!inspector->hasConsoleMessageStorage(contextGroupId)) return; | 468 if (!inspector->hasConsoleMessageStorage(contextGroupId)) return; |
470 | 469 |
471 DCHECK(m_messages.size() <= maxConsoleMessageCount); | 470 DCHECK(m_messages.size() <= maxConsoleMessageCount); |
472 if (m_messages.size() == maxConsoleMessageCount) { | 471 if (m_messages.size() == maxConsoleMessageCount) { |
473 m_estimatedSize -= m_messages.front()->estimatedSize(); | 472 m_estimatedSize -= m_messages.front()->estimatedSize(); |
474 m_messages.pop_front(); | 473 m_messages.pop_front(); |
475 } | 474 } |
476 while (m_estimatedSize + message->estimatedSize() > maxConsoleMessageV8Size && | 475 while (m_estimatedSize + message->estimatedSize() > maxConsoleMessageV8Size && |
477 !m_messages.empty()) { | 476 !m_messages.empty()) { |
478 m_estimatedSize -= m_messages.front()->estimatedSize(); | 477 m_estimatedSize -= m_messages.front()->estimatedSize(); |
479 m_messages.pop_front(); | 478 m_messages.pop_front(); |
480 } | 479 } |
481 | 480 |
482 m_messages.push_back(std::move(message)); | 481 m_messages.push_back(std::move(message)); |
483 m_estimatedSize += m_messages.back()->estimatedSize(); | 482 m_estimatedSize += m_messages.back()->estimatedSize(); |
484 } | 483 } |
485 | 484 |
486 void V8ConsoleMessageStorage::clear() { | 485 void V8ConsoleMessageStorage::clear() { |
487 m_messages.clear(); | 486 m_messages.clear(); |
488 m_estimatedSize = 0; | 487 m_estimatedSize = 0; |
489 if (V8InspectorSessionImpl* session = | 488 m_inspector->forEachSession(m_contextGroupId, |
490 m_inspector->sessionForContextGroup(m_contextGroupId)) { | 489 [](V8InspectorSessionImpl* session) { |
491 session->releaseObjectGroup("console"); | 490 session->releaseObjectGroup("console"); |
492 } | 491 }); |
493 m_data.clear(); | 492 m_data.clear(); |
494 } | 493 } |
495 | 494 |
496 bool V8ConsoleMessageStorage::shouldReportDeprecationMessage( | 495 bool V8ConsoleMessageStorage::shouldReportDeprecationMessage( |
497 int contextId, const String16& method) { | 496 int contextId, const String16& method) { |
498 std::set<String16>& reportedDeprecationMessages = | 497 std::set<String16>& reportedDeprecationMessages = |
499 m_data[contextId].m_reportedDeprecationMessages; | 498 m_data[contextId].m_reportedDeprecationMessages; |
500 auto it = reportedDeprecationMessages.find(method); | 499 auto it = reportedDeprecationMessages.find(method); |
501 if (it != reportedDeprecationMessages.end()) return false; | 500 if (it != reportedDeprecationMessages.end()) return false; |
502 reportedDeprecationMessages.insert(it, method); | 501 reportedDeprecationMessages.insert(it, method); |
(...skipping 21 matching lines...) Expand all Loading... |
524 m_estimatedSize = 0; | 523 m_estimatedSize = 0; |
525 for (size_t i = 0; i < m_messages.size(); ++i) { | 524 for (size_t i = 0; i < m_messages.size(); ++i) { |
526 m_messages[i]->contextDestroyed(contextId); | 525 m_messages[i]->contextDestroyed(contextId); |
527 m_estimatedSize += m_messages[i]->estimatedSize(); | 526 m_estimatedSize += m_messages[i]->estimatedSize(); |
528 } | 527 } |
529 auto it = m_data.find(contextId); | 528 auto it = m_data.find(contextId); |
530 if (it != m_data.end()) m_data.erase(contextId); | 529 if (it != m_data.end()) m_data.erase(contextId); |
531 } | 530 } |
532 | 531 |
533 } // namespace v8_inspector | 532 } // namespace v8_inspector |
OLD | NEW |