blob: cf95fb68a9a0c37aa0460bde1812cf83229d712e [file] [log] [blame]
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "android_webview/browser/page_load_metrics/aw_page_load_metrics_memory_tracker_factory.h"
#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
#include "components/page_load_metrics/browser/page_load_metrics_memory_tracker.h"
namespace android_webview {
page_load_metrics::PageLoadMetricsMemoryTracker*
AwPageLoadMetricsMemoryTrackerFactory::GetForBrowserContext(
content::BrowserContext* context) {
return static_cast<page_load_metrics::PageLoadMetricsMemoryTracker*>(
GetInstance()->GetServiceForBrowserContext(context, true));
}
AwPageLoadMetricsMemoryTrackerFactory*
AwPageLoadMetricsMemoryTrackerFactory::GetInstance() {
return base::Singleton<AwPageLoadMetricsMemoryTrackerFactory>::get();
}
AwPageLoadMetricsMemoryTrackerFactory::AwPageLoadMetricsMemoryTrackerFactory()
: BrowserContextKeyedServiceFactory(
"PageLoadMetricsMemoryTracker",
BrowserContextDependencyManager::GetInstance()) {}
bool AwPageLoadMetricsMemoryTrackerFactory::ServiceIsCreatedWithBrowserContext()
const {
return base::FeatureList::IsEnabled(features::kV8PerFrameMemoryMonitoring);
}
std::unique_ptr<KeyedService>
AwPageLoadMetricsMemoryTrackerFactory::BuildServiceInstanceForBrowserContext(
content::BrowserContext* context) const {
return std::make_unique<page_load_metrics::PageLoadMetricsMemoryTracker>();
}
content::BrowserContext*
AwPageLoadMetricsMemoryTrackerFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return context;
}
} // namespace android_webview