| 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 "content/renderer/render_thread_impl.h" | 5 #include "content/renderer/render_thread_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 2200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2211 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); | 2211 static_cast<blink::WebMemoryPressureLevel>(memory_pressure_level)); |
| 2212 } | 2212 } |
| 2213 if (memory_pressure_level == | 2213 if (memory_pressure_level == |
| 2214 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { | 2214 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL) { |
| 2215 ReleaseFreeMemory(); | 2215 ReleaseFreeMemory(); |
| 2216 ClearMemory(); | 2216 ClearMemory(); |
| 2217 } | 2217 } |
| 2218 } | 2218 } |
| 2219 | 2219 |
| 2220 void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) { | 2220 void RenderThreadImpl::OnMemoryStateChange(base::MemoryState state) { |
| 2221 // TODO(hajimehoshi): Adjust the size of this memory usage according to | |
| 2222 // |state|. RenderThreadImpl doesn't have a feature to limit memory usage at | |
| 2223 // present. | |
| 2224 if (blink_platform_impl_) { | 2221 if (blink_platform_impl_) { |
| 2225 blink::WebMemoryCoordinator::onMemoryStateChange( | 2222 blink::WebMemoryCoordinator::onMemoryStateChange( |
| 2226 static_cast<blink::MemoryState>(state)); | 2223 static_cast<blink::MemoryState>(state)); |
| 2227 } | 2224 } |
| 2228 switch (state) { | 2225 } |
| 2229 case base::MemoryState::NORMAL: | 2226 |
| 2230 break; | 2227 void RenderThreadImpl::OnPurgeMemory() { |
| 2231 case base::MemoryState::THROTTLED: | 2228 OnTrimMemoryImmediately(); |
| 2232 // TODO(bashi): Figure out what kind of strategy is suitable on | 2229 ReleaseFreeMemory(); |
| 2233 // THROTTLED state. crbug.com/674815 | 2230 ClearMemory(); |
| 2234 #if defined(OS_ANDROID) | 2231 if (blink_platform_impl_) |
| 2235 OnTrimMemoryImmediately(); | 2232 blink::WebMemoryCoordinator::onPurgeMemory(); |
| 2236 #else | |
| 2237 OnSyncMemoryPressure( | |
| 2238 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); | |
| 2239 #endif | |
| 2240 ReleaseFreeMemory(); | |
| 2241 break; | |
| 2242 case base::MemoryState::SUSPENDED: | |
| 2243 OnTrimMemoryImmediately(); | |
| 2244 ReleaseFreeMemory(); | |
| 2245 ClearMemory(); | |
| 2246 break; | |
| 2247 case base::MemoryState::UNKNOWN: | |
| 2248 NOTREACHED(); | |
| 2249 break; | |
| 2250 } | |
| 2251 } | 2233 } |
| 2252 | 2234 |
| 2253 void RenderThreadImpl::ClearMemory() { | 2235 void RenderThreadImpl::ClearMemory() { |
| 2254 // Do not call into blink if it is not initialized. | 2236 // Do not call into blink if it is not initialized. |
| 2255 if (blink_platform_impl_) { | 2237 if (blink_platform_impl_) { |
| 2256 // Purge Skia font cache, by setting it to 0 and then again to the | 2238 // Purge Skia font cache, by setting it to 0 and then again to the |
| 2257 // previous limit. | 2239 // previous limit. |
| 2258 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); | 2240 size_t font_cache_limit = SkGraphics::SetFontCacheLimit(0); |
| 2259 SkGraphics::SetFontCacheLimit(font_cache_limit); | 2241 SkGraphics::SetFontCacheLimit(font_cache_limit); |
| 2260 } | 2242 } |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2440 } | 2422 } |
| 2441 } | 2423 } |
| 2442 | 2424 |
| 2443 void RenderThreadImpl::OnRendererInterfaceRequest( | 2425 void RenderThreadImpl::OnRendererInterfaceRequest( |
| 2444 mojom::RendererAssociatedRequest request) { | 2426 mojom::RendererAssociatedRequest request) { |
| 2445 DCHECK(!renderer_binding_.is_bound()); | 2427 DCHECK(!renderer_binding_.is_bound()); |
| 2446 renderer_binding_.Bind(std::move(request)); | 2428 renderer_binding_.Bind(std::move(request)); |
| 2447 } | 2429 } |
| 2448 | 2430 |
| 2449 } // namespace content | 2431 } // namespace content |
| OLD | NEW |