mandoline: Enable the sandbox on clipboard and tracing.
[chromium-blink-merge.git] / mojo / runner / init.cc
blob17d5c1b46b0392ac6b58d6c1676ddc764494521e
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mojo/runner/init.h"
7 #include "base/base_switches.h"
8 #include "base/command_line.h"
9 #include "base/debug/debugger.h"
10 #include "base/files/file_path.h"
11 #include "base/logging.h"
12 #include "base/stl_util.h"
13 #include "base/strings/string_split.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "mojo/runner/switches.h"
17 #if defined(OS_WIN)
18 #include <windows.h>
19 #elif (OS_POSIX)
20 #include <unistd.h>
21 #endif
23 namespace mojo {
24 namespace runner {
26 void InitializeLogging() {
27 logging::LoggingSettings settings;
28 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
29 logging::InitLogging(settings);
30 // To view log output with IDs and timestamps use "adb logcat -v threadtime".
31 logging::SetLogItems(false, // Process ID
32 false, // Thread ID
33 false, // Timestamp
34 false); // Tick count
37 void WaitForDebuggerIfNecessary() {
38 const base::CommandLine* command_line =
39 base::CommandLine::ForCurrentProcess();
40 if (command_line->HasSwitch(switches::kWaitForDebugger)) {
41 std::vector<std::string> apps_to_debug;
42 base::SplitString(
43 command_line->GetSwitchValueASCII(switches::kWaitForDebugger), ',',
44 &apps_to_debug);
45 std::string app = "launcher";
46 if (command_line->HasSwitch(switches::kChildProcess)) {
47 app = command_line->GetSwitchValuePath(switches::kChildProcess)
48 .BaseName()
49 .RemoveExtension()
50 .MaybeAsASCII();
52 if (apps_to_debug.empty() || ContainsValue(apps_to_debug, app)) {
53 #if defined(OS_WIN)
54 base::string16 appw = base::UTF8ToUTF16(app);
55 MessageBox(NULL, appw.c_str(), appw.c_str(), MB_OK | MB_SETFOREGROUND);
56 #else
57 LOG(ERROR) << app << " waiting for GDB. pid: " << getpid();
58 base::debug::WaitForDebugger(60, true);
59 #endif
64 } // namespace runner
65 } // namespace mojo