Commit edced766 authored by Sebastien Marchand's avatar Sebastien Marchand Committed by Commit Bot

Add some IsLoaded/IsFrozen helper functions to RCTabHelper.

Change-Id: Ifb83230b1a3621d0bcf02cf9b9b2b71617df6462
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1606443Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Commit-Queue: Sébastien Marchand <sebmarchand@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659193}
parent 3ac0a8a7
...@@ -13,7 +13,10 @@ ...@@ -13,7 +13,10 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/resource_coordinator/lifecycle_unit_state.mojom-shared.h"
#include "chrome/browser/resource_coordinator/resource_coordinator_parts.h" #include "chrome/browser/resource_coordinator/resource_coordinator_parts.h"
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit_external.h"
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit_source.h"
#include "chrome/browser/resource_coordinator/tab_load_tracker.h" #include "chrome/browser/resource_coordinator/tab_load_tracker.h"
#include "chrome/browser/resource_coordinator/tab_memory_metrics_reporter.h" #include "chrome/browser/resource_coordinator/tab_memory_metrics_reporter.h"
#include "chrome/browser/resource_coordinator/utils.h" #include "chrome/browser/resource_coordinator/utils.h"
...@@ -53,6 +56,28 @@ ResourceCoordinatorTabHelper::ResourceCoordinatorTabHelper( ...@@ -53,6 +56,28 @@ ResourceCoordinatorTabHelper::ResourceCoordinatorTabHelper(
ResourceCoordinatorTabHelper::~ResourceCoordinatorTabHelper() = default; ResourceCoordinatorTabHelper::~ResourceCoordinatorTabHelper() = default;
bool ResourceCoordinatorTabHelper::IsLoaded(content::WebContents* contents) {
if (resource_coordinator::ResourceCoordinatorTabHelper::FromWebContents(
contents)) {
return resource_coordinator::TabLoadTracker::Get()->GetLoadingState(
contents) == ::mojom::LifecycleUnitLoadingState::LOADED;
}
return true;
}
bool ResourceCoordinatorTabHelper::IsFrozen(content::WebContents* contents) {
#if !defined(OS_ANDROID)
if (resource_coordinator::ResourceCoordinatorTabHelper::FromWebContents(
contents)) {
auto* tab_lifecycle_unit = resource_coordinator::TabLifecycleUnitSource::
GetTabLifecycleUnitExternal(contents);
if (tab_lifecycle_unit)
return tab_lifecycle_unit->IsFrozen();
}
#endif
return false;
}
void ResourceCoordinatorTabHelper::DidStartLoading() { void ResourceCoordinatorTabHelper::DidStartLoading() {
TabLoadTracker::Get()->DidStartLoading(web_contents()); TabLoadTracker::Get()->DidStartLoading(web_contents());
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/process/kill.h" #include "base/process/kill.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h" #include "content/public/browser/web_contents_user_data.h"
#include "services/metrics/public/cpp/ukm_source_id.h" #include "services/metrics/public/cpp/ukm_source_id.h"
...@@ -28,6 +29,14 @@ class ResourceCoordinatorTabHelper ...@@ -28,6 +29,14 @@ class ResourceCoordinatorTabHelper
public: public:
~ResourceCoordinatorTabHelper() override; ~ResourceCoordinatorTabHelper() override;
// Helper function to check if a given WebContents is loaded. Returns true by
// default if there's no TabHelper for this content.
static bool IsLoaded(content::WebContents* contents);
// Helper function to check if a given WebContents is frozen. Returns false by
// default if there's no TabHelper for this content.
static bool IsFrozen(content::WebContents* contents);
// WebContentsObserver overrides. // WebContentsObserver overrides.
void DidStartLoading() override; void DidStartLoading() override;
void DidReceiveResponse() override; void DidReceiveResponse() override;
......
...@@ -514,6 +514,7 @@ TEST_F(TabManagerTest, OnTabIsLoaded) { ...@@ -514,6 +514,7 @@ TEST_F(TabManagerTest, OnTabIsLoaded) {
->DidStartNavigation(nav_handle1_.get()); ->DidStartNavigation(nav_handle1_.get());
EXPECT_TRUE(tab_manager_->IsTabLoadingForTest(contents1_.get())); EXPECT_TRUE(tab_manager_->IsTabLoadingForTest(contents1_.get()));
EXPECT_FALSE(ResourceCoordinatorTabHelper::IsLoaded(contents1_.get()));
EXPECT_FALSE(tab_manager_->IsTabLoadingForTest(contents2_.get())); EXPECT_FALSE(tab_manager_->IsTabLoadingForTest(contents2_.get()));
EXPECT_TRUE(tab_manager_->IsNavigationDelayedForTest(nav_handle2_.get())); EXPECT_TRUE(tab_manager_->IsNavigationDelayedForTest(nav_handle2_.get()));
...@@ -524,6 +525,7 @@ TEST_F(TabManagerTest, OnTabIsLoaded) { ...@@ -524,6 +525,7 @@ TEST_F(TabManagerTest, OnTabIsLoaded) {
// After tab 1 has finished loading, TabManager starts loading the next tab. // After tab 1 has finished loading, TabManager starts loading the next tab.
EXPECT_FALSE(tab_manager_->IsTabLoadingForTest(contents1_.get())); EXPECT_FALSE(tab_manager_->IsTabLoadingForTest(contents1_.get()));
EXPECT_TRUE(tab_manager_->IsTabLoadingForTest(contents2_.get())); EXPECT_TRUE(tab_manager_->IsTabLoadingForTest(contents2_.get()));
EXPECT_TRUE(ResourceCoordinatorTabHelper::IsLoaded(contents1_.get()));
EXPECT_FALSE(tab_manager_->IsNavigationDelayedForTest(nav_handle2_.get())); EXPECT_FALSE(tab_manager_->IsNavigationDelayedForTest(nav_handle2_.get()));
} }
...@@ -1402,12 +1404,24 @@ TEST_F(TabManagerWithProactiveDiscardExperimentEnabledTest, ...@@ -1402,12 +1404,24 @@ TEST_F(TabManagerWithProactiveDiscardExperimentEnabledTest,
EXPECT_FALSE(IsTabFrozen(tab_strip->GetWebContentsAt(0))); EXPECT_FALSE(IsTabFrozen(tab_strip->GetWebContentsAt(0)));
EXPECT_FALSE(IsTabFrozen(tab_strip->GetWebContentsAt(1))); EXPECT_FALSE(IsTabFrozen(tab_strip->GetWebContentsAt(1)));
EXPECT_TRUE(IsTabFrozen(tab_strip->GetWebContentsAt(2))); EXPECT_TRUE(IsTabFrozen(tab_strip->GetWebContentsAt(2)));
EXPECT_FALSE(
ResourceCoordinatorTabHelper::IsFrozen(tab_strip->GetWebContentsAt(0)));
EXPECT_FALSE(
ResourceCoordinatorTabHelper::IsFrozen(tab_strip->GetWebContentsAt(1)));
EXPECT_TRUE(
ResourceCoordinatorTabHelper::IsFrozen(tab_strip->GetWebContentsAt(2)));
// After half the freeze timeout, the 1st tab should be frozen. // After half the freeze timeout, the 1st tab should be frozen.
task_runner_->FastForwardBy(kFreezeTimeout / 2); task_runner_->FastForwardBy(kFreezeTimeout / 2);
EXPECT_TRUE(IsTabFrozen(tab_strip->GetWebContentsAt(0))); EXPECT_TRUE(IsTabFrozen(tab_strip->GetWebContentsAt(0)));
EXPECT_FALSE(IsTabFrozen(tab_strip->GetWebContentsAt(1))); EXPECT_FALSE(IsTabFrozen(tab_strip->GetWebContentsAt(1)));
EXPECT_TRUE(IsTabFrozen(tab_strip->GetWebContentsAt(2))); EXPECT_TRUE(IsTabFrozen(tab_strip->GetWebContentsAt(2)));
EXPECT_TRUE(
ResourceCoordinatorTabHelper::IsFrozen(tab_strip->GetWebContentsAt(0)));
EXPECT_FALSE(
ResourceCoordinatorTabHelper::IsFrozen(tab_strip->GetWebContentsAt(1)));
EXPECT_TRUE(
ResourceCoordinatorTabHelper::IsFrozen(tab_strip->GetWebContentsAt(2)));
tab_strip->CloseAllTabs(); tab_strip->CloseAllTabs();
} }
......
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