#include "chrome/browser/ui/webui/discards/graph_dump_impl.h"
#include <memory>
#include <utility>
#include "base/base64.h"
#include "base/functional/bind.h"
#include "base/json/json_string_value_serializer.h"
#include "base/memory/weak_ptr.h"
#include "base/not_fatal_until.h"
#include "base/task/bind_post_task.h"
#include "base/task/cancelable_task_tracker.h"
#include "base/task/sequenced_task_runner.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/discards/discards.mojom.h"
#include "components/favicon/core/favicon_service.h"
#include "components/favicon_base/favicon_callback.h"
#include "components/performance_manager/public/graph/graph.h"
#include "components/performance_manager/public/graph/node_data_describer.h"
#include "components/performance_manager/public/graph/node_data_describer_registry.h"
#include "components/performance_manager/public/performance_manager.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace {
std::string ToJSON(const base::Value::Dict& value) { … }
}
class DiscardsGraphDumpImpl::FaviconRequestHelper { … };
void DiscardsGraphDumpImpl::FaviconRequestHelper::RequestFavicon(
GURL page_url,
base::WeakPtr<content::WebContents> web_contents,
FaviconAvailableCallback on_favicon_available) { … }
void DiscardsGraphDumpImpl::FaviconRequestHelper::FaviconDataAvailable(
FaviconAvailableCallback on_favicon_available,
const favicon_base::FaviconRawBitmapResult& result) { … }
DiscardsGraphDumpImpl::DiscardsGraphDumpImpl() { … }
DiscardsGraphDumpImpl::~DiscardsGraphDumpImpl() { … }
void DiscardsGraphDumpImpl::CreateAndBind(
mojo::PendingReceiver<discards::mojom::GraphDump> receiver,
performance_manager::Graph* graph) { … }
void DiscardsGraphDumpImpl::BindWithGraph(
performance_manager::Graph* graph,
mojo::PendingReceiver<discards::mojom::GraphDump> receiver) { … }
int64_t DiscardsGraphDumpImpl::GetNodeIdForTesting(
const performance_manager::Node* node) { … }
namespace {
template <typename FunctionType>
void ForFrameAndOffspring(const performance_manager::FrameNode* parent_frame,
FunctionType on_frame) { … }
}
void DiscardsGraphDumpImpl::SubscribeToChanges(
mojo::PendingRemote<discards::mojom::GraphChangeStream> change_subscriber) { … }
void DiscardsGraphDumpImpl::RequestNodeDescriptions(
const std::vector<int64_t>& node_ids,
RequestNodeDescriptionsCallback callback) { … }
void DiscardsGraphDumpImpl::OnPassedToGraph(performance_manager::Graph* graph) { … }
void DiscardsGraphDumpImpl::OnTakenFromGraph(
performance_manager::Graph* graph) { … }
void DiscardsGraphDumpImpl::OnFrameNodeAdded(
const performance_manager::FrameNode* frame_node) { … }
void DiscardsGraphDumpImpl::OnBeforeFrameNodeRemoved(
const performance_manager::FrameNode* frame_node) { … }
void DiscardsGraphDumpImpl::OnURLChanged(
const performance_manager::FrameNode* frame_node,
const GURL& previous_value) { … }
void DiscardsGraphDumpImpl::OnPageNodeAdded(
const performance_manager::PageNode* page_node) { … }
void DiscardsGraphDumpImpl::OnBeforePageNodeRemoved(
const performance_manager::PageNode* page_node) { … }
void DiscardsGraphDumpImpl::OnOpenerFrameNodeChanged(
const performance_manager::PageNode* page_node,
const performance_manager::FrameNode* previous_opener) { … }
void DiscardsGraphDumpImpl::OnEmbedderFrameNodeChanged(
const performance_manager::PageNode* page_node,
const performance_manager::FrameNode*,
EmbeddingType) { … }
void DiscardsGraphDumpImpl::OnFaviconUpdated(
const performance_manager::PageNode* page_node) { … }
void DiscardsGraphDumpImpl::OnMainFrameUrlChanged(
const performance_manager::PageNode* page_node) { … }
void DiscardsGraphDumpImpl::OnProcessNodeAdded(
const performance_manager::ProcessNode* process_node) { … }
void DiscardsGraphDumpImpl::OnProcessLifetimeChange(
const performance_manager::ProcessNode* process_node) { … }
void DiscardsGraphDumpImpl::OnBeforeProcessNodeRemoved(
const performance_manager::ProcessNode* process_node) { … }
void DiscardsGraphDumpImpl::OnWorkerNodeAdded(
const performance_manager::WorkerNode* worker_node) { … }
void DiscardsGraphDumpImpl::OnBeforeWorkerNodeRemoved(
const performance_manager::WorkerNode* worker_node) { … }
void DiscardsGraphDumpImpl::OnFinalResponseURLDetermined(
const performance_manager::WorkerNode* worker_node) { … }
void DiscardsGraphDumpImpl::OnBeforeClientFrameAdded(
const performance_manager::WorkerNode* worker_node,
const performance_manager::FrameNode* client_frame_node) { … }
void DiscardsGraphDumpImpl::OnClientFrameAdded(
const performance_manager::WorkerNode* worker_node,
const performance_manager::FrameNode* client_frame_node) { … }
void DiscardsGraphDumpImpl::OnBeforeClientFrameRemoved(
const performance_manager::WorkerNode* worker_node,
const performance_manager::FrameNode* client_frame_node) { … }
void DiscardsGraphDumpImpl::OnBeforeClientWorkerAdded(
const performance_manager::WorkerNode* worker_node,
const performance_manager::WorkerNode* client_worker_node) { … }
void DiscardsGraphDumpImpl::OnClientWorkerAdded(
const performance_manager::WorkerNode* worker_node,
const performance_manager::WorkerNode* client_worker_node) { … }
void DiscardsGraphDumpImpl::OnBeforeClientWorkerRemoved(
const performance_manager::WorkerNode* worker_node,
const performance_manager::WorkerNode* client_worker_node) { … }
void DiscardsGraphDumpImpl::AddNode(const performance_manager::Node* node) { … }
void DiscardsGraphDumpImpl::RemoveNode(const performance_manager::Node* node) { … }
bool DiscardsGraphDumpImpl::HasNode(
const performance_manager::Node* node) const { … }
int64_t DiscardsGraphDumpImpl::GetNodeId(
const performance_manager::Node* node) const { … }
base::SequenceBound<DiscardsGraphDumpImpl::FaviconRequestHelper>&
DiscardsGraphDumpImpl::EnsureFaviconRequestHelper() { … }
DiscardsGraphDumpImpl::FaviconAvailableCallback
DiscardsGraphDumpImpl::GetFaviconAvailableCallback(int64_t serialization_id) { … }
void DiscardsGraphDumpImpl::StartPageFaviconRequest(
const performance_manager::PageNode* page_node) { … }
void DiscardsGraphDumpImpl::StartFrameFaviconRequest(
const performance_manager::FrameNode* frame_node) { … }
void DiscardsGraphDumpImpl::SendNotificationToAllNodes(bool created) { … }
void DiscardsGraphDumpImpl::SendFrameNotification(
const performance_manager::FrameNode* frame,
bool created) { … }
void DiscardsGraphDumpImpl::SendPageNotification(
const performance_manager::PageNode* page_node,
bool created) { … }
void DiscardsGraphDumpImpl::SendProcessNotification(
const performance_manager::ProcessNode* process,
bool created) { … }
void DiscardsGraphDumpImpl::SendWorkerNotification(
const performance_manager::WorkerNode* worker,
bool created) { … }
void DiscardsGraphDumpImpl::SendDeletionNotification(
const performance_manager::Node* node) { … }
void DiscardsGraphDumpImpl::SendFaviconNotification(
int64_t serialization_id,
scoped_refptr<base::RefCountedMemory> bitmap_data) { … }
void DiscardsGraphDumpImpl::OnConnectionError(DiscardsGraphDumpImpl* impl) { … }