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

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: reset protection time Created 4 years, 4 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 | « chrome/browser/extensions/api/tabs/tabs_test.cc ('k') | chrome/browser/memory/tab_manager.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 (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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // the automatic tab discarding mechanism. Note that this is not used when 97 // the automatic tab discarding mechanism. Note that this is not used when
98 // discarding a particular tab from about:discards. 98 // discarding a particular tab from about:discards.
99 bool CanDiscardTab(int64_t target_web_contents_id) const; 99 bool CanDiscardTab(int64_t target_web_contents_id) const;
100 100
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 new web_contents
108 // that got discarded. This value is mostly useful during testing. 108 // of the discarded tab.
109 content::WebContents* DiscardTabById(int64_t target_web_contents_id); 109 content::WebContents* DiscardTabById(int64_t target_web_contents_id);
110 110
111 // Method used by the extensions API to discard tabs. If |contents| is null,
112 // discards the least important tab using DiscardTab(). Otherwise discards
113 // the given contents. Returns the new web_contents or null if no tab
114 // was discarded.
115 content::WebContents* DiscardTabByExtension(content::WebContents* contents);
116
111 // Log memory statistics for the running processes, then discards a tab. 117 // Log memory statistics for the running processes, then discards a tab.
112 // Tab discard happens sometime later, as collecting the statistics touches 118 // Tab discard happens sometime later, as collecting the statistics touches
113 // multiple threads and takes time. 119 // multiple threads and takes time.
114 void LogMemoryAndDiscardTab(); 120 void LogMemoryAndDiscardTab();
115 121
116 // Log memory statistics for the running processes, then call the callback. 122 // Log memory statistics for the running processes, then call the callback.
117 void LogMemory(const std::string& title, const base::Closure& callback); 123 void LogMemory(const std::string& title, const base::Closure& callback);
118 124
119 // Used to set the test TickClock, which then gets used by NowTicks(). See 125 // Used to set the test TickClock, which then gets used by NowTicks(). See
120 // |test_tick_clock_| for more details. 126 // |test_tick_clock_| for more details.
121 void set_test_tick_clock(base::TickClock* test_tick_clock); 127 void set_test_tick_clock(base::TickClock* test_tick_clock);
122 128
123 // Returns the list of the stats for all renderers. Must be called on the UI 129 // Returns the list of the stats for all renderers. Must be called on the UI
124 // thread. 130 // thread.
125 TabStatsList GetUnsortedTabStats(); 131 TabStatsList GetUnsortedTabStats();
126 132
127 void AddObserver(TabManagerObserver* observer); 133 void AddObserver(TabManagerObserver* observer);
128 void RemoveObserver(TabManagerObserver* observer); 134 void RemoveObserver(TabManagerObserver* observer);
129 135
136 // Used in tests to change the protection time of the tabs.
137 void set_minimum_protection_time_for_tests(
138 base::TimeDelta minimum_protection_time);
139
130 // Returns the auto-discardable state of the tab. When true, the tab is 140 // Returns the auto-discardable state of the tab. When true, the tab is
131 // eligible to be automatically discarded when critical memory pressure hits, 141 // eligible to be automatically discarded when critical memory pressure hits,
132 // otherwise the tab is ignored and will never be automatically discarded. 142 // otherwise the tab is ignored and will never be automatically discarded.
133 // Note that this property doesn't block the discarding of the tab via other 143 // Note that this property doesn't block the discarding of the tab via other
134 // methods (about:discards for instance). 144 // methods (about:discards for instance).
135 bool IsTabAutoDiscardable(content::WebContents* contents) const; 145 bool IsTabAutoDiscardable(content::WebContents* contents) const;
136 146
137 // Sets/clears the auto-discardable state of the tab. 147 // Sets/clears the auto-discardable state of the tab.
138 void SetTabAutoDiscardableState(content::WebContents* contents, bool state); 148 void SetTabAutoDiscardableState(content::WebContents* contents, bool state);
139 149
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 WebContentsData* GetWebContentsData(content::WebContents* contents) const; 274 WebContentsData* GetWebContentsData(content::WebContents* contents) const;
265 275
266 // Returns either the system's clock or the test clock. See |test_tick_clock_| 276 // Returns either the system's clock or the test clock. See |test_tick_clock_|
267 // for more details. 277 // for more details.
268 base::TimeTicks NowTicks() const; 278 base::TimeTicks NowTicks() const;
269 279
270 // Dispatches a memory pressure message to a single child process, and 280 // Dispatches a memory pressure message to a single child process, and
271 // schedules another call to itself as long as memory pressure continues. 281 // schedules another call to itself as long as memory pressure continues.
272 void DoChildProcessDispatch(); 282 void DoChildProcessDispatch();
273 283
274 // Implementation of DiscardTab. 284 // Implementation of DiscardTab. Returns null if no tab was discarded.
275 bool DiscardTabImpl(); 285 // Otherwise returns the new web_contents of the discarded tab.
286 content::WebContents* DiscardTabImpl();
276 287
277 // Returns true if tabs can be discarded only once. 288 // Returns true if tabs can be discarded only once.
278 bool CanOnlyDiscardOnce(); 289 bool CanOnlyDiscardOnce();
279 290
280 // Timer to periodically update the stats of the renderers. 291 // Timer to periodically update the stats of the renderers.
281 base::RepeatingTimer update_timer_; 292 base::RepeatingTimer update_timer_;
282 293
283 // Timer to periodically report whether a tab has been discarded since the 294 // Timer to periodically report whether a tab has been discarded since the
284 // last time the timer has fired. 295 // last time the timer has fired.
285 base::RepeatingTimer recent_tab_discard_timer_; 296 base::RepeatingTimer recent_tab_discard_timer_;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 374
364 // Weak pointer factory used for posting delayed tasks to task_runner_. 375 // Weak pointer factory used for posting delayed tasks to task_runner_.
365 base::WeakPtrFactory<TabManager> weak_ptr_factory_; 376 base::WeakPtrFactory<TabManager> weak_ptr_factory_;
366 377
367 DISALLOW_COPY_AND_ASSIGN(TabManager); 378 DISALLOW_COPY_AND_ASSIGN(TabManager);
368 }; 379 };
369 380
370 } // namespace memory 381 } // namespace memory
371 382
372 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ 383 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs_test.cc ('k') | chrome/browser/memory/tab_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698