summaryrefslogtreecommitdiffstats
path: root/mojo/shell/standalone/desktop/launcher_process.cc
blob: 58309188ef5b682861ba8237b3298345ac649913 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2013 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 <stdio.h>
#include <string.h>

#include <iostream>

#include "base/base_switches.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/debug/stack_trace.h"
#include "base/files/file_util.h"
#include "base/i18n/icu_util.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/platform_thread.h"
#include "mojo/shell/standalone/context.h"
#include "mojo/shell/switches.h"

namespace mojo {
namespace shell {

int LauncherProcessMain() {
#if !defined(OFFICIAL_BUILD)
  base::debug::EnableInProcessStackDumping();
#endif
  base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
  // http://crbug.com/546644
  command_line->AppendSwitch(switches::kNoSandbox);

  base::PlatformThread::SetName("mojo_runner");

  // We want the Context to outlive the MessageLoop so that pipes are all
  // gracefully closed / error-out before we try to shut the Context down.
  Context shell_context;
  {
    base::MessageLoop message_loop;
    CHECK(base::i18n::InitializeICU());
    shell_context.Init(nullptr);

    message_loop.PostTask(
        FROM_HERE,
        base::Bind(&Context::RunCommandLineApplication,
                    base::Unretained(&shell_context)));

    message_loop.Run();

    // Must be called before |message_loop| is destroyed.
    shell_context.Shutdown();
  }

  return 0;
}

}  // namespace shell
}  // namespace mojo