| Index: chrome/browser/resource_coordinator/tab_manager.cc
|
| diff --git a/chrome/browser/resource_coordinator/tab_manager.cc b/chrome/browser/resource_coordinator/tab_manager.cc
|
| index c2b5150b795c23e21d1e97cbe43d51ba2ba9316e..2e9cc7c6a79e12f209e22715a3b2b3453d01a894 100644
|
| --- a/chrome/browser/resource_coordinator/tab_manager.cc
|
| +++ b/chrome/browser/resource_coordinator/tab_manager.cc
|
| @@ -12,7 +12,6 @@
|
|
|
| #include "base/bind.h"
|
| #include "base/bind_helpers.h"
|
| -#include "base/command_line.h"
|
| #include "base/feature_list.h"
|
| #include "base/macros.h"
|
| #include "base/memory/memory_pressure_monitor.h"
|
| @@ -43,12 +42,12 @@
|
| #include "chrome/browser/ui/tabs/tab_utils.h"
|
| #include "chrome/common/chrome_constants.h"
|
| #include "chrome/common/chrome_features.h"
|
| -#include "chrome/common/chrome_switches.h"
|
| #include "chrome/common/url_constants.h"
|
| #include "components/metrics/system_memory_stats_recorder.h"
|
| #include "components/variations/variations_associated_data.h"
|
| #include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/navigation_controller.h"
|
| +#include "content/public/browser/navigation_handle.h"
|
| #include "content/public/browser/render_process_host.h"
|
| #include "content/public/browser/web_contents.h"
|
| #include "content/public/common/page_importance_signals.h"
|
| @@ -111,6 +110,7 @@ TabManager::TabManager()
|
| #endif
|
| browser_tab_strip_tracker_(this, nullptr, nullptr),
|
| test_tick_clock_(nullptr),
|
| + loading_contents_(nullptr),
|
| weak_ptr_factory_(this) {
|
| #if defined(OS_CHROMEOS)
|
| delegate_.reset(new TabManagerDelegate(weak_ptr_factory_.GetWeakPtr()));
|
| @@ -786,6 +786,8 @@ void TabManager::ActiveTabChanged(content::WebContents* old_contents,
|
| GetWebContentsData(old_contents)
|
| ->set_time_to_purge(GetTimeToPurge(min_time_to_purge_));
|
| }
|
| +
|
| + ResumeTabNavigationIfNeeded(new_contents);
|
| }
|
|
|
| void TabManager::TabInsertedAt(TabStripModel* tab_strip_model,
|
| @@ -875,4 +877,58 @@ bool TabManager::CanOnlyDiscardOnce() const {
|
| #endif
|
| }
|
|
|
| +content::NavigationThrottle::ThrottleCheckResult
|
| +TabManager::MaybeThrottleNavigation(
|
| + content::NavigationHandle* navigation_handle) {
|
| + if (!ShouldDelayNavigation(navigation_handle)) {
|
| + loading_contents_ = navigation_handle->GetWebContents();
|
| + return content::NavigationThrottle::PROCEED;
|
| + }
|
| +
|
| + pending_navigations_.push_back(navigation_handle);
|
| + return content::NavigationThrottle::DEFER;
|
| +}
|
| +
|
| +bool TabManager::ShouldDelayNavigation(
|
| + content::NavigationHandle* navigation_handle) const {
|
| + if (!navigation_handle)
|
| + return false;
|
| +
|
| + // Do not throttle the navigation if no tab is currently loading.
|
| + if (!loading_contents_) {
|
| + return false;
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| +void TabManager::HasFinishedLoadingTab(content::WebContents* contents) {
|
| + loading_contents_ = nullptr;
|
| +
|
| + while (!pending_navigations_.empty()) {
|
| + content::NavigationHandle* navigation_handle = pending_navigations_.front();
|
| + pending_navigations_.erase(pending_navigations_.begin());
|
| +
|
| + if (navigation_handle) {
|
| + loading_contents_ = navigation_handle->GetWebContents();
|
| + navigation_handle->Resume();
|
| + break;
|
| + }
|
| + }
|
| +}
|
| +
|
| +void TabManager::ResumeTabNavigationIfNeeded(content::WebContents* contents) {
|
| + auto it = pending_navigations_.begin();
|
| + while (it != pending_navigations_.end()) {
|
| + content::NavigationHandle* navigation_handle = *it;
|
| + if (navigation_handle && navigation_handle->GetWebContents() == contents) {
|
| + loading_contents_ = navigation_handle->GetWebContents();
|
| + navigation_handle->Resume();
|
| + pending_navigations_.erase(it);
|
| + break;
|
| + }
|
| + it++;
|
| + }
|
| +}
|
| +
|
| } // namespace resource_coordinator
|
|
|