OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_SESSIONS_TAB_LOADER_H_ | 5 #ifndef CHROME_BROWSER_SESSIONS_TAB_LOADER_H_ |
6 #define CHROME_BROWSER_SESSIONS_TAB_LOADER_H_ | 6 #define CHROME_BROWSER_SESSIONS_TAB_LOADER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <list> | 10 #include <list> |
11 #include <memory> | 11 #include <memory> |
12 #include <set> | 12 #include <set> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/memory_coordinator_client.h" |
15 #include "base/memory/memory_pressure_listener.h" | 16 #include "base/memory/memory_pressure_listener.h" |
16 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
17 #include "chrome/browser/sessions/session_restore_delegate.h" | 18 #include "chrome/browser/sessions/session_restore_delegate.h" |
18 #include "chrome/browser/sessions/tab_loader_delegate.h" | 19 #include "chrome/browser/sessions/tab_loader_delegate.h" |
19 #include "content/public/browser/notification_observer.h" | 20 #include "content/public/browser/notification_observer.h" |
20 #include "content/public/browser/notification_registrar.h" | 21 #include "content/public/browser/notification_registrar.h" |
21 | 22 |
22 namespace content { | 23 namespace content { |
23 class NavigationController; | 24 class NavigationController; |
24 class RenderWidgetHost; | 25 class RenderWidgetHost; |
25 } | 26 } |
26 | 27 |
27 class SessionRestoreStatsCollector; | 28 class SessionRestoreStatsCollector; |
28 | 29 |
29 // TabLoader is responsible for loading tabs after session restore has finished | 30 // TabLoader is responsible for loading tabs after session restore has finished |
30 // creating all the tabs. Tabs are loaded after a previously tab finishes | 31 // creating all the tabs. Tabs are loaded after a previously tab finishes |
31 // loading or a timeout is reached. If the timeout is reached before a tab | 32 // loading or a timeout is reached. If the timeout is reached before a tab |
32 // finishes loading the timeout delay is doubled. | 33 // finishes loading the timeout delay is doubled. |
33 // | 34 // |
34 // TabLoader keeps a reference to itself when it's loading. When it has finished | 35 // TabLoader keeps a reference to itself when it's loading. When it has finished |
35 // loading, it drops the reference. If another profile is restored while the | 36 // loading, it drops the reference. If another profile is restored while the |
36 // TabLoader is loading, it will schedule its tabs to get loaded by the same | 37 // TabLoader is loading, it will schedule its tabs to get loaded by the same |
37 // TabLoader. When doing the scheduling, it holds a reference to the TabLoader. | 38 // TabLoader. When doing the scheduling, it holds a reference to the TabLoader. |
38 // | 39 // |
39 // This is not part of SessionRestoreImpl so that synchronous destruction | 40 // This is not part of SessionRestoreImpl so that synchronous destruction |
40 // of SessionRestoreImpl doesn't have timing problems. | 41 // of SessionRestoreImpl doesn't have timing problems. |
41 class TabLoader : public content::NotificationObserver, | 42 class TabLoader : public content::NotificationObserver, |
42 public base::RefCounted<TabLoader>, | 43 public base::RefCounted<TabLoader>, |
43 public TabLoaderCallback { | 44 public TabLoaderCallback, |
| 45 public base::MemoryCoordinatorClient { |
44 public: | 46 public: |
45 using RestoredTab = SessionRestoreDelegate::RestoredTab; | 47 using RestoredTab = SessionRestoreDelegate::RestoredTab; |
46 | 48 |
47 // NotificationObserver method. Removes the specified tab and loads the next | 49 // NotificationObserver method. Removes the specified tab and loads the next |
48 // tab. | 50 // tab. |
49 void Observe(int type, | 51 void Observe(int type, |
50 const content::NotificationSource& source, | 52 const content::NotificationSource& source, |
51 const content::NotificationDetails& details) override; | 53 const content::NotificationDetails& details) override; |
52 | 54 |
53 // TabLoaderCallback: | 55 // TabLoaderCallback: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 // NULL otherwise. | 98 // NULL otherwise. |
97 static content::RenderWidgetHost* GetRenderWidgetHost( | 99 static content::RenderWidgetHost* GetRenderWidgetHost( |
98 content::NavigationController* controller); | 100 content::NavigationController* controller); |
99 | 101 |
100 // Register for necessary notifications on a tab navigation controller. | 102 // Register for necessary notifications on a tab navigation controller. |
101 void RegisterForNotifications(content::NavigationController* controller); | 103 void RegisterForNotifications(content::NavigationController* controller); |
102 | 104 |
103 // Called when a tab goes away or a load completes. | 105 // Called when a tab goes away or a load completes. |
104 void HandleTabClosedOrLoaded(content::NavigationController* controller); | 106 void HandleTabClosedOrLoaded(content::NavigationController* controller); |
105 | 107 |
106 // Convenience function returning the current memory pressure level. | 108 // Returns true when this is under memory pressure and required to purge |
107 base::MemoryPressureListener::MemoryPressureLevel | 109 // memory by stopping loading tabs. |
108 CurrentMemoryPressureLevel(); | 110 bool ShouldStopLoadingTabs() const; |
109 | 111 |
110 // React to memory pressure by stopping to load any more tabs. | 112 // React to memory pressure by stopping to load any more tabs. |
111 void OnMemoryPressure( | 113 void OnMemoryPressure( |
112 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); | 114 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level); |
113 | 115 |
| 116 // base::MemoryCoordinatorClient implementation: |
| 117 void OnMemoryStateChange(base::MemoryState state) override; |
| 118 |
| 119 // Stops loading tabs to purge memory by stopping to load any more tabs. |
| 120 void StopLoadingTabs(); |
| 121 |
114 std::unique_ptr<TabLoaderDelegate> delegate_; | 122 std::unique_ptr<TabLoaderDelegate> delegate_; |
115 | 123 |
116 // Listens for system under memory pressure notifications and stops loading | 124 // Listens for system under memory pressure notifications and stops loading |
117 // of tabs when we start running out of memory. | 125 // of tabs when we start running out of memory. |
118 base::MemoryPressureListener memory_pressure_listener_; | 126 base::MemoryPressureListener memory_pressure_listener_; |
119 | 127 |
120 content::NotificationRegistrar registrar_; | 128 content::NotificationRegistrar registrar_; |
121 | 129 |
122 // The delay timer multiplier. See class description for details. | 130 // The delay timer multiplier. See class description for details. |
123 size_t force_load_delay_multiplier_; | 131 size_t force_load_delay_multiplier_; |
(...skipping 21 matching lines...) Expand all Loading... |
145 // explicitly referenced so that it can be notified of deferred tab loads due | 153 // explicitly referenced so that it can be notified of deferred tab loads due |
146 // to memory pressure. | 154 // to memory pressure. |
147 scoped_refptr<SessionRestoreStatsCollector> stats_collector_; | 155 scoped_refptr<SessionRestoreStatsCollector> stats_collector_; |
148 | 156 |
149 static TabLoader* shared_tab_loader_; | 157 static TabLoader* shared_tab_loader_; |
150 | 158 |
151 DISALLOW_COPY_AND_ASSIGN(TabLoader); | 159 DISALLOW_COPY_AND_ASSIGN(TabLoader); |
152 }; | 160 }; |
153 | 161 |
154 #endif // CHROME_BROWSER_SESSIONS_TAB_LOADER_H_ | 162 #endif // CHROME_BROWSER_SESSIONS_TAB_LOADER_H_ |
OLD | NEW |