#include "chrome/browser/performance_manager/policies/page_discarding_helper.h"
#include <memory>
#include <utility>
#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_macros.h"
#include "base/sequence_checker.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/performance_manager/mechanisms/page_discarder.h"
#include "chrome/browser/performance_manager/policies/policy_features.h"
#include "components/performance_manager/graph/page_node_impl.h"
#include "components/performance_manager/public/decorators/tab_page_decorator.h"
#include "components/performance_manager/public/graph/frame_node.h"
#include "components/performance_manager/public/graph/graph_operations.h"
#include "components/performance_manager/public/graph/node_attached_data.h"
#include "components/performance_manager/public/graph/node_data_describer_registry.h"
#include "components/performance_manager/public/graph/node_data_describer_util.h"
#include "components/performance_manager/public/graph/page_node.h"
#include "components/performance_manager/public/graph/process_node.h"
#include "components/performance_manager/public/user_tuning/tab_revisit_tracker.h"
#include "components/url_matcher/url_matcher.h"
#include "components/url_matcher/url_util.h"
#include "third_party/abseil-cpp/absl/cleanup/cleanup.h"
#include "url/gurl.h"
PageDiscarder;
namespace performance_manager {
namespace policies {
namespace {
class DiscardAttemptMarker
: public ExternalNodeAttachedDataImpl<DiscardAttemptMarker> { … };
const char kDescriberName[] = …;
NodeRssMap;
NodeRssMap GetPageNodeRssEstimateKb(
const std::vector<PageNodeSortProxy>& candidates) { … }
void RecordDiscardedTabMetrics(const PageNodeSortProxy& candidate) { … }
}
PageDiscardingHelper::PageDiscardingHelper()
: … { … }
PageDiscardingHelper::~PageDiscardingHelper() = default;
void PageDiscardingHelper::DiscardAPage(
base::OnceCallback<void(bool)> post_discard_cb,
DiscardReason discard_reason,
base::TimeDelta minimum_time_in_background) { … }
void PageDiscardingHelper::DiscardMultiplePages(
std::optional<memory_pressure::ReclaimTarget> reclaim_target,
bool discard_protected_tabs,
base::OnceCallback<void(bool)> post_discard_cb,
DiscardReason discard_reason,
base::TimeDelta minimum_time_in_background) { … }
void PageDiscardingHelper::ImmediatelyDiscardMultiplePages(
const std::vector<const PageNode*>& page_nodes,
DiscardReason discard_reason,
base::OnceCallback<void(bool)> post_discard_cb) { … }
void PageDiscardingHelper::SetNoDiscardPatternsForProfile(
const std::string& browser_context_id,
const std::vector<std::string>& patterns) { … }
void PageDiscardingHelper::ClearNoDiscardPatternsForProfile(
const std::string& browser_context_id) { … }
void PageDiscardingHelper::SetMockDiscarderForTesting(
std::unique_ptr<PageDiscarder> discarder) { … }
void PageDiscardingHelper::AddDiscardAttemptMarkerForTesting(
PageNode* page_node) { … }
void PageDiscardingHelper::RemovesDiscardAttemptMarkerForTesting(
PageNode* page_node) { … }
void PageDiscardingHelper::OnPassedToGraph(Graph* graph) { … }
void PageDiscardingHelper::OnTakenFromGraph(Graph* graph) { … }
const PageLiveStateDecorator::Data*
PageDiscardingHelper::GetPageNodeLiveStateData(
const PageNode* page_node) const { … }
PageDiscardingHelper::CanDiscardResult PageDiscardingHelper::CanDiscard(
const PageNode* page_node,
DiscardReason discard_reason,
base::TimeDelta minimum_time_in_background) const { … }
bool PageDiscardingHelper::IsPageOptedOutOfDiscarding(
const std::string& browser_context_id,
const GURL& url) const { … }
base::Value::Dict PageDiscardingHelper::DescribePageNodeData(
const PageNode* node) const { … }
void PageDiscardingHelper::PostDiscardAttemptCallback(
std::optional<memory_pressure::ReclaimTarget> reclaim_target,
bool discard_protected_tabs,
base::OnceCallback<void(bool)> post_discard_cb,
DiscardReason discard_reason,
base::TimeDelta minimum_time_in_background,
const std::vector<PageDiscarder::DiscardEvent>& discard_events) { … }
}
}