Commit 2a8b1e54 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Remove NotificationService use from ChromeBrowserMainExtraPartsPerformanceManager

Bug: 268984
Change-Id: I0f9d0ed9d2e7a156e2ebc03468deadf2fb0022c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1877248
Commit-Queue: Chris Hamilton <chrisha@chromium.org>
Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709159}
parent 6f02374d
......@@ -10,7 +10,6 @@
#include "base/feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/performance_manager/browser_child_process_watcher.h"
#include "chrome/browser/performance_manager/decorators/frozen_frame_aggregator.h"
#include "chrome/browser/performance_manager/decorators/page_aggregator.h"
......@@ -27,7 +26,6 @@
#include "components/performance_manager/performance_manager_tab_helper.h"
#include "components/performance_manager/render_process_user_data.h"
#include "components/performance_manager/shared_worker_watcher.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/common/content_features.h"
......@@ -110,11 +108,7 @@ void ChromeBrowserMainExtraPartsPerformanceManager::PostCreateThreads() {
// There are no existing loaded profiles.
DCHECK(g_browser_process->profile_manager()->GetLoadedProfiles().empty());
// Register for profile events to observe them as they come and go.
notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED,
content::NotificationService::AllSources());
notification_registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
content::NotificationService::AllSources());
g_browser_process->profile_manager()->AddObserver(this);
}
void ChromeBrowserMainExtraPartsPerformanceManager::PostMainMessageLoopRun() {
......@@ -123,6 +117,9 @@ void ChromeBrowserMainExtraPartsPerformanceManager::PostMainMessageLoopRun() {
browser_child_process_watcher_->TearDown();
browser_child_process_watcher_.reset();
g_browser_process->profile_manager()->RemoveObserver(this);
observed_profiles_.RemoveAll();
// Clear up the worker nodes.
for (auto& shared_worker_watcher : shared_worker_watchers_)
shared_worker_watcher.second->TearDown();
......@@ -140,35 +137,11 @@ void ChromeBrowserMainExtraPartsPerformanceManager::PostMainMessageLoopRun() {
performance_manager::PerformanceManagerImpl::Destroy(
std::move(performance_manager_));
// Unregister to profile notifications so as to not create more worker
// watchers after this point.
notification_registrar_.RemoveAll();
}
void ChromeBrowserMainExtraPartsPerformanceManager::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
switch (type) {
case chrome::NOTIFICATION_PROFILE_CREATED: {
Profile* profile = content::Source<Profile>(source).ptr();
CreateSharedWorkerWatcher(profile);
break;
}
case chrome::NOTIFICATION_PROFILE_DESTROYED: {
Profile* profile = content::Source<Profile>(source).ptr();
DeleteSharedWorkerWatcher(profile);
break;
}
default:
NOTREACHED();
break;
}
}
void ChromeBrowserMainExtraPartsPerformanceManager::CreateSharedWorkerWatcher(
void ChromeBrowserMainExtraPartsPerformanceManager::OnProfileAdded(
Profile* profile) {
observed_profiles_.Add(profile);
auto shared_worker_watcher =
std::make_unique<performance_manager::SharedWorkerWatcher>(
profile->UniqueId(),
......@@ -182,8 +155,14 @@ void ChromeBrowserMainExtraPartsPerformanceManager::CreateSharedWorkerWatcher(
DCHECK(inserted);
}
void ChromeBrowserMainExtraPartsPerformanceManager::DeleteSharedWorkerWatcher(
void ChromeBrowserMainExtraPartsPerformanceManager::
OnOffTheRecordProfileCreated(Profile* off_the_record) {
OnProfileAdded(off_the_record);
}
void ChromeBrowserMainExtraPartsPerformanceManager::OnProfileWillBeDestroyed(
Profile* profile) {
observed_profiles_.Remove(profile);
auto it = shared_worker_watchers_.find(profile);
DCHECK(it != shared_worker_watchers_.end());
it->second->TearDown();
......
......@@ -10,11 +10,13 @@
#include "base/compiler_specific.h"
#include "base/containers/flat_map.h"
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "chrome/browser/chrome_browser_main_extra_parts.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager_observer.h"
#include "chrome/browser/profiles/profile_observer.h"
#include "components/performance_manager/process_node_source.h"
#include "components/performance_manager/tab_helper_frame_node_source.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
class Profile;
......@@ -33,7 +35,8 @@ class SharedWorkerWatcher;
// classes that create/manage graph nodes.
class ChromeBrowserMainExtraPartsPerformanceManager
: public ChromeBrowserMainExtraParts,
public content::NotificationObserver {
public ProfileManagerObserver,
public ProfileObserver {
public:
ChromeBrowserMainExtraPartsPerformanceManager();
~ChromeBrowserMainExtraPartsPerformanceManager() override;
......@@ -55,14 +58,12 @@ class ChromeBrowserMainExtraPartsPerformanceManager
void PostCreateThreads() override;
void PostMainMessageLoopRun() override;
// content::NotificationObserver:
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
// ProfileManagerObserver:
void OnProfileAdded(Profile* profile) override;
// Handlers for profile creation and destruction notifications.
void CreateSharedWorkerWatcher(Profile* profile);
void DeleteSharedWorkerWatcher(Profile* profile);
// ProfileObserver:
void OnOffTheRecordProfileCreated(Profile* off_the_record) override;
void OnProfileWillBeDestroyed(Profile* profile) override;
std::unique_ptr<performance_manager::PerformanceManagerImpl>
performance_manager_;
......@@ -75,7 +76,7 @@ class ChromeBrowserMainExtraPartsPerformanceManager
std::unique_ptr<performance_manager::BrowserChildProcessWatcher>
browser_child_process_watcher_;
content::NotificationRegistrar notification_registrar_;
ScopedObserver<Profile, ProfileObserver> observed_profiles_{this};
// Needed by the worker watchers to access existing process nodes and frame
// 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