1
// vim:expandtab:shiftwidth=2:tabstop=2:
2
// Copyright (C) 2013 Canonical Ltd.
4
// This library is free software; you can redistribute it and/or
5
// modify it under the terms of the GNU Lesser General Public
6
// License as published by the Free Software Foundation; either
7
// version 2.1 of the License, or (at your option) any later version.
9
// This library is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
// Lesser General Public License for more details.
14
// You should have received a copy of the GNU Lesser General Public
15
// License along with this library; if not, write to the Free Software
16
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
#include "oxide_browser_process_main.h"
20
#include "base/logging.h"
21
#include "content/public/app/content_main_runner.h"
22
#include "content/public/browser/browser_main_runner.h"
24
#include "common/oxide_content_main_delegate.h"
26
#include "oxide_io_thread_delegate.h"
29
oxide::ContentMainDelegateFactory* g_main_delegate_factory;
30
oxide::BrowserProcessMain* g_process;
36
BrowserProcessMain* BrowserProcessMain::GetInstance() {
45
void BrowserProcessMain::Create() {
46
BrowserProcessMain* tmp = new BrowserProcessMain();
52
bool BrowserProcessMain::Init() {
53
// XXX: Normally this comes from main() and takes some arguments.
54
// Should we pass any default args here?
55
if (main_runner_->Initialize(0, NULL, main_delegate_.get()) != -1) {
59
if (main_runner_->Run() != 0) {
67
int BrowserProcessMain::RunBrowserProcess(
68
const content::MainFunctionParams& main_function_params) {
69
g_process->browser_main_runner_.reset(content::BrowserMainRunner::Create());
70
int rv = g_process->browser_main_runner_->Initialize(main_function_params);
75
return g_process->browser_main_runner_->Run();
79
void BrowserProcessMain::ShutdownBrowserProcess() {
80
g_process->browser_main_runner_->Shutdown();
84
void BrowserProcessMain::PreCreateThreads() {
85
g_process->io_thread_delegate_.reset(new IOThreadDelegate());
89
void BrowserProcessMain::InitContentMainDelegateFactory(
90
ContentMainDelegateFactory* factory) {
91
DCHECK(!g_process || g_main_delegate_factory == factory);
92
g_main_delegate_factory = factory;
95
BrowserProcessMain::BrowserProcessMain() {
96
DCHECK(g_main_delegate_factory) <<
97
"Implementation needs to specify a ContentMainDelegate factory";
98
main_delegate_.reset(g_main_delegate_factory());
99
main_runner_.reset(content::ContentMainRunner::Create());
102
BrowserProcessMain::~BrowserProcessMain() {
103
main_runner_->Shutdown();
107
IOThreadDelegate* BrowserProcessMain::io_thread_delegate() {
108
return g_process->io_thread_delegate_.get();
112
bool BrowserProcessMain::Exists() {