Commit 814050de authored by Francois Doray's avatar Francois Doray Committed by Commit Bot

Remove ResourceCoordinatorTabHelper::IsEnabled().

Instantiating a ResourceCoordinatorTabHelper is useful to support
TabLoadTracker, even when the service manager and GRC are not enabled.

Bug: 775644
Change-Id: I5a47aa711f4759172a73a5bc8c75685513995e27
Reviewed-on: https://chromium-review.googlesource.com/1071718
Commit-Queue: Chris Hamilton <chrisha@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Cr-Commit-Position: refs/heads/master@{#561939}
parent 52964de0
......@@ -35,13 +35,13 @@ namespace resource_coordinator {
ResourceCoordinatorTabHelper::ResourceCoordinatorTabHelper(
content::WebContents* web_contents)
: content::WebContentsObserver(web_contents) {
TabLoadTracker::Get()->StartTracking(web_contents);
service_manager::Connector* connector = nullptr;
// |ServiceManagerConnection| is null in test.
if (content::ServiceManagerConnection::GetForProcess()) {
if (resource_coordinator::IsResourceCoordinatorEnabled() &&
content::ServiceManagerConnection::GetForProcess()) {
connector =
content::ServiceManagerConnection::GetForProcess()->GetConnector();
}
page_resource_coordinator_ =
std::make_unique<resource_coordinator::PageResourceCoordinator>(
connector);
......@@ -60,20 +60,14 @@ ResourceCoordinatorTabHelper::ResourceCoordinatorTabHelper(
page_resource_coordinator_->id(), web_contents);
}
TabLoadTracker::Get()->StartTracking(web_contents);
TabMemoryMetricsReporter::Get()->StartReporting(TabLoadTracker::Get());
}
}
ResourceCoordinatorTabHelper::~ResourceCoordinatorTabHelper() = default;
// static
bool ResourceCoordinatorTabHelper::IsEnabled() {
// Check that service_manager is active and GRC is enabled.
return content::ServiceManagerConnection::GetForProcess() != nullptr &&
resource_coordinator::IsResourceCoordinatorEnabled();
}
void ResourceCoordinatorTabHelper::DidStartLoading() {
if (page_resource_coordinator_)
page_resource_coordinator_->SetIsLoading(true);
TabLoadTracker::Get()->DidStartLoading(web_contents());
}
......@@ -83,6 +77,7 @@ void ResourceCoordinatorTabHelper::DidReceiveResponse() {
}
void ResourceCoordinatorTabHelper::DidStopLoading() {
if (page_resource_coordinator_)
page_resource_coordinator_->SetIsLoading(false);
TabLoadTracker::Get()->DidStopLoading(web_contents());
}
......@@ -97,12 +92,15 @@ void ResourceCoordinatorTabHelper::DidFailLoad(
void ResourceCoordinatorTabHelper::OnVisibilityChanged(
content::Visibility visibility) {
if (page_resource_coordinator_) {
// TODO(fdoray): An OCCLUDED tab should not be considered visible.
const bool is_visible = visibility != content::Visibility::HIDDEN;
page_resource_coordinator_->SetVisibility(is_visible);
}
}
void ResourceCoordinatorTabHelper::WebContentsDestroyed() {
if (page_resource_coordinator_) {
if (auto* page_signal_receiver =
resource_coordinator::PageSignalReceiver::GetInstance()) {
// Gets CoordinationUnitID for this WebContents and removes it from
......@@ -110,6 +108,7 @@ void ResourceCoordinatorTabHelper::WebContentsDestroyed() {
page_signal_receiver->RemoveCoordinationUnitID(
page_resource_coordinator_->id());
}
}
TabLoadTracker::Get()->StopTracking(web_contents());
}
......@@ -123,6 +122,7 @@ void ResourceCoordinatorTabHelper::DidFinishNavigation(
content::RenderFrameHost* render_frame_host =
navigation_handle->GetRenderFrameHost();
if (page_resource_coordinator_) {
// Make sure the hierarchical structure is constructed before sending signal
// to Resource Coordinator.
auto* frame_resource_coordinator =
......@@ -138,6 +138,7 @@ void ResourceCoordinatorTabHelper::DidFinishNavigation(
ResetFlag();
page_resource_coordinator_->OnMainFrameNavigationCommitted();
}
}
}
void ResourceCoordinatorTabHelper::TitleWasSet(
......@@ -146,6 +147,7 @@ void ResourceCoordinatorTabHelper::TitleWasSet(
first_time_title_set_ = true;
return;
}
if (page_resource_coordinator_)
page_resource_coordinator_->OnTitleUpdated();
}
......@@ -155,12 +157,14 @@ void ResourceCoordinatorTabHelper::DidUpdateFaviconURL(
first_time_favicon_set_ = true;
return;
}
if (page_resource_coordinator_)
page_resource_coordinator_->OnFaviconUpdated();
}
void ResourceCoordinatorTabHelper::UpdateUkmRecorder(int64_t navigation_id) {
ukm_source_id_ =
ukm::ConvertToSourceId(navigation_id, ukm::SourceIdType::NAVIGATION_ID);
if (page_resource_coordinator_)
page_resource_coordinator_->SetUKMSourceId(ukm_source_id_);
}
......
......@@ -26,8 +26,6 @@ class ResourceCoordinatorTabHelper
static bool ukm_recorder_initialized;
static bool IsEnabled();
resource_coordinator::PageResourceCoordinator* page_resource_coordinator() {
return page_resource_coordinator_.get();
}
......
......@@ -346,8 +346,6 @@ offline_pages::RecentTabHelper::CreateForWebContents(web_contents);
if (MediaEngagementService::IsEnabled())
MediaEngagementService::CreateWebContentsObserver(web_contents);
if (resource_coordinator::ResourceCoordinatorTabHelper::IsEnabled()) {
resource_coordinator::ResourceCoordinatorTabHelper::CreateForWebContents(
web_contents);
}
}
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