Add long running gmail memory benchmark for background tab.
[chromium-blink-merge.git] / android_webview / lib / main / aw_main_delegate.cc
blobf94d49882278a31fa284d475f7bd9dfc664198be
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
3 // found in the LICENSE file.
5 #include "android_webview/lib/main/aw_main_delegate.h"
7 #include "android_webview/browser/aw_content_browser_client.h"
8 #include "android_webview/browser/browser_view_renderer.h"
9 #include "android_webview/browser/scoped_allow_wait_for_legacy_web_view_api.h"
10 #include "android_webview/common/aw_switches.h"
11 #include "android_webview/crash_reporter/aw_microdump_crash_reporter.h"
12 #include "android_webview/lib/aw_browser_dependency_factory_impl.h"
13 #include "android_webview/native/aw_media_url_interceptor.h"
14 #include "android_webview/native/aw_message_port_service_impl.h"
15 #include "android_webview/native/aw_quota_manager_bridge_impl.h"
16 #include "android_webview/native/aw_web_contents_view_delegate.h"
17 #include "android_webview/native/aw_web_preferences_populater_impl.h"
18 #include "android_webview/renderer/aw_content_renderer_client.h"
19 #include "base/android/apk_assets.h"
20 #include "base/command_line.h"
21 #include "base/cpu.h"
22 #include "base/i18n/icu_util.h"
23 #include "base/lazy_instance.h"
24 #include "base/logging.h"
25 #include "base/memory/scoped_ptr.h"
26 #include "base/threading/thread_restrictions.h"
27 #include "cc/base/switches.h"
28 #include "components/external_video_surface/browser/android/external_video_surface_container_impl.h"
29 #include "content/public/browser/android/browser_media_player_manager_register.h"
30 #include "content/public/browser/browser_main_runner.h"
31 #include "content/public/browser/browser_thread.h"
32 #include "content/public/common/content_descriptors.h"
33 #include "content/public/common/content_switches.h"
34 #include "gin/public/isolate_holder.h"
35 #include "gpu/command_buffer/client/gl_in_process_context.h"
36 #include "gpu/command_buffer/service/gpu_switches.h"
37 #include "media/base/media_switches.h"
39 namespace android_webview {
41 namespace {
43 // TODO(boliu): Remove this global Allow once the underlying issues are
44 // resolved - http://crbug.com/240453. See AwMainDelegate::RunProcess below.
45 base::LazyInstance<scoped_ptr<ScopedAllowWaitForLegacyWebViewApi> >
46 g_allow_wait_in_ui_thread = LAZY_INSTANCE_INITIALIZER;
50 AwMainDelegate::AwMainDelegate() {
53 AwMainDelegate::~AwMainDelegate() {
56 bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
57 content::SetContentClient(&content_client_);
59 content::RegisterMediaUrlInterceptor(new AwMediaUrlInterceptor());
61 BrowserViewRenderer::CalculateTileMemoryPolicy();
63 base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
64 cl->AppendSwitch(switches::kUseIpcCommandBuffer);
65 cl->AppendSwitch(cc::switches::kEnableBeginFrameScheduling);
67 // WebView uses the Android system's scrollbars and overscroll glow.
68 cl->AppendSwitch(switches::kDisableOverscrollEdgeEffect);
70 // Pull-to-refresh should never be a default WebView action.
71 cl->AppendSwitch(switches::kDisablePullToRefreshEffect);
73 // Not yet supported in single-process mode.
74 cl->AppendSwitch(switches::kDisableSharedWorkers);
76 // File system API not supported (requires some new API; internal bug 6930981)
77 cl->AppendSwitch(switches::kDisableFileSystem);
79 // Web Notification API and the Push API are not supported (crbug.com/434712)
80 cl->AppendSwitch(switches::kDisableNotifications);
82 // WebRTC hardware decoding is not supported, internal bug 15075307
83 cl->AppendSwitch(switches::kDisableWebRtcHWDecoding);
84 cl->AppendSwitch(switches::kDisableAcceleratedVideoDecode);
86 // This is needed for sharing textures across the different GL threads.
87 cl->AppendSwitch(switches::kEnableThreadedTextureMailboxes);
89 // WebView does not yet support screen orientation locking.
90 cl->AppendSwitch(switches::kDisableScreenOrientationLock);
92 // WebView does not currently support Web Speech API (crbug.com/487255)
93 cl->AppendSwitch(switches::kDisableSpeechAPI);
95 // WebView does not currently support the Permissions API (crbug.com/490120)
96 cl->AppendSwitch(switches::kDisablePermissionsAPI);
98 // WebView does not (yet) save Chromium data during shutdown, so add setting
99 // for Chrome to aggressively persist DOM Storage to minimize data loss.
100 // http://crbug.com/479767
101 cl->AppendSwitch(switches::kEnableAggressiveDOMStorageFlushing);
103 // This is needed to be able to mmap the V8 snapshot and ICU data file
104 // directly from the WebView .apk.
105 // This needs to be here so that it gets to run before the code in
106 // content_main_runner that reads these values tries to do so.
107 // In multi-process mode this code would live in
108 // AwContentBrowserClient::GetAdditionalMappedFilesForChildProcess.
109 #ifdef __LP64__
110 const char kNativesFileName[] = "assets/natives_blob_64.bin";
111 const char kSnapshotFileName[] = "assets/snapshot_blob_64.bin";
112 #else
113 const char kNativesFileName[] = "assets/natives_blob_32.bin";
114 const char kSnapshotFileName[] = "assets/snapshot_blob_32.bin";
115 #endif // __LP64__
116 // TODO(gsennton) we should use
117 // gin::IsolateHolder::kNativesFileName/kSnapshotFileName
118 // here when those files have arch specific names http://crbug.com/455699
119 CHECK(base::android::RegisterApkAssetWithGlobalDescriptors(
120 kV8NativesDataDescriptor, kNativesFileName));
121 CHECK(base::android::RegisterApkAssetWithGlobalDescriptors(
122 kV8SnapshotDataDescriptor, kSnapshotFileName));
123 CHECK(base::android::RegisterApkAssetWithGlobalDescriptors(
124 kAndroidICUDataDescriptor, "assets/icudtl.dat"));
126 return false;
129 void AwMainDelegate::PreSandboxStartup() {
130 // TODO(torne): When we have a separate renderer process, we need to handle
131 // being passed open FDs for the resource paks here.
132 #if defined(ARCH_CPU_ARM_FAMILY)
133 // Create an instance of the CPU class to parse /proc/cpuinfo and cache
134 // cpu_brand info.
135 base::CPU cpu_info;
136 #endif
138 crash_reporter::EnableMicrodumpCrashReporter();
141 void AwMainDelegate::SandboxInitialized(const std::string& process_type) {
142 // TODO(torne): Adjust linux OOM score here.
145 int AwMainDelegate::RunProcess(
146 const std::string& process_type,
147 const content::MainFunctionParams& main_function_params) {
148 if (process_type.empty()) {
149 AwBrowserDependencyFactoryImpl::InstallInstance();
151 browser_runner_.reset(content::BrowserMainRunner::Create());
152 int exit_code = browser_runner_->Initialize(main_function_params);
153 DCHECK_LT(exit_code, 0);
155 g_allow_wait_in_ui_thread.Get().reset(
156 new ScopedAllowWaitForLegacyWebViewApi);
158 // Return 0 so that we do NOT trigger the default behavior. On Android, the
159 // UI message loop is managed by the Java application.
160 return 0;
163 return -1;
166 void AwMainDelegate::ProcessExiting(const std::string& process_type) {
167 // TODO(torne): Clean up resources when we handle them.
169 logging::CloseLogFile();
172 content::ContentBrowserClient*
173 AwMainDelegate::CreateContentBrowserClient() {
174 content_browser_client_.reset(new AwContentBrowserClient(this));
175 return content_browser_client_.get();
178 content::ContentRendererClient*
179 AwMainDelegate::CreateContentRendererClient() {
180 content_renderer_client_.reset(new AwContentRendererClient());
181 return content_renderer_client_.get();
184 scoped_refptr<AwQuotaManagerBridge> AwMainDelegate::CreateAwQuotaManagerBridge(
185 AwBrowserContext* browser_context) {
186 return AwQuotaManagerBridgeImpl::Create(browser_context);
189 content::WebContentsViewDelegate* AwMainDelegate::CreateViewDelegate(
190 content::WebContents* web_contents) {
191 return AwWebContentsViewDelegate::Create(web_contents);
194 AwWebPreferencesPopulater* AwMainDelegate::CreateWebPreferencesPopulater() {
195 return new AwWebPreferencesPopulaterImpl();
198 AwMessagePortService* AwMainDelegate::CreateAwMessagePortService() {
199 return new AwMessagePortServiceImpl();
202 #if defined(VIDEO_HOLE)
203 content::ExternalVideoSurfaceContainer*
204 AwMainDelegate::CreateExternalVideoSurfaceContainer(
205 content::WebContents* web_contents) {
206 return external_video_surface::ExternalVideoSurfaceContainerImpl::Create(
207 web_contents);
209 #endif
211 } // namespace android_webview