Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: chrome/browser/resource_coordinator/tab_manager.cc

Issue 2931023002: [TooManyTabs] Add TabNavigationThrottle (Closed)
Patch Set: review fix Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/resource_coordinator/tab_manager.h" 5 #include "chrome/browser/resource_coordinator/tab_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/bind_helpers.h" 14 #include "base/bind_helpers.h"
15 #include "base/command_line.h"
16 #include "base/feature_list.h" 15 #include "base/feature_list.h"
17 #include "base/macros.h" 16 #include "base/macros.h"
18 #include "base/memory/memory_pressure_monitor.h" 17 #include "base/memory/memory_pressure_monitor.h"
19 #include "base/metrics/field_trial.h" 18 #include "base/metrics/field_trial.h"
20 #include "base/metrics/histogram_macros.h" 19 #include "base/metrics/histogram_macros.h"
21 #include "base/observer_list.h" 20 #include "base/observer_list.h"
22 #include "base/process/process.h" 21 #include "base/process/process.h"
23 #include "base/rand_util.h" 22 #include "base/rand_util.h"
24 #include "base/strings/string16.h" 23 #include "base/strings/string16.h"
25 #include "base/strings/string_number_conversions.h" 24 #include "base/strings/string_number_conversions.h"
(...skipping 10 matching lines...) Expand all
36 #include "chrome/browser/resource_coordinator/tab_manager_observer.h" 35 #include "chrome/browser/resource_coordinator/tab_manager_observer.h"
37 #include "chrome/browser/resource_coordinator/tab_manager_web_contents_data.h" 36 #include "chrome/browser/resource_coordinator/tab_manager_web_contents_data.h"
38 #include "chrome/browser/ui/browser.h" 37 #include "chrome/browser/ui/browser.h"
39 #include "chrome/browser/ui/browser_list.h" 38 #include "chrome/browser/ui/browser_list.h"
40 #include "chrome/browser/ui/browser_window.h" 39 #include "chrome/browser/ui/browser_window.h"
41 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h" 40 #include "chrome/browser/ui/tab_contents/tab_contents_iterator.h"
42 #include "chrome/browser/ui/tabs/tab_strip_model.h" 41 #include "chrome/browser/ui/tabs/tab_strip_model.h"
43 #include "chrome/browser/ui/tabs/tab_utils.h" 42 #include "chrome/browser/ui/tabs/tab_utils.h"
44 #include "chrome/common/chrome_constants.h" 43 #include "chrome/common/chrome_constants.h"
45 #include "chrome/common/chrome_features.h" 44 #include "chrome/common/chrome_features.h"
46 #include "chrome/common/chrome_switches.h"
47 #include "chrome/common/url_constants.h" 45 #include "chrome/common/url_constants.h"
48 #include "components/metrics/system_memory_stats_recorder.h" 46 #include "components/metrics/system_memory_stats_recorder.h"
49 #include "components/variations/variations_associated_data.h" 47 #include "components/variations/variations_associated_data.h"
50 #include "content/public/browser/browser_thread.h" 48 #include "content/public/browser/browser_thread.h"
51 #include "content/public/browser/navigation_controller.h" 49 #include "content/public/browser/navigation_controller.h"
50 #include "content/public/browser/navigation_handle.h"
52 #include "content/public/browser/render_process_host.h" 51 #include "content/public/browser/render_process_host.h"
53 #include "content/public/browser/web_contents.h" 52 #include "content/public/browser/web_contents.h"
54 #include "content/public/common/page_importance_signals.h" 53 #include "content/public/common/page_importance_signals.h"
55 54
56 #if defined(OS_CHROMEOS) 55 #if defined(OS_CHROMEOS)
57 #include "ash/multi_profile_uma.h" 56 #include "ash/multi_profile_uma.h"
58 #include "ash/shell_port.h" 57 #include "ash/shell_port.h"
59 #include "chrome/browser/resource_coordinator/tab_manager_delegate_chromeos.h" 58 #include "chrome/browser/resource_coordinator/tab_manager_delegate_chromeos.h"
60 #include "components/user_manager/user_manager.h" 59 #include "components/user_manager/user_manager.h"
61 #endif 60 #endif
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 103
105 TabManager::TabManager() 104 TabManager::TabManager()
106 : discard_count_(0), 105 : discard_count_(0),
107 recent_tab_discard_(false), 106 recent_tab_discard_(false),
108 discard_once_(false), 107 discard_once_(false),
109 #if !defined(OS_CHROMEOS) 108 #if !defined(OS_CHROMEOS)
110 minimum_protection_time_(base::TimeDelta::FromMinutes(10)), 109 minimum_protection_time_(base::TimeDelta::FromMinutes(10)),
111 #endif 110 #endif
112 browser_tab_strip_tracker_(this, nullptr, nullptr), 111 browser_tab_strip_tracker_(this, nullptr, nullptr),
113 test_tick_clock_(nullptr), 112 test_tick_clock_(nullptr),
113 loading_contents_(nullptr),
114 weak_ptr_factory_(this) { 114 weak_ptr_factory_(this) {
115 #if defined(OS_CHROMEOS) 115 #if defined(OS_CHROMEOS)
116 delegate_.reset(new TabManagerDelegate(weak_ptr_factory_.GetWeakPtr())); 116 delegate_.reset(new TabManagerDelegate(weak_ptr_factory_.GetWeakPtr()));
117 #endif 117 #endif
118 browser_tab_strip_tracker_.Init(); 118 browser_tab_strip_tracker_.Init();
119 } 119 }
120 120
121 TabManager::~TabManager() { 121 TabManager::~TabManager() {
122 Stop(); 122 Stop();
123 } 123 }
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 // When ActiveTabChanged, |new_contents| purged state changes to be false. 779 // When ActiveTabChanged, |new_contents| purged state changes to be false.
780 GetWebContentsData(new_contents)->set_is_purged(false); 780 GetWebContentsData(new_contents)->set_is_purged(false);
781 // If |old_contents| is set, that tab has switched from being active to 781 // If |old_contents| is set, that tab has switched from being active to
782 // inactive, so record the time of that transition. 782 // inactive, so record the time of that transition.
783 if (old_contents) { 783 if (old_contents) {
784 GetWebContentsData(old_contents)->SetLastInactiveTime(NowTicks()); 784 GetWebContentsData(old_contents)->SetLastInactiveTime(NowTicks());
785 // Re-setting time-to-purge every time a tab becomes inactive. 785 // Re-setting time-to-purge every time a tab becomes inactive.
786 GetWebContentsData(old_contents) 786 GetWebContentsData(old_contents)
787 ->set_time_to_purge(GetTimeToPurge(min_time_to_purge_)); 787 ->set_time_to_purge(GetTimeToPurge(min_time_to_purge_));
788 } 788 }
789
790 ResumeTabNavigationIfNeeded(new_contents);
789 } 791 }
790 792
791 void TabManager::TabInsertedAt(TabStripModel* tab_strip_model, 793 void TabManager::TabInsertedAt(TabStripModel* tab_strip_model,
792 content::WebContents* contents, 794 content::WebContents* contents,
793 int index, 795 int index,
794 bool foreground) { 796 bool foreground) {
795 // Only interested in background tabs, as foreground tabs get taken care of by 797 // Only interested in background tabs, as foreground tabs get taken care of by
796 // ActiveTabChanged. 798 // ActiveTabChanged.
797 if (foreground) 799 if (foreground)
798 return; 800 return;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
868 // TODO(georgesak): Add Linux when automatic discarding is enabled for that 870 // TODO(georgesak): Add Linux when automatic discarding is enabled for that
869 // platform. 871 // platform.
870 std::string allow_multiple_discards = variations::GetVariationParamValue( 872 std::string allow_multiple_discards = variations::GetVariationParamValue(
871 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); 873 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards");
872 return (allow_multiple_discards != "true"); 874 return (allow_multiple_discards != "true");
873 #else 875 #else
874 return false; 876 return false;
875 #endif 877 #endif
876 } 878 }
877 879
880 content::NavigationThrottle::ThrottleCheckResult
881 TabManager::MaybeThrottleNavigation(
882 content::NavigationHandle* navigation_handle) {
883 if (!ShouldDelayNavigation(navigation_handle)) {
884 loading_contents_ = navigation_handle->GetWebContents();
885 return content::NavigationThrottle::PROCEED;
886 }
887
888 pending_navigations_.push_back(navigation_handle);
889 return content::NavigationThrottle::DEFER;
890 }
891
892 bool TabManager::ShouldDelayNavigation(
893 content::NavigationHandle* navigation_handle) const {
894 if (!navigation_handle)
895 return false;
896
897 // Do not throttle the navigation if no tab is currently loading.
898 if (!loading_contents_) {
899 return false;
900 }
901
902 return true;
903 }
904
905 void TabManager::HasFinishedLoadingTab(content::WebContents* contents) {
906 loading_contents_ = nullptr;
907
908 while (!pending_navigations_.empty()) {
909 content::NavigationHandle* navigation_handle = pending_navigations_.front();
910 pending_navigations_.erase(pending_navigations_.begin());
911
912 if (navigation_handle) {
913 loading_contents_ = navigation_handle->GetWebContents();
914 navigation_handle->Resume();
915 break;
916 }
917 }
918 }
919
920 void TabManager::ResumeTabNavigationIfNeeded(content::WebContents* contents) {
921 auto it = pending_navigations_.begin();
922 while (it != pending_navigations_.end()) {
923 content::NavigationHandle* navigation_handle = *it;
924 if (navigation_handle && navigation_handle->GetWebContents() == contents) {
925 loading_contents_ = navigation_handle->GetWebContents();
926 navigation_handle->Resume();
927 pending_navigations_.erase(it);
928 break;
929 }
930 it++;
931 }
932 }
933
878 } // namespace resource_coordinator 934 } // namespace resource_coordinator
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698