aw_main_delegate.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
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.
4
5#include "android_webview/lib/main/aw_main_delegate.h"
6
7#include "android_webview/browser/aw_content_browser_client.h"
8#include "android_webview/lib/aw_browser_dependency_factory_impl.h"
9#include "android_webview/renderer/aw_content_renderer_client.h"
10#include "base/lazy_instance.h"
11#include "base/logging.h"
12#include "base/memory/scoped_ptr.h"
13#include "content/public/browser/browser_main_runner.h"
14
15namespace android_webview {
16
17base::LazyInstance<AwContentBrowserClient>
18    g_webview_content_browser_client = LAZY_INSTANCE_INITIALIZER;
19base::LazyInstance<AwContentRendererClient>
20    g_webview_content_renderer_client = LAZY_INSTANCE_INITIALIZER;
21
22AwMainDelegate::AwMainDelegate() {
23}
24
25AwMainDelegate::~AwMainDelegate() {
26}
27
28bool AwMainDelegate::BasicStartupComplete(int* exit_code) {
29  content::SetContentClient(&content_client_);
30
31  return false;
32}
33
34void AwMainDelegate::PreSandboxStartup() {
35  // TODO(torne): When we have a separate renderer process, we need to handle
36  // being passed open FDs for the resource paks here.
37}
38
39void AwMainDelegate::SandboxInitialized(const std::string& process_type) {
40  // TODO(torne): Adjust linux OOM score here.
41}
42
43int AwMainDelegate::RunProcess(
44    const std::string& process_type,
45    const content::MainFunctionParams& main_function_params) {
46  if (process_type.empty()) {
47    AwBrowserDependencyFactoryImpl::InstallInstance();
48
49    browser_runner_.reset(content::BrowserMainRunner::Create());
50    int exit_code = browser_runner_->Initialize(main_function_params);
51    DCHECK(exit_code < 0);
52
53    // Return 0 so that we do NOT trigger the default behavior. On Android, the
54    // UI message loop is managed by the Java application.
55    return 0;
56  }
57
58  return -1;
59}
60
61void AwMainDelegate::ProcessExiting(const std::string& process_type) {
62  // TODO(torne): Clean up resources when we handle them.
63
64  logging::CloseLogFile();
65}
66
67content::ContentBrowserClient*
68    AwMainDelegate::CreateContentBrowserClient() {
69  return &g_webview_content_browser_client.Get();
70}
71
72content::ContentRendererClient*
73    AwMainDelegate::CreateContentRendererClient() {
74  return &g_webview_content_renderer_client.Get();
75}
76
77}  // namespace android_webview
78