| OLD | NEW | 
|    1 // Copyright 2013 The Chromium Authors. All rights reserved. |    1 // Copyright 2013 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 "content/browser/renderer_host/renderer_frame_manager.h" |    5 #include "content/browser/renderer_host/renderer_frame_manager.h" | 
|    6  |    6  | 
|    7 #include <algorithm> |    7 #include <algorithm> | 
|    8  |    8  | 
|    9 #include "base/bind.h" |    9 #include "base/bind.h" | 
|   10 #include "base/logging.h" |   10 #include "base/logging.h" | 
|   11 #include "base/memory/memory_coordinator_client_registry.h" |   11 #include "base/memory/memory_coordinator_client_registry.h" | 
|   12 #include "base/memory/memory_coordinator_proxy.h" |   12 #include "base/memory/memory_coordinator_proxy.h" | 
|   13 #include "base/memory/memory_pressure_listener.h" |   13 #include "base/memory/memory_pressure_listener.h" | 
|   14 #include "base/memory/memory_pressure_monitor.h" |   14 #include "base/memory/memory_pressure_monitor.h" | 
|   15 #include "base/memory/shared_memory.h" |   15 #include "base/memory/shared_memory.h" | 
|   16 #include "base/sys_info.h" |   16 #include "base/sys_info.h" | 
|   17 #include "build/build_config.h" |   17 #include "build/build_config.h" | 
|   18 #include "content/common/host_shared_bitmap_manager.h" |   18 #include "components/display_compositor/host_shared_bitmap_manager.h" | 
|   19 #include "content/public/common/content_features.h" |   19 #include "content/public/common/content_features.h" | 
|   20  |   20  | 
|   21 namespace content { |   21 namespace content { | 
|   22 namespace { |   22 namespace { | 
|   23  |   23  | 
|   24 const int kModeratePressurePercentage = 50; |   24 const int kModeratePressurePercentage = 50; | 
|   25 const int kCriticalPressurePercentage = 10; |   25 const int kCriticalPressurePercentage = 10; | 
|   26  |   26  | 
|   27 }  // namespace |   27 }  // namespace | 
|   28  |   28  | 
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  128       std::min(5, 2 + (base::SysInfo::AmountOfPhysicalMemoryMB() / 256)); |  128       std::min(5, 2 + (base::SysInfo::AmountOfPhysicalMemoryMB() / 256)); | 
|  129 #endif |  129 #endif | 
|  130   max_handles_ = base::SharedMemory::GetHandleLimit() / 8.0f; |  130   max_handles_ = base::SharedMemory::GetHandleLimit() / 8.0f; | 
|  131 } |  131 } | 
|  132  |  132  | 
|  133 RendererFrameManager::~RendererFrameManager() {} |  133 RendererFrameManager::~RendererFrameManager() {} | 
|  134  |  134  | 
|  135 void RendererFrameManager::CullUnlockedFrames(size_t saved_frame_limit) { |  135 void RendererFrameManager::CullUnlockedFrames(size_t saved_frame_limit) { | 
|  136   if (unlocked_frames_.size() + locked_frames_.size() > 0) { |  136   if (unlocked_frames_.size() + locked_frames_.size() > 0) { | 
|  137     float handles_per_frame = |  137     float handles_per_frame = | 
|  138         HostSharedBitmapManager::current()->AllocatedBitmapCount() * 1.0f / |  138         display_compositor::HostSharedBitmapManager::current() | 
|  139         (unlocked_frames_.size() + locked_frames_.size()); |  139             ->AllocatedBitmapCount() * | 
 |  140         1.0f / (unlocked_frames_.size() + locked_frames_.size()); | 
|  140  |  141  | 
|  141     saved_frame_limit = std::max( |  142     saved_frame_limit = std::max( | 
|  142         1, |  143         1, | 
|  143         static_cast<int>(std::min(static_cast<float>(saved_frame_limit), |  144         static_cast<int>(std::min(static_cast<float>(saved_frame_limit), | 
|  144                                   max_handles_ / handles_per_frame))); |  145                                   max_handles_ / handles_per_frame))); | 
|  145   } |  146   } | 
|  146   while (!unlocked_frames_.empty() && |  147   while (!unlocked_frames_.empty() && | 
|  147          unlocked_frames_.size() + locked_frames_.size() > saved_frame_limit) { |  148          unlocked_frames_.size() + locked_frames_.size() > saved_frame_limit) { | 
|  148     size_t old_size = unlocked_frames_.size(); |  149     size_t old_size = unlocked_frames_.size(); | 
|  149     // Should remove self from list. |  150     // Should remove self from list. | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
|  172 } |  173 } | 
|  173  |  174  | 
|  174 void RendererFrameManager::PurgeMemory(int percentage) { |  175 void RendererFrameManager::PurgeMemory(int percentage) { | 
|  175   int saved_frame_limit = max_number_of_saved_frames_; |  176   int saved_frame_limit = max_number_of_saved_frames_; | 
|  176   if (saved_frame_limit <= 1) |  177   if (saved_frame_limit <= 1) | 
|  177     return; |  178     return; | 
|  178   CullUnlockedFrames(std::max(1, (saved_frame_limit * percentage) / 100)); |  179   CullUnlockedFrames(std::max(1, (saved_frame_limit * percentage) / 100)); | 
|  179 } |  180 } | 
|  180  |  181  | 
|  181 }  // namespace content |  182 }  // namespace content | 
| OLD | NEW |