| OLD | NEW |
| 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 // TODO(gunsch): These should be platform/product-dependent. Look into a way |
| 34 // to move these to platform-specific repositories. |
| 35 const int kCriticalMinFreeMemMB = 24; |
| 36 const int kModerateMinFreeMemMB = 48; |
| 37 const int kPollingIntervalMS = 5000; |
| 38 |
| 39 void PlatformPollFreemem(void) { |
| 40 struct sysinfo sys; |
| 41 |
| 42 if (sysinfo(&sys) == -1) { |
| 43 LOG(ERROR) << "platform_poll_freemem(): sysinfo failed"; |
| 44 } else { |
| 45 int free_mem_mb = static_cast<int64_t>(sys.freeram) * |
| 46 sys.mem_unit / (1024 * 1024); |
| 47 |
| 48 if (free_mem_mb <= kModerateMinFreeMemMB) { |
| 49 if (free_mem_mb <= kCriticalMinFreeMemMB) { |
| 50 // Memory is getting really low, we need to do whatever we can to |
| 51 // prevent deadlocks and interfering with other processes. |
| 52 base::MemoryPressureListener::NotifyMemoryPressure( |
| 53 base::MemoryPressureListener::MEMORY_PRESSURE_CRITICAL); |
| 54 } else { |
| 55 // There is enough memory, but it is starting to get low. |
| 56 base::MemoryPressureListener::NotifyMemoryPressure( |
| 57 base::MemoryPressureListener::MEMORY_PRESSURE_MODERATE); |
| 58 } |
| 59 } |
| 60 } |
| 61 |
| 62 // Setup next poll. |
| 63 base::MessageLoopProxy::current()->PostDelayedTask( |
| 64 FROM_HERE, |
| 65 base::Bind(&PlatformPollFreemem), |
| 66 base::TimeDelta::FromMilliseconds(kPollingIntervalMS)); |
| 67 } |
| 68 #endif |
| 69 |
| 30 // Default background color to set for WebViews. WebColor is in ARGB format | 70 // Default background color to set for WebViews. WebColor is in ARGB format |
| 31 // though the comment of WebColor says it is in RGBA. | 71 // though the comment of WebColor says it is in RGBA. |
| 32 const blink::WebColor kColorBlack = 0xFF000000; | 72 const blink::WebColor kColorBlack = 0xFF000000; |
| 33 | 73 |
| 34 } // namespace | 74 } // namespace |
| 35 | 75 |
| 36 CastContentRendererClient::CastContentRendererClient() { | 76 CastContentRendererClient::CastContentRendererClient() { |
| 37 } | 77 } |
| 38 | 78 |
| 39 CastContentRendererClient::~CastContentRendererClient() { | 79 CastContentRendererClient::~CastContentRendererClient() { |
| 40 } | 80 } |
| 41 | 81 |
| 42 void CastContentRendererClient::RenderThreadStarted() { | 82 void CastContentRendererClient::RenderThreadStarted() { |
| 43 #if defined(USE_NSS) | 83 #if defined(USE_NSS) |
| 44 // Note: Copied from chrome_render_process_observer.cc to fix b/8676652. | 84 // Note: Copied from chrome_render_process_observer.cc to fix b/8676652. |
| 45 // | 85 // |
| 46 // On platforms where the system NSS shared libraries are used, | 86 // 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 | 87 // initialize NSS now because it won't be able to load the .so's |
| 48 // after entering the sandbox. | 88 // after entering the sandbox. |
| 49 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 89 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 50 if (!command_line->HasSwitch(switches::kSingleProcess)) | 90 if (!command_line->HasSwitch(switches::kSingleProcess)) |
| 51 crypto::InitNSSSafely(); | 91 crypto::InitNSSSafely(); |
| 52 #endif | 92 #endif |
| 53 | 93 |
| 94 #if defined(ARCH_CPU_ARM_FAMILY) && !defined(OS_ANDROID) |
| 95 PlatformPollFreemem(); |
| 96 #endif |
| 97 |
| 54 cast_observer_.reset(new CastRenderProcessObserver()); | 98 cast_observer_.reset(new CastRenderProcessObserver()); |
| 55 | 99 |
| 56 prescient_networking_dispatcher_.reset( | 100 prescient_networking_dispatcher_.reset( |
| 57 new dns_prefetch::PrescientNetworkingDispatcher()); | 101 new dns_prefetch::PrescientNetworkingDispatcher()); |
| 58 } | 102 } |
| 59 | 103 |
| 60 void CastContentRendererClient::RenderViewCreated( | 104 void CastContentRendererClient::RenderViewCreated( |
| 61 content::RenderView* render_view) { | 105 content::RenderView* render_view) { |
| 62 blink::WebView* webview = render_view->GetWebView(); | 106 blink::WebView* webview = render_view->GetWebView(); |
| 63 if (webview) { | 107 if (webview) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 closure.Run(); | 146 closure.Run(); |
| 103 return; | 147 return; |
| 104 } | 148 } |
| 105 | 149 |
| 106 // Lifetime is tied to |render_frame| via content::RenderFrameObserver. | 150 // Lifetime is tied to |render_frame| via content::RenderFrameObserver. |
| 107 new CastMediaLoadDeferrer(render_frame, closure); | 151 new CastMediaLoadDeferrer(render_frame, closure); |
| 108 } | 152 } |
| 109 | 153 |
| 110 } // namespace shell | 154 } // namespace shell |
| 111 } // namespace chromecast | 155 } // namespace chromecast |
| OLD | NEW |