Chromium Code Reviews

Side by Side Diff: chromecast/renderer/cast_content_renderer_client.cc

Issue 834213002: Chromecast: forcibly trigger GC in low-memory situations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chromecast/renderer/cast_content_renderer_client.h" 5 #include "chromecast/renderer/cast_content_renderer_client.h"
6 6
7 #include <sys/sysinfo.h> 7 #include <sys/sysinfo.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/memory/memory_pressure_listener.h" 10 #include "base/memory/memory_pressure_listener.h"
11 #include "chromecast/common/chromecast_switches.h" 11 #include "chromecast/common/chromecast_switches.h"
12 #include "chromecast/renderer/cast_media_load_deferrer.h" 12 #include "chromecast/renderer/cast_media_load_deferrer.h"
13 #include "chromecast/renderer/cast_render_process_observer.h" 13 #include "chromecast/renderer/cast_render_process_observer.h"
14 #include "chromecast/renderer/key_systems_cast.h" 14 #include "chromecast/renderer/key_systems_cast.h"
15 #include "chromecast/renderer/media/cma_media_renderer_factory.h" 15 #include "chromecast/renderer/media/cma_media_renderer_factory.h"
16 #include "components/dns_prefetch/renderer/prescient_networking_dispatcher.h" 16 #include "components/dns_prefetch/renderer/prescient_networking_dispatcher.h"
17 #include "content/public/common/content_switches.h" 17 #include "content/public/common/content_switches.h"
18 #include "content/public/renderer/render_frame.h" 18 #include "content/public/renderer/render_frame.h"
19 #include "content/public/renderer/render_view.h" 19 #include "content/public/renderer/render_view.h"
20 #include "crypto/nss_util.h" 20 #include "crypto/nss_util.h"
21 #include "third_party/WebKit/public/platform/WebColor.h" 21 #include "third_party/WebKit/public/platform/WebColor.h"
22 #include "third_party/WebKit/public/web/WebSettings.h" 22 #include "third_party/WebKit/public/web/WebSettings.h"
23 #include "third_party/WebKit/public/web/WebView.h" 23 #include "third_party/WebKit/public/web/WebView.h"
24 24
25 namespace chromecast { 25 namespace chromecast {
26 namespace shell { 26 namespace shell {
27 27
28 namespace { 28 namespace {
29 29
30 #if defined(ARCH_CPU_ARM_FAMILY) && !defined(OS_ANDROID)
31 // These memory thresholds are set for Chromecast. See the UMA histogram
32 // Platform.MeminfoMemFree when tuning.
33 const int kCriticalMinFreeMemMB = 24;
34 const int kModerateMinFreeMemMB = 48;
35 const int kPollingIntervalMS = 5000;
lcwu1 2015/01/08 18:52:12 These numbers should be platform/product dependent
gunsch 2015/01/08 19:02:08 Done.
36
37 void PlatformPollFreemem(void) {
38 struct sysinfo sys;
39
40 if (sysinfo(&sys) == -1) {
41 LOG(ERROR) << "platform_poll_freemem(): sysinfo failed";
42 } else {
43 int free_mem_mb = static_cast<int64_t>(sys.freeram) *
44 sys.mem_unit / (1024 * 1024);
45
46 if (free_mem_mb <= kModerateMinFreeMemMB) {
47 if (free_mem_mb <= kCriticalMinFreeMemMB) {
48 // Memory is getting really low, we need to do whatever we can to
49 // prevent deadlocks and interfering with other processes.
50 base::MemoryPressureListener::NotifyMemoryPressure(
51 base::MemoryPressureListener::MEMORY_PRESSURE_CRITICAL);
52 } else {
53 // There is enough memory, but it is starting to get low.
54 base::MemoryPressureListener::NotifyMemoryPressure(
55 base::MemoryPressureListener::MEMORY_PRESSURE_MODERATE);
56 }
57 }
58 }
59
60 // Setup next poll.
61 base::MessageLoopProxy::current()->PostDelayedTask(
62 FROM_HERE,
63 base::Bind(&PlatformPollFreemem),
64 base::TimeDelta::FromMilliseconds(kPollingIntervalMS));
65 }
66 #endif
67
30 // Default background color to set for WebViews. WebColor is in ARGB format 68 // Default background color to set for WebViews. WebColor is in ARGB format
31 // though the comment of WebColor says it is in RGBA. 69 // though the comment of WebColor says it is in RGBA.
32 const blink::WebColor kColorBlack = 0xFF000000; 70 const blink::WebColor kColorBlack = 0xFF000000;
33 71
34 } // namespace 72 } // namespace
35 73
36 CastContentRendererClient::CastContentRendererClient() { 74 CastContentRendererClient::CastContentRendererClient() {
37 } 75 }
38 76
39 CastContentRendererClient::~CastContentRendererClient() { 77 CastContentRendererClient::~CastContentRendererClient() {
40 } 78 }
41 79
42 void CastContentRendererClient::RenderThreadStarted() { 80 void CastContentRendererClient::RenderThreadStarted() {
43 #if defined(USE_NSS) 81 #if defined(USE_NSS)
44 // Note: Copied from chrome_render_process_observer.cc to fix b/8676652. 82 // Note: Copied from chrome_render_process_observer.cc to fix b/8676652.
45 // 83 //
46 // On platforms where the system NSS shared libraries are used, 84 // On platforms where the system NSS shared libraries are used,
47 // initialize NSS now because it won't be able to load the .so's 85 // initialize NSS now because it won't be able to load the .so's
48 // after entering the sandbox. 86 // after entering the sandbox.
49 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 87 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
50 if (!command_line->HasSwitch(switches::kSingleProcess)) 88 if (!command_line->HasSwitch(switches::kSingleProcess))
51 crypto::InitNSSSafely(); 89 crypto::InitNSSSafely();
52 #endif 90 #endif
53 91
92 #if defined(ARCH_CPU_ARM_FAMILY) && !defined(OS_ANDROID)
93 PlatformPollFreemem();
94 #endif
95
54 cast_observer_.reset(new CastRenderProcessObserver()); 96 cast_observer_.reset(new CastRenderProcessObserver());
55 97
56 prescient_networking_dispatcher_.reset( 98 prescient_networking_dispatcher_.reset(
57 new dns_prefetch::PrescientNetworkingDispatcher()); 99 new dns_prefetch::PrescientNetworkingDispatcher());
58 } 100 }
59 101
60 void CastContentRendererClient::RenderViewCreated( 102 void CastContentRendererClient::RenderViewCreated(
61 content::RenderView* render_view) { 103 content::RenderView* render_view) {
62 blink::WebView* webview = render_view->GetWebView(); 104 blink::WebView* webview = render_view->GetWebView();
63 if (webview) { 105 if (webview) {
(...skipping 38 matching lines...)
102 closure.Run(); 144 closure.Run();
103 return; 145 return;
104 } 146 }
105 147
106 // Lifetime is tied to |render_frame| via content::RenderFrameObserver. 148 // Lifetime is tied to |render_frame| via content::RenderFrameObserver.
107 new CastMediaLoadDeferrer(render_frame, closure); 149 new CastMediaLoadDeferrer(render_frame, closure);
108 } 150 }
109 151
110 } // namespace shell 152 } // namespace shell
111 } // namespace chromecast 153 } // namespace chromecast
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine