Skip to content

Commit

Permalink
[PM] Use PerformanceManagerLifetime in chrome/browser
Browse files Browse the repository at this point in the history
R=chrisha

Change-Id: If4cbdaea18b23333bf65f9300208d46e03e8a928
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3208113
Auto-Submit: Joe Mason <joenotcharles@google.com>
Commit-Queue: Chris Hamilton <chrisha@chromium.org>
Reviewed-by: Chris Hamilton <chrisha@chromium.org>
Cr-Commit-Position: refs/heads/main@{#929248}
  • Loading branch information
JoeNotCharlesGoogle authored and Chromium LUCI CQ committed Oct 7, 2021
1 parent 56c2929 commit c66affc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "chrome/browser/performance_manager/chrome_browser_main_extra_parts_performance_manager.h"

#include <memory>
#include <utility>

#include "base/bind.h"
#include "base/feature_list.h"
Expand All @@ -24,6 +23,7 @@
#include "chrome/browser/performance_manager/policies/policy_features.h"
#include "chrome/browser/performance_manager/policies/working_set_trimmer_policy.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "components/performance_manager/embedder/graph_features.h"
#include "components/performance_manager/embedder/performance_manager_lifetime.h"
#include "components/performance_manager/embedder/performance_manager_registry.h"
#include "components/performance_manager/performance_manager_feature_observer_client.h"
Expand Down Expand Up @@ -180,11 +180,11 @@ ChromeBrowserMainExtraPartsPerformanceManager::GetFeatureObserverClient() {
}

void ChromeBrowserMainExtraPartsPerformanceManager::PostCreateThreads() {
performance_manager_ =
performance_manager::CreatePerformanceManagerWithDefaultFeatures(
performance_manager_lifetime_ =
std::make_unique<performance_manager::PerformanceManagerLifetime>(
performance_manager::GraphFeatures::WithDefault(),
base::BindOnce(&ChromeBrowserMainExtraPartsPerformanceManager::
CreatePoliciesAndDecorators));
registry_ = performance_manager::PerformanceManagerRegistry::Create();
browser_child_process_watcher_ =
std::make_unique<performance_manager::BrowserChildProcessWatcher>();
browser_child_process_watcher_->Initialize();
Expand Down Expand Up @@ -215,21 +215,16 @@ void ChromeBrowserMainExtraPartsPerformanceManager::PostMainMessageLoopRun() {
page_live_state_data_helper_.reset();
page_load_metrics_observer_.reset();

// There may still be worker hosts, WebContents and RenderProcessHosts with
// attached user data, retaining WorkerNodes, PageNodes, FrameNodes and
// ProcessNodes. Tear down the registry to release these nodes. After this,
// there is no convenient call-out to destroy the performance manager.
registry_->TearDown();
registry_.reset();

performance_manager::DestroyPerformanceManager(
std::move(performance_manager_));
// Releasing `performance_manager_lifetime_` will tear down the registry and
// graph safely.
performance_manager_lifetime_.reset();
}

void ChromeBrowserMainExtraPartsPerformanceManager::OnProfileAdded(
Profile* profile) {
profile_observations_.AddObservation(profile);
registry_->NotifyBrowserContextAdded(profile);
performance_manager::PerformanceManagerRegistry::GetInstance()
->NotifyBrowserContextAdded(profile);
}

void ChromeBrowserMainExtraPartsPerformanceManager::
Expand All @@ -240,5 +235,6 @@ void ChromeBrowserMainExtraPartsPerformanceManager::
void ChromeBrowserMainExtraPartsPerformanceManager::OnProfileWillBeDestroyed(
Profile* profile) {
profile_observations_.RemoveObservation(profile);
registry_->NotifyBrowserContextRemoved(profile);
performance_manager::PerformanceManagerRegistry::GetInstance()
->NotifyBrowserContextRemoved(profile);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ class Graph;
class PageLiveStateDecoratorHelper;
class PageLoadMetricsObserver;
class PageLoadTrackerDecoratorHelper;
class PerformanceManager;
class PerformanceManagerFeatureObserverClient;
class PerformanceManagerRegistry;
class PerformanceManagerLifetime;
} // namespace performance_manager

// Handles the initialization of the performance manager and a few dependent
Expand Down Expand Up @@ -71,8 +70,10 @@ class ChromeBrowserMainExtraPartsPerformanceManager
void OnOffTheRecordProfileCreated(Profile* off_the_record) override;
void OnProfileWillBeDestroyed(Profile* profile) override;

std::unique_ptr<performance_manager::PerformanceManager> performance_manager_;
std::unique_ptr<performance_manager::PerformanceManagerRegistry> registry_;
// Manages the lifetime of the PerformanceManager graph and registry for the
// browser process.
std::unique_ptr<performance_manager::PerformanceManagerLifetime>
performance_manager_lifetime_;

const std::unique_ptr<
performance_manager::PerformanceManagerFeatureObserverClient>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ class PerformanceManagerLifetime {
std::unique_ptr<PerformanceManagerRegistry> performance_manager_registry_;
};

// Creates a PerformanceManager with default decorators.
// |graph_created_callback| is invoked on the PM sequence once the Graph is
// created.
std::unique_ptr<PerformanceManager> CreatePerformanceManagerWithDefaultFeatures(
GraphCreatedCallback graph_created_callback);

// Unregisters |instance| and arranges for its deletion on its sequence.
void DestroyPerformanceManager(std::unique_ptr<PerformanceManager> instance);

Expand Down
10 changes: 3 additions & 7 deletions components/performance_manager/performance_manager_lifetime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ PerformanceManagerLifetime::PerformanceManagerLifetime(
performance_manager::PerformanceManagerRegistry::Create()) {}

PerformanceManagerLifetime::~PerformanceManagerLifetime() {
// There may still be worker hosts, WebContents and RenderProcessHosts with
// attached user data, retaining WorkerNodes, PageNodes, FrameNodes and
// ProcessNodes. Tear down the registry to release these nodes.
performance_manager_registry_->TearDown();
performance_manager_registry_.reset();
performance_manager::DestroyPerformanceManager(
Expand All @@ -83,13 +86,6 @@ void PerformanceManagerLifetime::SetGraphFeaturesOverrideForTesting(
*GetGraphFeaturesOverride() = graph_features_override;
}

std::unique_ptr<PerformanceManager> CreatePerformanceManagerWithDefaultFeatures(
GraphCreatedCallback graph_created_callback) {
return PerformanceManagerImpl::Create(
base::BindOnce(&OnGraphCreated, GraphFeatures::WithDefault(),
std::move(graph_created_callback)));
}

void DestroyPerformanceManager(std::unique_ptr<PerformanceManager> instance) {
PerformanceManagerImpl::Destroy(std::move(instance));
}
Expand Down

0 comments on commit c66affc

Please sign in to comment.