summaryrefslogtreecommitdiffstats
path: root/mojo/shell/background/background_shell_main.cc
blob: 72c082f483a034d346190579077e3d70720cb848 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "mojo/shell/background/background_shell_main.h"

#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/debug/debugger.h"
#include "base/process/launch.h"
#include "mojo/shell/runner/common/switches.h"
#include "mojo/shell/runner/host/child_process.h"
#include "mojo/shell/runner/init.h"

namespace mojo {
namespace shell {
namespace {

int RunChildProcess() {
  base::AtExitManager at_exit;
  InitializeLogging();
  WaitForDebuggerIfNecessary();
#if !defined(OFFICIAL_BUILD) && defined(OS_WIN)
  base::RouteStdioToConsole(false);
#endif
  return ChildProcessMain();
}

}  // namespace
}  // shell
}  // mojo

int main(int argc, char** argv) {
  base::CommandLine::Init(argc, argv);
  if (base::CommandLine::ForCurrentProcess()->HasSwitch(
          switches::kChildProcess)) {
    return mojo::shell::RunChildProcess();
  }
  // Reset CommandLine as most likely main() is going to use CommandLine too
  // and expect to be able to initialize it.
  base::CommandLine::Reset();
  return MasterProcessMain(argc, argv);
}