Roll src/third_party/WebKit a05b987:7eb2976 (svn 202510:202511)
[chromium-blink-merge.git] / mojo / runner / init.cc
blob2c7d289894796ff5a3107fb15cb7a4d10feee3c9
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 = base::SplitString(
42 command_line->GetSwitchValueASCII(switches::kWaitForDebugger), ",",
43 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
44 std::string app = "launcher";
45 if (command_line->HasSwitch(switches::kChildProcess)) {
46 app = command_line->GetSwitchValuePath(switches::kChildProcess)
47 .BaseName()
48 .RemoveExtension()
49 .MaybeAsASCII();
51 if (apps_to_debug.empty() || ContainsValue(apps_to_debug, app)) {
52 #if defined(OS_WIN)
53 base::string16 appw = base::UTF8ToUTF16(app);
54 MessageBox(NULL, appw.c_str(), appw.c_str(), MB_OK | MB_SETFOREGROUND);
55 #else
56 LOG(ERROR) << app << " waiting for GDB. pid: " << getpid();
57 base::debug::WaitForDebugger(60, true);
58 #endif
63 } // namespace runner
64 } // namespace mojo