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_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 10 matching lines...) Expand all Loading... |
21 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
22 #include "base/observer_list.h" | 22 #include "base/observer_list.h" |
23 #include "base/strings/string16.h" | 23 #include "base/strings/string16.h" |
24 #include "base/task_runner.h" | 24 #include "base/task_runner.h" |
25 #include "base/timer/timer.h" | 25 #include "base/timer/timer.h" |
26 #include "build/build_config.h" | 26 #include "build/build_config.h" |
27 #include "chrome/browser/memory/tab_manager_observer.h" | 27 #include "chrome/browser/memory/tab_manager_observer.h" |
28 #include "chrome/browser/memory/tab_stats.h" | 28 #include "chrome/browser/memory/tab_stats.h" |
29 #include "chrome/browser/ui/browser_tab_strip_tracker.h" | 29 #include "chrome/browser/ui/browser_tab_strip_tracker.h" |
30 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 30 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 31 #include "content/public/browser/memory_coordinator_delegate.h" |
31 | 32 |
32 class BrowserList; | 33 class BrowserList; |
33 class GURL; | 34 class GURL; |
34 class TabStripModel; | 35 class TabStripModel; |
35 | 36 |
36 namespace base { | 37 namespace base { |
37 class TickClock; | 38 class TickClock; |
38 } | 39 } |
39 | 40 |
40 namespace content { | 41 namespace content { |
(...skipping 17 matching lines...) Expand all Loading... |
58 // | 59 // |
59 // On Chrome OS (via the delegate), the kernel (via /proc/<pid>/oom_score_adj) | 60 // On Chrome OS (via the delegate), the kernel (via /proc/<pid>/oom_score_adj) |
60 // will be informed of each renderer's score, which is based on the status, so | 61 // will be informed of each renderer's score, which is based on the status, so |
61 // in case Chrome is not able to relieve the pressure quickly enough and the | 62 // in case Chrome is not able to relieve the pressure quickly enough and the |
62 // kernel is forced to kill processes, it will be able to do so using the same | 63 // kernel is forced to kill processes, it will be able to do so using the same |
63 // algorithm as the one used here. | 64 // algorithm as the one used here. |
64 // | 65 // |
65 // Note that the browser tests are only active for platforms that use | 66 // Note that the browser tests are only active for platforms that use |
66 // TabManager (CrOS only for now) and need to be adjusted accordingly if | 67 // TabManager (CrOS only for now) and need to be adjusted accordingly if |
67 // support for new platforms is added. | 68 // support for new platforms is added. |
68 class TabManager : public TabStripModelObserver { | 69 class TabManager : public TabStripModelObserver, |
| 70 public content::MemoryCoordinatorDelegate { |
69 public: | 71 public: |
70 // Needs to be public for DEFINE_WEB_CONTENTS_USER_DATA_KEY. | 72 // Needs to be public for DEFINE_WEB_CONTENTS_USER_DATA_KEY. |
71 class WebContentsData; | 73 class WebContentsData; |
72 | 74 |
73 TabManager(); | 75 TabManager(); |
74 ~TabManager() override; | 76 ~TabManager() override; |
75 | 77 |
76 // Number of discard events since Chrome started. | 78 // Number of discard events since Chrome started. |
77 int discard_count() const { return discard_count_; } | 79 int discard_count() const { return discard_count_; } |
78 | 80 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 // Returns the auto-discardable state of the tab. When true, the tab is | 142 // Returns the auto-discardable state of the tab. When true, the tab is |
141 // eligible to be automatically discarded when critical memory pressure hits, | 143 // eligible to be automatically discarded when critical memory pressure hits, |
142 // otherwise the tab is ignored and will never be automatically discarded. | 144 // otherwise the tab is ignored and will never be automatically discarded. |
143 // Note that this property doesn't block the discarding of the tab via other | 145 // Note that this property doesn't block the discarding of the tab via other |
144 // methods (about:discards for instance). | 146 // methods (about:discards for instance). |
145 bool IsTabAutoDiscardable(content::WebContents* contents) const; | 147 bool IsTabAutoDiscardable(content::WebContents* contents) const; |
146 | 148 |
147 // Sets/clears the auto-discardable state of the tab. | 149 // Sets/clears the auto-discardable state of the tab. |
148 void SetTabAutoDiscardableState(content::WebContents* contents, bool state); | 150 void SetTabAutoDiscardableState(content::WebContents* contents, bool state); |
149 | 151 |
| 152 // MemoryCoordinatorDelegate implementation. |
| 153 bool CanSuspendBackgroundedRenderer(int render_process_id) override; |
| 154 |
150 // Returns true if |first| is considered less desirable to be killed than | 155 // Returns true if |first| is considered less desirable to be killed than |
151 // |second|. | 156 // |second|. |
152 static bool CompareTabStats(const TabStats& first, const TabStats& second); | 157 static bool CompareTabStats(const TabStats& first, const TabStats& second); |
153 | 158 |
154 // Returns a unique ID for a WebContents. Do not cast back to a pointer, as | 159 // Returns a unique ID for a WebContents. Do not cast back to a pointer, as |
155 // the WebContents could be deleted if the user closed the tab. | 160 // the WebContents could be deleted if the user closed the tab. |
156 static int64_t IdFromWebContents(content::WebContents* web_contents); | 161 static int64_t IdFromWebContents(content::WebContents* web_contents); |
157 | 162 |
158 private: | 163 private: |
159 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, AutoDiscardable); | 164 FRIEND_TEST_ALL_PREFIXES(TabManagerTest, AutoDiscardable); |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 | 384 |
380 // Weak pointer factory used for posting delayed tasks to task_runner_. | 385 // Weak pointer factory used for posting delayed tasks to task_runner_. |
381 base::WeakPtrFactory<TabManager> weak_ptr_factory_; | 386 base::WeakPtrFactory<TabManager> weak_ptr_factory_; |
382 | 387 |
383 DISALLOW_COPY_AND_ASSIGN(TabManager); | 388 DISALLOW_COPY_AND_ASSIGN(TabManager); |
384 }; | 389 }; |
385 | 390 |
386 } // namespace memory | 391 } // namespace memory |
387 | 392 |
388 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ | 393 #endif // CHROME_BROWSER_MEMORY_TAB_MANAGER_H_ |
OLD | NEW |