Commit fa72e802 authored by Michael Bai's avatar Michael Bai Committed by Commit Bot

ContentCapture Refactoring: Remove SentNodes class

SentNodes is a wrapper of HeapHashSet and has little value be a
separated class.

This patch also moves SentNodes to TaskSession, it was used to
share the SentNode between the different ContentCaptureTasks, but
ContentCaptureTask will never be recreated.

Bug: 1137463
Change-Id: Ic8f958a8ae4da957fd3ab49e1b65faa9508acac4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2466505Reviewed-by: default avatarXianzhu Wang <wangxianzhu@chromium.org>
Commit-Queue: Michael Bai <michaelbai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816399}
parent e9dd9c5a
...@@ -16,8 +16,6 @@ blink_core_sources("content_capture") { ...@@ -16,8 +16,6 @@ blink_core_sources("content_capture") {
"content_capture_task_histogram_reporter.h", "content_capture_task_histogram_reporter.h",
"content_holder.cc", "content_holder.cc",
"content_holder.h", "content_holder.h",
"sent_nodes.cc",
"sent_nodes.h",
"task_session.cc", "task_session.cc",
"task_session.h", "task_session.h",
] ]
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "third_party/blink/renderer/core/content_capture/content_capture_manager.h" #include "third_party/blink/renderer/core/content_capture/content_capture_manager.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "third_party/blink/renderer/core/content_capture/sent_nodes.h"
#include "third_party/blink/renderer/core/frame/local_frame.h" #include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/layout/layout_text.h" #include "third_party/blink/renderer/core/layout/layout_text.h"
...@@ -29,8 +28,7 @@ void ContentCaptureManager::UserActivation::Trace(Visitor* visitor) const { ...@@ -29,8 +28,7 @@ void ContentCaptureManager::UserActivation::Trace(Visitor* visitor) const {
ContentCaptureManager::ContentCaptureManager(LocalFrame& local_frame_root) ContentCaptureManager::ContentCaptureManager(LocalFrame& local_frame_root)
: local_frame_root_(&local_frame_root) { : local_frame_root_(&local_frame_root) {
DCHECK(local_frame_root.IsLocalRoot()); DCHECK(local_frame_root.IsLocalRoot());
sent_nodes_ = MakeGarbageCollected<SentNodes>(); task_session_ = MakeGarbageCollected<TaskSession>();
task_session_ = MakeGarbageCollected<TaskSession>(*sent_nodes_);
} }
ContentCaptureManager::~ContentCaptureManager() = default; ContentCaptureManager::~ContentCaptureManager() = default;
...@@ -114,7 +112,6 @@ void ContentCaptureManager::Trace(Visitor* visitor) const { ...@@ -114,7 +112,6 @@ void ContentCaptureManager::Trace(Visitor* visitor) const {
visitor->Trace(content_capture_idle_task_); visitor->Trace(content_capture_idle_task_);
visitor->Trace(local_frame_root_); visitor->Trace(local_frame_root_);
visitor->Trace(task_session_); visitor->Trace(task_session_);
visitor->Trace(sent_nodes_);
visitor->Trace(latest_user_activation_); visitor->Trace(latest_user_activation_);
} }
......
...@@ -16,7 +16,6 @@ namespace blink { ...@@ -16,7 +16,6 @@ namespace blink {
class LocalFrame; class LocalFrame;
class Node; class Node;
class SentNodes;
// This class is used to create the NodeHolder, and start the ContentCaptureTask // This class is used to create the NodeHolder, and start the ContentCaptureTask
// when necessary. The ContentCaptureManager is owned by main frame. // when necessary. The ContentCaptureManager is owned by main frame.
...@@ -83,9 +82,6 @@ class CORE_EXPORT ContentCaptureManager ...@@ -83,9 +82,6 @@ class CORE_EXPORT ContentCaptureManager
Member<TaskSession> task_session_; Member<TaskSession> task_session_;
// A set of weak reference of the node that has been sent.
Member<SentNodes> sent_nodes_;
// The latest user activation in any frame of the |local_frame_root_|. // The latest user activation in any frame of the |local_frame_root_|.
Member<UserActivation> latest_user_activation_; Member<UserActivation> latest_user_activation_;
}; };
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/content_capture/sent_nodes.h"
#include "third_party/blink/renderer/core/dom/node.h"
namespace blink {
bool SentNodes::HasSent(const Node& node) {
return sent_nodes_.Contains(&node);
}
void SentNodes::OnSent(const Node& node) {
sent_nodes_.insert(WeakMember<const Node>(&node));
}
void SentNodes::Trace(Visitor* visitor) const {
visitor->Trace(sent_nodes_);
}
} // namespace blink
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CONTENT_CAPTURE_SENT_NODES_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_CONTENT_CAPTURE_SENT_NODES_H_
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/heap_allocator.h"
#include "third_party/blink/renderer/platform/heap/member.h"
namespace blink {
class Node;
// The class manages a list of nodes that have been sent, is only used when
// kNodeID is used, see WebContentCaptureClient::GetNodeType().
class SentNodes final : public GarbageCollected<SentNodes> {
public:
bool HasSent(const Node& node);
void OnSent(const Node& node);
void Trace(Visitor*) const;
private:
HeapHashSet<WeakMember<const Node>> sent_nodes_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_CONTENT_CAPTURE_SENT_NODES_H_
...@@ -6,14 +6,14 @@ ...@@ -6,14 +6,14 @@
#include <utility> #include <utility>
#include "third_party/blink/renderer/core/content_capture/sent_nodes.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/dom_node_ids.h" #include "third_party/blink/renderer/core/dom/dom_node_ids.h"
namespace blink { namespace blink {
TaskSession::DocumentSession::DocumentSession(const Document& document, TaskSession::DocumentSession::DocumentSession(
SentNodes& sent_nodes, const Document& document,
HeapHashSet<WeakMember<const Node>>& sent_nodes,
SentNodeCountCallback& callback) SentNodeCountCallback& callback)
: document_(&document), sent_nodes_(&sent_nodes), callback_(callback) {} : document_(&document), sent_nodes_(&sent_nodes), callback_(callback) {}
...@@ -46,8 +46,8 @@ ContentHolder* TaskSession::DocumentSession::GetNextUnsentNode() { ...@@ -46,8 +46,8 @@ ContentHolder* TaskSession::DocumentSession::GetNextUnsentNode() {
while (!captured_content_.IsEmpty()) { while (!captured_content_.IsEmpty()) {
auto node = captured_content_.begin()->key; auto node = captured_content_.begin()->key;
const gfx::Rect rect = captured_content_.Take(node); const gfx::Rect rect = captured_content_.Take(node);
if (node && node->GetLayoutObject() && !sent_nodes_->HasSent(*node)) { if (node && node->GetLayoutObject() && !sent_nodes_->Contains(node)) {
sent_nodes_->OnSent(*node); sent_nodes_->insert(WeakMember<const Node>(node));
total_sent_nodes_++; total_sent_nodes_++;
return MakeGarbageCollected<ContentHolder>(node, rect); return MakeGarbageCollected<ContentHolder>(node, rect);
} }
...@@ -69,7 +69,6 @@ ContentHolder* TaskSession::DocumentSession::GetNextChangedNode() { ...@@ -69,7 +69,6 @@ ContentHolder* TaskSession::DocumentSession::GetNextChangedNode() {
void TaskSession::DocumentSession::Trace(Visitor* visitor) const { void TaskSession::DocumentSession::Trace(Visitor* visitor) const {
visitor->Trace(captured_content_); visitor->Trace(captured_content_);
visitor->Trace(sent_nodes_);
visitor->Trace(document_); visitor->Trace(document_);
visitor->Trace(changed_content_); visitor->Trace(changed_content_);
} }
...@@ -80,7 +79,7 @@ void TaskSession::DocumentSession::Reset() { ...@@ -80,7 +79,7 @@ void TaskSession::DocumentSession::Reset() {
detached_nodes_.Clear(); detached_nodes_.Clear();
} }
TaskSession::TaskSession(SentNodes& sent_nodes) : sent_nodes_(sent_nodes) {} TaskSession::TaskSession() = default;
TaskSession::DocumentSession* TaskSession::GetNextUnsentDocumentSession() { TaskSession::DocumentSession* TaskSession::GetNextUnsentDocumentSession() {
for (auto& doc : to_document_session_.Values()) { for (auto& doc : to_document_session_.Values()) {
...@@ -109,7 +108,7 @@ void TaskSession::GroupCapturedContentByDocument( ...@@ -109,7 +108,7 @@ void TaskSession::GroupCapturedContentByDocument(
if (Node* node = DOMNodeIds::NodeForId(i.node_id)) { if (Node* node = DOMNodeIds::NodeForId(i.node_id)) {
if (changed_nodes_.Take(node)) { if (changed_nodes_.Take(node)) {
// The changed node might not be sent. // The changed node might not be sent.
if (sent_nodes_->HasSent(*node)) { if (sent_nodes_.Contains(node)) {
EnsureDocumentSession(node->GetDocument()) EnsureDocumentSession(node->GetDocument())
.AddChangedNode(*node, i.visual_rect); .AddChangedNode(*node, i.visual_rect);
} else { } else {
...@@ -118,7 +117,7 @@ void TaskSession::GroupCapturedContentByDocument( ...@@ -118,7 +117,7 @@ void TaskSession::GroupCapturedContentByDocument(
} }
continue; continue;
} }
if (!sent_nodes_->HasSent(*node)) { if (!sent_nodes_.Contains(node)) {
EnsureDocumentSession(node->GetDocument()) EnsureDocumentSession(node->GetDocument())
.AddCapturedNode(*node, i.visual_rect); .AddCapturedNode(*node, i.visual_rect);
} }
...@@ -127,7 +126,7 @@ void TaskSession::GroupCapturedContentByDocument( ...@@ -127,7 +126,7 @@ void TaskSession::GroupCapturedContentByDocument(
} }
void TaskSession::OnNodeDetached(const Node& node) { void TaskSession::OnNodeDetached(const Node& node) {
if (sent_nodes_->HasSent(node)) { if (sent_nodes_.Contains(&node)) {
EnsureDocumentSession(node.GetDocument()) EnsureDocumentSession(node.GetDocument())
.AddDetachedNode(reinterpret_cast<int64_t>(&node)); .AddDetachedNode(reinterpret_cast<int64_t>(&node));
has_unsent_data_ = true; has_unsent_data_ = true;
...@@ -143,7 +142,7 @@ TaskSession::DocumentSession& TaskSession::EnsureDocumentSession( ...@@ -143,7 +142,7 @@ TaskSession::DocumentSession& TaskSession::EnsureDocumentSession(
DocumentSession* doc_session = GetDocumentSession(doc); DocumentSession* doc_session = GetDocumentSession(doc);
if (!doc_session) { if (!doc_session) {
doc_session = doc_session =
MakeGarbageCollected<DocumentSession>(doc, *sent_nodes_, callback_); MakeGarbageCollected<DocumentSession>(doc, sent_nodes_, callback_);
to_document_session_.insert(&doc, doc_session); to_document_session_.insert(&doc, doc_session);
} }
return *doc_session; return *doc_session;
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
namespace blink { namespace blink {
class Document; class Document;
class SentNodes;
// This class wraps the captured content and the detached nodes that need to be // This class wraps the captured content and the detached nodes that need to be
// sent out by the ContentCaptureTask, it has a Document to DocumentSession // sent out by the ContentCaptureTask, it has a Document to DocumentSession
...@@ -51,7 +50,7 @@ class TaskSession final : public GarbageCollected<TaskSession> { ...@@ -51,7 +50,7 @@ class TaskSession final : public GarbageCollected<TaskSession> {
using SentNodeCountCallback = base::RepeatingCallback<void(size_t)>; using SentNodeCountCallback = base::RepeatingCallback<void(size_t)>;
DocumentSession(const Document& document, DocumentSession(const Document& document,
SentNodes& sent_nodes, HeapHashSet<WeakMember<const Node>>& sent_nodes,
SentNodeCountCallback& call_back); SentNodeCountCallback& call_back);
~DocumentSession(); ~DocumentSession();
void AddCapturedNode(Node& node, const gfx::Rect& rect); void AddCapturedNode(Node& node, const gfx::Rect& rect);
...@@ -90,7 +89,7 @@ class TaskSession final : public GarbageCollected<TaskSession> { ...@@ -90,7 +89,7 @@ class TaskSession final : public GarbageCollected<TaskSession> {
// LayoutTree. // LayoutTree.
WebVector<int64_t> detached_nodes_; WebVector<int64_t> detached_nodes_;
WeakMember<const Document> document_; WeakMember<const Document> document_;
Member<SentNodes> sent_nodes_; HeapHashSet<WeakMember<const Node>>* sent_nodes_;
// The list of changed nodes that needs to be sent. // The list of changed nodes that needs to be sent.
HeapHashMap<WeakMember<Node>, gfx::Rect> changed_content_; HeapHashMap<WeakMember<Node>, gfx::Rect> changed_content_;
...@@ -102,7 +101,7 @@ class TaskSession final : public GarbageCollected<TaskSession> { ...@@ -102,7 +101,7 @@ class TaskSession final : public GarbageCollected<TaskSession> {
base::Optional<SentNodeCountCallback> callback_; base::Optional<SentNodeCountCallback> callback_;
}; };
TaskSession(SentNodes& sent_nodes); TaskSession();
// Returns the DocumentSession that hasn't been sent. // Returns the DocumentSession that hasn't been sent.
DocumentSession* GetNextUnsentDocumentSession(); DocumentSession* GetNextUnsentDocumentSession();
...@@ -132,7 +131,8 @@ class TaskSession final : public GarbageCollected<TaskSession> { ...@@ -132,7 +131,8 @@ class TaskSession final : public GarbageCollected<TaskSession> {
DocumentSession& EnsureDocumentSession(const Document& doc); DocumentSession& EnsureDocumentSession(const Document& doc);
DocumentSession* GetDocumentSession(const Document& document) const; DocumentSession* GetDocumentSession(const Document& document) const;
Member<SentNodes> sent_nodes_; // A set of weak reference of the node that has been sent.
HeapHashSet<WeakMember<const Node>> sent_nodes_;
// The list of node whose value has changed. // The list of node whose value has changed.
HeapHashSet<WeakMember<Node>> changed_nodes_; HeapHashSet<WeakMember<Node>> changed_nodes_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment