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

Side by Side Diff: chrome/browser/memory/tab_manager.h

Issue 2153943002: Implementing TabManager extensions API Discard Function. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: testcases Created 4 years, 5 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 #ifndef CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ 5 #ifndef CHROME_BROWSER_MEMORY_TAB_MANAGER_H_
6 #define CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ 6 #define CHROME_BROWSER_MEMORY_TAB_MANAGER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // Discards a tab to free the memory occupied by its renderer. The tab still 101 // Discards a tab to free the memory occupied by its renderer. The tab still
102 // exists in the tab-strip; clicking on it will reload it. 102 // exists in the tab-strip; clicking on it will reload it.
103 void DiscardTab(); 103 void DiscardTab();
104 104
105 // Discards a tab with the given unique ID. The tab still exists in the 105 // Discards a tab with the given unique ID. The tab still exists in the
106 // tab-strip; clicking on it will reload it. Returns null if the tab cannot 106 // tab-strip; clicking on it will reload it. Returns null if the tab cannot
107 // be found or cannot be discarded. Otherwise returns the old web_contents 107 // be found or cannot be discarded. Otherwise returns the old web_contents
108 // that got discarded. This value is mostly useful during testing. 108 // that got discarded. This value is mostly useful during testing.
109 content::WebContents* DiscardTabById(int64_t target_web_contents_id); 109 content::WebContents* DiscardTabById(int64_t target_web_contents_id);
110 110
111 // If |contents| is null, discards the least important tab using DiscardTab().
Georges Khalil 2016/07/19 19:39:45 Start comment by explaining that this is the funct
Anderson Silva 2016/07/19 20:28:42 Done.
112 // Otherwise discards the given contents.
113 content::WebContents* DiscardTabByExtension(content::WebContents* contents);
114
111 // Log memory statistics for the running processes, then discards a tab. 115 // Log memory statistics for the running processes, then discards a tab.
112 // Tab discard happens sometime later, as collecting the statistics touches 116 // Tab discard happens sometime later, as collecting the statistics touches
113 // multiple threads and takes time. 117 // multiple threads and takes time.
114 void LogMemoryAndDiscardTab(); 118 void LogMemoryAndDiscardTab();
115 119
116 // Log memory statistics for the running processes, then call the callback. 120 // Log memory statistics for the running processes, then call the callback.
117 void LogMemory(const std::string& title, const base::Closure& callback); 121 void LogMemory(const std::string& title, const base::Closure& callback);
118 122
119 // Used to set the test TickClock, which then gets used by NowTicks(). See 123 // Used to set the test TickClock, which then gets used by NowTicks(). See
120 // |test_tick_clock_| for more details. 124 // |test_tick_clock_| for more details.
121 void set_test_tick_clock(base::TickClock* test_tick_clock); 125 void set_test_tick_clock(base::TickClock* test_tick_clock);
122 126
123 // Returns the list of the stats for all renderers. Must be called on the UI 127 // Returns the list of the stats for all renderers. Must be called on the UI
124 // thread. 128 // thread.
125 TabStatsList GetUnsortedTabStats(); 129 TabStatsList GetUnsortedTabStats();
126 130
127 // Add/remove observers. 131 // Add/remove observers.
128 void AddObserver(TabManagerObserver* observer); 132 void AddObserver(TabManagerObserver* observer);
129 void RemoveObserver(TabManagerObserver* observer); 133 void RemoveObserver(TabManagerObserver* observer);
130 134
135 // Used in tets to change the protection time of the tabs.
Georges Khalil 2016/07/19 19:39:45 nit: tets -> tests.
136 void set_minimum_protection_time_for_tests(unsigned int time_seconds);
Georges Khalil 2016/07/19 19:39:45 This should take a base::TimeDelta so there's no c
Anderson Silva 2016/07/19 20:28:42 Done.
137
131 private: 138 private:
132 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, CanOnlyDiscardOnce); 139 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, CanOnlyDiscardOnce);
133 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ChildProcessNotifications); 140 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ChildProcessNotifications);
134 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, Comparator); 141 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, Comparator);
135 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardedTabKeepsLastActiveTime); 142 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardedTabKeepsLastActiveTime);
136 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardWebContentsAt); 143 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, DiscardWebContentsAt);
137 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, InvalidOrEmptyURL); 144 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, InvalidOrEmptyURL);
138 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, IsInternalPage); 145 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, IsInternalPage);
139 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, OomPressureListener); 146 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, OomPressureListener);
140 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ProtectPDFPages); 147 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, ProtectPDFPages);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 static bool CompareTabStats(TabStats first, TabStats second); 256 static bool CompareTabStats(TabStats first, TabStats second);
250 257
251 // Returns either the system's clock or the test clock. See |test_tick_clock_| 258 // Returns either the system's clock or the test clock. See |test_tick_clock_|
252 // for more details. 259 // for more details.
253 base::TimeTicks NowTicks() const; 260 base::TimeTicks NowTicks() const;
254 261
255 // Dispatches a memory pressure message to a single child process, and 262 // Dispatches a memory pressure message to a single child process, and
256 // schedules another call to itself as long as memory pressure continues. 263 // schedules another call to itself as long as memory pressure continues.
257 void DoChildProcessDispatch(); 264 void DoChildProcessDispatch();
258 265
259 // Implementation of DiscardTab. 266 // Implementation of DiscardTab.
Georges Khalil 2016/07/19 19:39:45 Add comment about return value.
260 bool DiscardTabImpl(); 267 content::WebContents* DiscardTabImpl();
261 268
262 // Returns true if tabs can be discarded only once. 269 // Returns true if tabs can be discarded only once.
263 bool CanOnlyDiscardOnce(); 270 bool CanOnlyDiscardOnce();
264 271
265 // Timer to periodically update the stats of the renderers. 272 // Timer to periodically update the stats of the renderers.
266 base::RepeatingTimer update_timer_; 273 base::RepeatingTimer update_timer_;
267 274
268 // Timer to periodically report whether a tab has been discarded since the 275 // Timer to periodically report whether a tab has been discarded since the
269 // last time the timer has fired. 276 // last time the timer has fired.
270 base::RepeatingTimer recent_tab_discard_timer_; 277 base::RepeatingTimer recent_tab_discard_timer_;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 355
349 // Weak pointer factory used for posting delayed tasks to task_runner_. 356 // Weak pointer factory used for posting delayed tasks to task_runner_.
350 base::WeakPtrFactory<TabManager> weak_ptr_factory_; 357 base::WeakPtrFactory<TabManager> weak_ptr_factory_;
351 358
352 DISALLOW_COPY_AND_ASSIGN(TabManager); 359 DISALLOW_COPY_AND_ASSIGN(TabManager);
353 }; 360 };
354 361
355 } // namespace memory 362 } // namespace memory
356 363
357 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ 364 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698