| 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 "services/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 "services/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 shell { | |
| 28 | |
| 29 void InitializeLogging() { | |
| 30 logging::LoggingSettings settings; | |
| 31 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | |
| 32 logging::InitLogging(settings); | |
| 33 // To view log output with IDs and timestamps use "adb logcat -v threadtime". | |
| 34 logging::SetLogItems(true, // Process ID | |
| 35 true, // Thread ID | |
| 36 true, // Timestamp | |
| 37 true); // Tick count | |
| 38 } | |
| 39 | |
| 40 void WaitForDebuggerIfNecessary() { | |
| 41 const base::CommandLine* command_line = | |
| 42 base::CommandLine::ForCurrentProcess(); | |
| 43 if (command_line->HasSwitch(switches::kWaitForDebugger)) { | |
| 44 std::vector<std::string> apps_to_debug = base::SplitString( | |
| 45 command_line->GetSwitchValueASCII(switches::kWaitForDebugger), ",", | |
| 46 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | |
| 47 std::string app = "launcher"; | |
| 48 if (command_line->HasSwitch(switches::kChildProcess)) { | |
| 49 app = command_line->GetSwitchValuePath(switches::kChildProcess) | |
| 50 .BaseName() | |
| 51 .RemoveExtension() | |
| 52 .MaybeAsASCII(); | |
| 53 } else { | |
| 54 base::FilePath exe_path = | |
| 55 command_line->GetProgram().BaseName().RemoveExtension(); | |
| 56 for (const auto& app_name : apps_to_debug) { | |
| 57 if (base::FilePath().AppendASCII(app_name) == exe_path) { | |
| 58 app = app_name; | |
| 59 break; | |
| 60 } | |
| 61 } | |
| 62 } | |
| 63 if (apps_to_debug.empty() || base::ContainsValue(apps_to_debug, app)) { | |
| 64 #if defined(OS_WIN) | |
| 65 base::string16 appw = base::UTF8ToUTF16(app); | |
| 66 base::string16 message = base::UTF8ToUTF16( | |
| 67 base::StringPrintf("%s - %d", app.c_str(), GetCurrentProcessId())); | |
| 68 MessageBox(NULL, message.c_str(), appw.c_str(), MB_OK | MB_SETFOREGROUND); | |
| 69 #else | |
| 70 LOG(ERROR) << app << " waiting for GDB. pid: " << getpid(); | |
| 71 base::debug::WaitForDebugger(60, true); | |
| 72 #endif | |
| 73 } | |
| 74 } | |
| 75 } | |
| 76 | |
| 77 void CallLibraryEarlyInitialization(base::NativeLibrary app_library) { | |
| 78 // Do whatever warming that the service wants. | |
| 79 | |
| 80 #if ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE | |
| 81 typedef void (*LibraryEarlyInitFunction)(const uint8_t*); | |
| 82 LibraryEarlyInitFunction init_function = | |
| 83 reinterpret_cast<LibraryEarlyInitFunction>( | |
| 84 base::GetFunctionPointerFromNativeLibrary(app_library, | |
| 85 "InitializeBase")); | |
| 86 CHECK(init_function); | |
| 87 // Get the ICU data that we prewarmed in the runner and then pass it to | |
| 88 // the copy of icu in the mojo binary that we're running. | |
| 89 const uint8_t* icu_data = base::i18n::GetRawIcuMemory(); | |
| 90 init_function(icu_data); | |
| 91 #endif // ICU_UTIL_DATA_IMPL == ICU_UTIL_DATA_FILE | |
| 92 | |
| 93 // TODO(erg): All chromium binaries load base. We might want to make a | |
| 94 // general system for other people. | |
| 95 } | |
| 96 | |
| 97 } // namespace shell | |
| OLD | NEW |