| 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_CHROMEOS_MEMORY_OOM_PRIORITY_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_MEMORY_OOM_PRIORITY_MANAGER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_MEMORY_OOM_PRIORITY_MANAGER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_MEMORY_OOM_PRIORITY_MANAGER_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/hash_tables.h" | 12 #include "base/hash_tables.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/process.h" | 14 #include "base/process.h" |
| 15 #include "base/string16.h" | 15 #include "base/string16.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "base/time.h" | 17 #include "base/time.h" |
| 18 #include "base/timer.h" | 18 #include "base/timer.h" |
| 19 #include "content/public/browser/notification_observer.h" | 19 #include "content/public/browser/notification_observer.h" |
| 20 #include "content/public/browser/notification_registrar.h" | 20 #include "content/public/browser/notification_registrar.h" |
| 21 | 21 |
| 22 class GURL; |
| 23 |
| 22 namespace chromeos { | 24 namespace chromeos { |
| 23 | 25 |
| 24 class LowMemoryObserver; | 26 class LowMemoryObserver; |
| 25 | 27 |
| 26 // The OomPriorityManager periodically checks (see | 28 // The OomPriorityManager periodically checks (see |
| 27 // ADJUSTMENT_INTERVAL_SECONDS in the source) the status of renderers | 29 // ADJUSTMENT_INTERVAL_SECONDS in the source) the status of renderers |
| 28 // and adjusts the out of memory (OOM) adjustment value (in | 30 // and adjusts the out of memory (OOM) adjustment value (in |
| 29 // /proc/<pid>/oom_score_adj) of the renderers so that they match the | 31 // /proc/<pid>/oom_score_adj) of the renderers so that they match the |
| 30 // algorithm embedded here for priority in being killed upon OOM | 32 // algorithm embedded here for priority in being killed upon OOM |
| 31 // conditions. | 33 // conditions. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 52 // Returns true if it successfully found a tab and discarded it. | 54 // Returns true if it successfully found a tab and discarded it. |
| 53 bool DiscardTab(); | 55 bool DiscardTab(); |
| 54 | 56 |
| 55 // Log memory statistics for the running processes, then discards a tab. | 57 // Log memory statistics for the running processes, then discards a tab. |
| 56 // Tab discard happens sometime later, as collecting the statistics touches | 58 // Tab discard happens sometime later, as collecting the statistics touches |
| 57 // multiple threads and takes time. | 59 // multiple threads and takes time. |
| 58 void LogMemoryAndDiscardTab(); | 60 void LogMemoryAndDiscardTab(); |
| 59 | 61 |
| 60 private: | 62 private: |
| 61 FRIEND_TEST_ALL_PREFIXES(OomPriorityManagerTest, Comparator); | 63 FRIEND_TEST_ALL_PREFIXES(OomPriorityManagerTest, Comparator); |
| 64 FRIEND_TEST_ALL_PREFIXES(OomPriorityManagerTest, IsReloadableUI); |
| 62 | 65 |
| 63 struct TabStats { | 66 struct TabStats { |
| 64 TabStats(); | 67 TabStats(); |
| 65 ~TabStats(); | 68 ~TabStats(); |
| 66 bool is_app; // browser window is an app | 69 bool is_app; // browser window is an app |
| 70 bool is_reloadable_ui; // Reloadable web UI page, like NTP or Settings. |
| 67 bool is_pinned; | 71 bool is_pinned; |
| 68 bool is_selected; // selected in the currently active browser window | 72 bool is_selected; // selected in the currently active browser window |
| 69 bool is_discarded; | 73 bool is_discarded; |
| 70 base::TimeTicks last_selected; | 74 base::TimeTicks last_selected; |
| 71 base::ProcessHandle renderer_handle; | 75 base::ProcessHandle renderer_handle; |
| 72 string16 title; | 76 string16 title; |
| 73 int64 tab_contents_id; // unique ID per WebContents | 77 int64 tab_contents_id; // unique ID per WebContents |
| 74 }; | 78 }; |
| 75 typedef std::vector<TabStats> TabStatsList; | 79 typedef std::vector<TabStats> TabStatsList; |
| 76 | 80 |
| 81 // Returns true if the |url| represents an internal Chrome web UI page that |
| 82 // can be easily reloaded and hence makes a good choice to discard. |
| 83 static bool IsReloadableUI(const GURL& url); |
| 84 |
| 77 // Discards a tab with the given unique ID. Returns true if discard occurred. | 85 // Discards a tab with the given unique ID. Returns true if discard occurred. |
| 78 bool DiscardTabById(int64 target_web_contents_id); | 86 bool DiscardTabById(int64 target_web_contents_id); |
| 79 | 87 |
| 80 // Records UMA histogram statistics for a tab discard. We record statistics | 88 // Records UMA histogram statistics for a tab discard. We record statistics |
| 81 // for user triggered discards via chrome://discards/ because that allows us | 89 // for user triggered discards via chrome://discards/ because that allows us |
| 82 // to manually test the system. | 90 // to manually test the system. |
| 83 void RecordDiscardStatistics(); | 91 void RecordDiscardStatistics(); |
| 84 | 92 |
| 85 // Returns the number of tabs open in all browser instances. | 93 // Returns the number of tabs open in all browser instances. |
| 86 int GetTabCount() const; | 94 int GetTabCount() const; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 141 |
| 134 // Number of times we have discarded a tab, for statistics. | 142 // Number of times we have discarded a tab, for statistics. |
| 135 int discard_count_; | 143 int discard_count_; |
| 136 | 144 |
| 137 DISALLOW_COPY_AND_ASSIGN(OomPriorityManager); | 145 DISALLOW_COPY_AND_ASSIGN(OomPriorityManager); |
| 138 }; | 146 }; |
| 139 | 147 |
| 140 } // namespace chrome | 148 } // namespace chrome |
| 141 | 149 |
| 142 #endif // CHROME_BROWSER_CHROMEOS_MEMORY_OOM_PRIORITY_MANAGER_H_ | 150 #endif // CHROME_BROWSER_CHROMEOS_MEMORY_OOM_PRIORITY_MANAGER_H_ |
| OLD | NEW |