summaryrefslogtreecommitdiffstats
path: root/mandoline/app/desktop/launcher_process.cc
blob: 5a94a3200c8ee29d9ae4bb3f26d065fac83e54ff (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
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2015 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 <algorithm>
#include <iostream>

#include "base/base_switches.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/files/file_util.h"
#include "base/message_loop/message_loop.h"
#include "base/path_service.h"
#include "base/synchronization/waitable_event.h"
#include "base/trace_event/trace_event.h"
#include "components/tracing/trace_config_file.h"
#include "components/tracing/tracing_switches.h"
#include "mandoline/app/desktop/launcher_process.h"
#include "mojo/runner/context.h"
#include "mojo/runner/switches.h"
#include "mojo/shell/switches.h"

namespace mandoline {

int LauncherProcessMain(int argc, char** argv) {
  mojo::runner::Tracer tracer;
  base::CommandLine* command_line =
      base::CommandLine::ForCurrentProcess();
  if (!command_line->HasSwitch(switches::kMojoSingleProcess))
    command_line->AppendSwitch(switches::kEnableMultiprocess);
  command_line->AppendSwitch("use-new-edk");
  // http://crbug.com/546644
  command_line->AppendSwitch(switches::kMojoNoSandbox);

  bool trace_startup = command_line->HasSwitch(switches::kTraceStartup);
  if (trace_startup) {
    tracer.Start(
        command_line->GetSwitchValueASCII(switches::kTraceStartup),
        command_line->GetSwitchValueASCII(switches::kTraceStartupDuration),
        "mandoline.trace");
  }

  // We want the runner::Context to outlive the MessageLoop so that pipes are
  // all gracefully closed / error-out before we try to shut the Context down.
  mojo::runner::Context shell_context;
  {
    base::MessageLoop message_loop;
    base::FilePath shell_dir;
    PathService::Get(base::DIR_MODULE, &shell_dir);
    if (!shell_context.Init(shell_dir)) {
      return 0;
    }

    message_loop.PostTask(FROM_HERE,
                          base::Bind(&mojo::runner::Context::Run,
                                     base::Unretained(&shell_context),
                                     GURL("mojo:desktop_ui")));
    message_loop.Run();

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

  return 0;
}

}  // namespace mandoline