| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_MANAGER_H_ |
| 6 #define CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_MANAGER_H_ | 6 #define CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_MANAGER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <utility> | 12 #include <utility> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/callback.h" | 15 #include "base/callback.h" |
| 16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/gtest_prod_util.h" | 17 #include "base/gtest_prod_util.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/memory_pressure_listener.h" | 19 #include "base/memory/memory_pressure_listener.h" |
| 20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
| 21 #include "base/observer_list.h" | 21 #include "base/observer_list.h" |
| 22 #include "base/strings/string16.h" | 22 #include "base/strings/string16.h" |
| 23 #include "base/timer/timer.h" | 23 #include "base/timer/timer.h" |
| 24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 25 #include "chrome/browser/resource_coordinator/tab_manager_observer.h" | 25 #include "chrome/browser/resource_coordinator/tab_manager_observer.h" |
| 26 #include "chrome/browser/resource_coordinator/tab_stats.h" | 26 #include "chrome/browser/resource_coordinator/tab_stats.h" |
| 27 #include "chrome/browser/sessions/session_restore_observer.h" |
| 27 #include "chrome/browser/ui/browser_tab_strip_tracker.h" | 28 #include "chrome/browser/ui/browser_tab_strip_tracker.h" |
| 28 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 29 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 29 #include "ui/gfx/geometry/rect.h" | 30 #include "ui/gfx/geometry/rect.h" |
| 30 | 31 |
| 31 class BrowserList; | 32 class BrowserList; |
| 32 class GURL; | 33 class GURL; |
| 33 class TabStripModel; | 34 class TabStripModel; |
| 34 | 35 |
| 35 namespace base { | 36 namespace base { |
| 36 class TickClock; | 37 class TickClock; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 bool CanSuspendBackgroundedRenderer(int render_process_id) const; | 150 bool CanSuspendBackgroundedRenderer(int render_process_id) const; |
| 150 | 151 |
| 151 // Returns true if |first| is considered less desirable to be killed than | 152 // Returns true if |first| is considered less desirable to be killed than |
| 152 // |second|. | 153 // |second|. |
| 153 static bool CompareTabStats(const TabStats& first, const TabStats& second); | 154 static bool CompareTabStats(const TabStats& first, const TabStats& second); |
| 154 | 155 |
| 155 // Returns a unique ID for a WebContents. Do not cast back to a pointer, as | 156 // Returns a unique ID for a WebContents. Do not cast back to a pointer, as |
| 156 // the WebContents could be deleted if the user closed the tab. | 157 // the WebContents could be deleted if the user closed the tab. |
| 157 static int64_t IdFromWebContents(content::WebContents* web_contents); | 158 static int64_t IdFromWebContents(content::WebContents* web_contents); |
| 158 | 159 |
| 160 // Return whether tabs are being loaded during session restore. |
| 161 bool IsSessionRestoreLoadingTabs() const { |
| 162 return is_session_restore_loading_tabs_; |
| 163 } |
| 164 |
| 159 private: | 165 private: |
| 160 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, PurgeBackgroundRenderer); | 166 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, PurgeBackgroundRenderer); |
| 161 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ActivateTabResetPurgeState); | 167 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ActivateTabResetPurgeState); |
| 162 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ShouldPurgeAtDefaultTime); | 168 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ShouldPurgeAtDefaultTime); |
| 163 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DefaultTimeToPurgeInCorrectRange); | 169 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DefaultTimeToPurgeInCorrectRange); |
| 164 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, AutoDiscardable); | 170 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, AutoDiscardable); |
| 165 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, CanOnlyDiscardOnce); | 171 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, CanOnlyDiscardOnce); |
| 166 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ChildProcessNotifications); | 172 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ChildProcessNotifications); |
| 167 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, Comparator); | 173 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, Comparator); |
| 168 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardedTabKeepsLastActiveTime); | 174 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardedTabKeepsLastActiveTime); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 // Otherwise returns the new web_contents of the discarded tab. | 320 // Otherwise returns the new web_contents of the discarded tab. |
| 315 content::WebContents* DiscardTabImpl(); | 321 content::WebContents* DiscardTabImpl(); |
| 316 | 322 |
| 317 // Returns true if tabs can be discarded only once. | 323 // Returns true if tabs can be discarded only once. |
| 318 bool CanOnlyDiscardOnce() const; | 324 bool CanOnlyDiscardOnce() const; |
| 319 | 325 |
| 320 // Returns a list of BrowserInfo sorted in z-order from top to bottom. The | 326 // Returns a list of BrowserInfo sorted in z-order from top to bottom. The |
| 321 // list is constructed from either |test_browser_info_list_| or BrowserList. | 327 // list is constructed from either |test_browser_info_list_| or BrowserList. |
| 322 std::vector<BrowserInfo> GetBrowserInfoList() const; | 328 std::vector<BrowserInfo> GetBrowserInfoList() const; |
| 323 | 329 |
| 330 void OnSessionRestoreStartedLoadingTabs(); |
| 331 void OnSessionRestoreFinishedLoadingTabs(); |
| 332 |
| 324 // Timer to periodically update the stats of the renderers. | 333 // Timer to periodically update the stats of the renderers. |
| 325 base::RepeatingTimer update_timer_; | 334 base::RepeatingTimer update_timer_; |
| 326 | 335 |
| 327 // Timer to periodically report whether a tab has been discarded since the | 336 // Timer to periodically report whether a tab has been discarded since the |
| 328 // last time the timer has fired. | 337 // last time the timer has fired. |
| 329 base::RepeatingTimer recent_tab_discard_timer_; | 338 base::RepeatingTimer recent_tab_discard_timer_; |
| 330 | 339 |
| 331 // A listener to global memory pressure events. | 340 // A listener to global memory pressure events. |
| 332 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; | 341 std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; |
| 333 | 342 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 // be crawled as the authoritative source of tabs, otherwise the BrowserList | 385 // be crawled as the authoritative source of tabs, otherwise the BrowserList |
| 377 // and associated Browser objects are crawled. The list must be sorted in | 386 // and associated Browser objects are crawled. The list must be sorted in |
| 378 // z-order, from top to bottom. | 387 // z-order, from top to bottom. |
| 379 // TODO(chrisha): Factor out tab-strip model enumeration to a helper class, | 388 // TODO(chrisha): Factor out tab-strip model enumeration to a helper class, |
| 380 // and make a delegate that centralizes all testing seams. | 389 // and make a delegate that centralizes all testing seams. |
| 381 std::vector<BrowserInfo> test_browser_info_list_; | 390 std::vector<BrowserInfo> test_browser_info_list_; |
| 382 | 391 |
| 383 // List of observers that will receive notifications on state changes. | 392 // List of observers that will receive notifications on state changes. |
| 384 base::ObserverList<TabManagerObserver> observers_; | 393 base::ObserverList<TabManagerObserver> observers_; |
| 385 | 394 |
| 395 bool is_session_restore_loading_tabs_; |
| 396 |
| 397 class TabManagerSessionRestoreObserver; |
| 398 std::unique_ptr<TabManagerSessionRestoreObserver> session_restore_observer_; |
| 399 |
| 386 // Weak pointer factory used for posting delayed tasks. | 400 // Weak pointer factory used for posting delayed tasks. |
| 387 base::WeakPtrFactory<TabManager> weak_ptr_factory_; | 401 base::WeakPtrFactory<TabManager> weak_ptr_factory_; |
| 388 | 402 |
| 389 DISALLOW_COPY_AND_ASSIGN(TabManager); | 403 DISALLOW_COPY_AND_ASSIGN(TabManager); |
| 390 }; | 404 }; |
| 391 | 405 |
| 392 } // namespace resource_coordinator | 406 } // namespace resource_coordinator |
| 393 | 407 |
| 394 #endif // CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_MANAGER_H_ | 408 #endif // CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_MANAGER_H_ |
| OLD | NEW |