~oxide-developers/oxide/1.2

« back to all changes in this revision

Viewing changes to oxide/browser/oxide_browser_process_main.cc

  • Committer: Chris Coulson
  • Date: 2013-07-23 11:40:24 UTC
  • Revision ID: chris.coulson@canonical.com-20130723114024-p7z00cs9p0s5te6e
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// vim:expandtab:shiftwidth=2:tabstop=2:
 
2
// Copyright (C) 2013 Canonical Ltd.
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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
 
17
 
 
18
#include "oxide_browser_process_main.h"
 
19
 
 
20
#include "base/logging.h"
 
21
#include "content/public/app/content_main_runner.h"
 
22
#include "content/public/browser/browser_main_runner.h"
 
23
 
 
24
#include "common/oxide_content_main_delegate.h"
 
25
 
 
26
#include "oxide_io_thread_delegate.h"
 
27
 
 
28
namespace {
 
29
oxide::ContentMainDelegateFactory* g_main_delegate_factory;
 
30
oxide::BrowserProcessMain* g_process;
 
31
}
 
32
 
 
33
namespace oxide {
 
34
 
 
35
// static
 
36
BrowserProcessMain* BrowserProcessMain::GetInstance() {
 
37
  if (!g_process) {
 
38
    Create();
 
39
  }
 
40
 
 
41
  return g_process;
 
42
}
 
43
 
 
44
// static
 
45
void BrowserProcessMain::Create() {
 
46
  BrowserProcessMain* tmp = new BrowserProcessMain();
 
47
  if (!tmp->Init()) {
 
48
    delete tmp;
 
49
  }
 
50
}
 
51
 
 
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) {
 
56
    return false;
 
57
  }
 
58
 
 
59
  if (main_runner_->Run() != 0) {
 
60
    return false;
 
61
  }
 
62
 
 
63
  return true;
 
64
}
 
65
 
 
66
// static
 
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);
 
71
  if (rv != -1) {
 
72
    return rv;
 
73
  }
 
74
 
 
75
  return g_process->browser_main_runner_->Run();
 
76
}
 
77
 
 
78
// static
 
79
void BrowserProcessMain::ShutdownBrowserProcess() {
 
80
  g_process->browser_main_runner_->Shutdown();
 
81
}
 
82
 
 
83
// static
 
84
void BrowserProcessMain::PreCreateThreads() {
 
85
  g_process->io_thread_delegate_.reset(new IOThreadDelegate());
 
86
}
 
87
 
 
88
// static
 
89
void BrowserProcessMain::InitContentMainDelegateFactory(
 
90
    ContentMainDelegateFactory* factory) {
 
91
  DCHECK(!g_process || g_main_delegate_factory == factory);
 
92
  g_main_delegate_factory = factory;
 
93
}
 
94
 
 
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());
 
100
}
 
101
 
 
102
BrowserProcessMain::~BrowserProcessMain() {
 
103
  main_runner_->Shutdown();
 
104
}
 
105
 
 
106
// static
 
107
IOThreadDelegate* BrowserProcessMain::io_thread_delegate() {
 
108
  return g_process->io_thread_delegate_.get();
 
109
}
 
110
 
 
111
// static
 
112
bool BrowserProcessMain::Exists() {
 
113
  return !!g_process;
 
114
}
 
115
 
 
116
} // namespace oxide