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

Side by Side Diff: chrome/browser/sessions/tab_loader.h

Issue 2370753002: Make TabLoader a client of memory coordinator (Closed)
Patch Set: Add comments Created 4 years, 2 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
« no previous file with comments | « no previous file | chrome/browser/sessions/tab_loader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
128 // TODO(hajimehoshi): Remove this after implementing new API to get its
129 // current state instead.
130 base::MemoryState memory_state_;
haraken 2016/10/11 08:36:23 Is it hard to implement the API to get MemoryState
sky 2016/10/11 17:47:42 +1
hajimehoshi 2016/10/24 10:16:57 Done.
131
120 content::NotificationRegistrar registrar_; 132 content::NotificationRegistrar registrar_;
121 133
122 // The delay timer multiplier. See class description for details. 134 // The delay timer multiplier. See class description for details.
123 size_t force_load_delay_multiplier_; 135 size_t force_load_delay_multiplier_;
124 136
125 // True if the tab loading is enabled. 137 // True if the tab loading is enabled.
126 bool loading_enabled_; 138 bool loading_enabled_;
127 139
128 // The set of tabs we've initiated loading on. This does NOT include the 140 // The set of tabs we've initiated loading on. This does NOT include the
129 // selected tabs. 141 // selected tabs.
(...skipping 15 matching lines...) Expand all
145 // explicitly referenced so that it can be notified of deferred tab loads due 157 // explicitly referenced so that it can be notified of deferred tab loads due
146 // to memory pressure. 158 // to memory pressure.
147 scoped_refptr<SessionRestoreStatsCollector> stats_collector_; 159 scoped_refptr<SessionRestoreStatsCollector> stats_collector_;
148 160
149 static TabLoader* shared_tab_loader_; 161 static TabLoader* shared_tab_loader_;
150 162
151 DISALLOW_COPY_AND_ASSIGN(TabLoader); 163 DISALLOW_COPY_AND_ASSIGN(TabLoader);
152 }; 164 };
153 165
154 #endif // CHROME_BROWSER_SESSIONS_TAB_LOADER_H_ 166 #endif // CHROME_BROWSER_SESSIONS_TAB_LOADER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sessions/tab_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698