Fix race condition in gyp/ninja builds.
[chromium-blink-merge.git] / android_webview / browser / aw_browser_main_parts.cc
blob29e9003755682f2aa04e2e21031bf2aace38b876
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/browser/aw_browser_main_parts.h"
7 #include "android_webview/browser/aw_browser_context.h"
8 #include "android_webview/browser/aw_result_codes.h"
9 #include "base/android/build_info.h"
10 #include "base/android/memory_pressure_listener_android.h"
11 #include "base/command_line.h"
12 #include "base/files/file_path.h"
13 #include "base/path_service.h"
14 #include "content/public/browser/render_process_host.h"
15 #include "content/public/common/content_client.h"
16 #include "content/public/common/content_switches.h"
17 #include "content/public/common/result_codes.h"
18 #include "content/public/common/url_utils.h"
19 #include "gpu/command_buffer/service/mailbox_synchronizer.h"
20 #include "net/android/network_change_notifier_factory_android.h"
21 #include "net/base/network_change_notifier.h"
22 #include "ui/base/l10n/l10n_util_android.h"
23 #include "ui/base/layout.h"
24 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/base/ui_base_paths.h"
27 namespace android_webview {
29 AwBrowserMainParts::AwBrowserMainParts(AwBrowserContext* browser_context)
30 : browser_context_(browser_context) {
33 AwBrowserMainParts::~AwBrowserMainParts() {
36 void AwBrowserMainParts::PreEarlyInitialization() {
37 net::NetworkChangeNotifier::SetFactory(
38 new net::NetworkChangeNotifierFactoryAndroid());
40 // Android WebView does not use default MessageLoop. It has its own
41 // Android specific MessageLoop. Also see MainMessageLoopRun.
42 DCHECK(!main_message_loop_.get());
43 main_message_loop_.reset(new base::MessageLoopForUI);
44 base::MessageLoopForUI::current()->Start();
47 int AwBrowserMainParts::PreCreateThreads() {
48 ui::ResourceBundle::InitSharedInstanceLocaleOnly(
49 l10n_util::GetDefaultLocale(), NULL);
51 base::FilePath pak_path;
52 PathService::Get(ui::DIR_RESOURCE_PAKS_ANDROID, &pak_path);
54 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath(
55 pak_path.AppendASCII("webviewchromium.pak"),
56 ui::SCALE_FACTOR_NONE);
58 base::android::MemoryPressureListenerAndroid::RegisterSystemCallback(
59 base::android::AttachCurrentThread());
61 return content::RESULT_CODE_NORMAL_EXIT;
64 void AwBrowserMainParts::PreMainMessageLoopRun() {
65 // TODO(boliu): Can't support accelerated 2d canvas and WebGL with ubercomp
66 // yet: crbug.com/352424.
67 if (!gpu::gles2::MailboxSynchronizer::Initialize()) {
68 CommandLine* cl = CommandLine::ForCurrentProcess();
69 cl->AppendSwitch(switches::kDisableAccelerated2dCanvas);
70 cl->AppendSwitch(switches::kDisableExperimentalWebGL);
73 browser_context_->PreMainMessageLoopRun();
74 // This is needed for WebView Classic backwards compatibility
75 // See crbug.com/298495
76 content::SetMaxURLChars(20 * 1024 * 1024);
79 bool AwBrowserMainParts::MainMessageLoopRun(int* result_code) {
80 // Android WebView does not use default MessageLoop. It has its own
81 // Android specific MessageLoop.
82 return true;
85 } // namespace android_webview