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