| 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 #include "chrome/browser/memory/tab_manager.h" | 5 #include "chrome/browser/memory/tab_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 } | 912 } |
| 913 | 913 |
| 914 TimeTicks TabManager::NowTicks() const { | 914 TimeTicks TabManager::NowTicks() const { |
| 915 if (!test_tick_clock_) | 915 if (!test_tick_clock_) |
| 916 return TimeTicks::Now(); | 916 return TimeTicks::Now(); |
| 917 | 917 |
| 918 return test_tick_clock_->NowTicks(); | 918 return test_tick_clock_->NowTicks(); |
| 919 } | 919 } |
| 920 | 920 |
| 921 void TabManager::DoChildProcessDispatch() { | 921 void TabManager::DoChildProcessDispatch() { |
| 922 printf("TabManager::DoChildProcessDispatch\n"); |
| 922 // If Chrome is shutting down, do not do anything. | 923 // If Chrome is shutting down, do not do anything. |
| 923 if (g_browser_process->IsShuttingDown()) | 924 if (g_browser_process->IsShuttingDown()) |
| 924 return; | 925 return; |
| 925 | 926 |
| 926 if (!under_memory_pressure_) | 927 if (!under_memory_pressure_) |
| 927 under_memory_pressure_ = true; | 928 under_memory_pressure_ = true; |
| 928 | 929 |
| 929 // If the memory pressure condition has ended then stop dispatching messages. | 930 // If the memory pressure condition has ended then stop dispatching messages. |
| 930 auto level = get_current_pressure_level_.Run(); | 931 auto level = get_current_pressure_level_.Run(); |
| 931 if (level == base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) { | 932 if (level == base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_NONE) { |
| 933 printf(" ...no pressure\n"); |
| 932 under_memory_pressure_ = false; | 934 under_memory_pressure_ = false; |
| 933 notified_renderers_.clear(); | 935 notified_renderers_.clear(); |
| 934 return; | 936 return; |
| 935 } | 937 } |
| 936 | 938 |
| 937 // Get a vector of active renderers, from highest to lowest priority. | 939 // Get a vector of active renderers, from highest to lowest priority. |
| 938 auto renderers = GetOrderedRenderers(); | 940 auto renderers = GetOrderedRenderers(); |
| 939 | 941 |
| 940 // The following code requires at least one renderer to be present or it will | 942 // The following code requires at least one renderer to be present or it will |
| 941 // busyloop. It's possible for no renderers to exist (we eliminate visible | 943 // busyloop. It's possible for no renderers to exist (we eliminate visible |
| 942 // renderers to avoid janking them), so bail early if that's the case. | 944 // renderers to avoid janking them), so bail early if that's the case. |
| 943 if (renderers.empty()) | 945 if (renderers.empty()) |
| 944 return; | 946 return; |
| 945 | 947 |
| 946 // Notify a single renderer of memory pressure. | 948 // Notify a single renderer of memory pressure. |
| 947 bool notified = false; | 949 bool notified = false; |
| 948 while (!notified) { | 950 while (!notified) { |
| 949 // Notify the lowest priority renderer that hasn't been notified yet. | 951 // Notify the lowest priority renderer that hasn't been notified yet. |
| 950 for (auto rit = renderers.rbegin(); rit != renderers.rend(); ++rit) { | 952 for (auto rit = renderers.rbegin(); rit != renderers.rend(); ++rit) { |
| 951 // If this renderer has already been notified then look at the next one. | 953 // If this renderer has already been notified then look at the next one. |
| 952 if (!notified_renderers_.insert(*rit).second) | 954 if (!notified_renderers_.insert(*rit).second) |
| 953 continue; | 955 continue; |
| 954 | 956 |
| 955 // Notify the renderer. | 957 // Notify the renderer. |
| 956 notify_renderer_process_.Run(*rit, level); | 958 notify_renderer_process_.Run(*rit, level); |
| 959 printf(" ...notified renderer %x\n", (int)(intptr_t)(*rit)); |
| 957 notified = true; | 960 notified = true; |
| 958 break; | 961 break; |
| 959 } | 962 } |
| 960 | 963 |
| 961 // If all renderers were processed and none were notified, then all | 964 // If all renderers were processed and none were notified, then all |
| 962 // renderers have already been notified. Clear the list and start again. | 965 // renderers have already been notified. Clear the list and start again. |
| 963 if (!notified) | 966 if (!notified) |
| 964 notified_renderers_.clear(); | 967 notified_renderers_.clear(); |
| 965 | 968 |
| 966 // This loop can only run at most twice. If it doesn't exit the first time | 969 // This loop can only run at most twice. If it doesn't exit the first time |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 // platform. | 1014 // platform. |
| 1012 std::string allow_multiple_discards = variations::GetVariationParamValue( | 1015 std::string allow_multiple_discards = variations::GetVariationParamValue( |
| 1013 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); | 1016 features::kAutomaticTabDiscarding.name, "AllowMultipleDiscards"); |
| 1014 return (allow_multiple_discards != "true"); | 1017 return (allow_multiple_discards != "true"); |
| 1015 #else | 1018 #else |
| 1016 return false; | 1019 return false; |
| 1017 #endif | 1020 #endif |
| 1018 } | 1021 } |
| 1019 | 1022 |
| 1020 } // namespace memory | 1023 } // namespace memory |
| OLD | NEW |