| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "mojo/shell/runner/init.h" | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include "base/base_switches.h" | |
| 10 #include "base/command_line.h" | |
| 11 #include "base/debug/debugger.h" | |
| 12 #include "base/files/file_path.h" | |
| 13 #include "base/i18n/icu_util.h" | |
| 14 #include "base/logging.h" | |
| 15 #include "base/stl_util.h" | |
| 16 #include "base/strings/string_split.h" | |
| 17 #include "base/strings/stringprintf.h" | |
| 18 #include "base/strings/utf_string_conversions.h" | |
| 19 #include "mojo/shell/runner/common/switches.h" | |
| 20 | |
| 21 #if defined(OS_WIN) | |
| 22 #include <windows.h> | |
| 23 #elif (OS_POSIX) | |
| 24 #include <unistd.h> | |
| 25 #endif | |
| 26 | |
| 27 namespace mojo { | |
| 28 namespace shell { | |
| 29 | |
| 30 void InitializeLogging() { | |
| 31 logging::LoggingSettings settings; | |
| 32 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | |
| 33 logging::InitLogging(settings); | |
| 34 // To view log output with IDs and timestamps use "adb logcat -v threadtime". | |
| 35 logging::SetLogItems(true, // Process ID | |
| 36 true, // Thread ID | |
| 37 true, // Timestamp | |
| 38 true); // Tick count | |
| 39 } | |
| 40 | |
| 41 void WaitForDebuggerIfNecessary() { | |
| 42 const base::CommandLine* command_line = | |
| 43 base::CommandLine::ForCurrentProcess(); | |
| 44 if (command_line->HasSwitch(switches::kWaitForDebugger)) { | |
| 45 std::vector<std::string> apps_to_debug = base::SplitString( | |
| 46 command_line->GetSwitchValueASCII(switches::kWaitForDebugger), ",", | |
| 47 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | |
| 48 std::string app = "launcher"; | |
| 49 if (command_line->HasSwitch(switches::kChildProcess)) { | |
| 50 app = command_line->GetSwitchValuePath(switches::kChildProcess) | |
| 51 .BaseName() | |
| 52 .RemoveExtension() | |
| 53 .MaybeAsASCII(); | |
| 54 } | |
| 55 if (apps_to_debug.empty() || ContainsValue(apps_to_debug, app)) { | |
| 56 #if defined(OS_WIN) | |
| 57 base::string16 appw = base::UTF8ToUTF16(app); | |
| 58 base::string16 message = base::UTF8ToUTF16( | |
| 59 base::StringPrintf("%s - %d", app.c_str(), GetCurrentProcessId())); | |
| 60 MessageBox(NULL, message.c_str(), appw.c_str(), MB_OK | MB_SETFOREGROUND); | |
| 61 #else | |
| 62 LOG(ERROR) << app << " waiting for GDB. pid: " << getpid(); | |
| 63 base::debug::WaitForDebugger(60, true); | |
| 64 #endif | |
| 65 } | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 void CallLibraryEarlyInitialization(base::NativeLibrary app_library) { | |
| 70 // Do whatever warming that the mojo application wants. | |
| 71 typedef void (*LibraryEarlyInitFunction)(const uint8_t*); | |
| 72 LibraryEarlyInitFunction init_function = | |
| 73 reinterpret_cast<LibraryEarlyInitFunction>( | |
| 74 base::GetFunctionPointerFromNativeLibrary(app_library, | |
| 75 "InitializeBase")); | |
| 76 if (init_function) { | |
| 77 // Get the ICU data that we prewarmed in the runner and then pass it to | |
| 78 // the copy of icu in the mojo binary that we're running. | |
| 79 const uint8_t* icu_data = base::i18n::GetRawIcuMemory(); | |
| 80 init_function(icu_data); | |
| 81 } | |
| 82 | |
| 83 // TODO(erg): All chromium binaries load base. We might want to make a | |
| 84 // general system for other people. | |
| 85 } | |
| 86 | |
| 87 } // namespace shell | |
| 88 } // namespace mojo | |
| OLD | NEW |