| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/tools/crash_service/crash_service.h" | 5 #include "chrome/tools/crash_service/crash_service.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <tchar.h> | 9 #include <tchar.h> |
| 10 | 10 |
| 11 #include "base/at_exit.h" | 11 #include "base/at_exit.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const wchar_t kStandardLogFile[] = L"operation_log.txt"; | 18 const wchar_t kStandardLogFile[] = L"operation_log.txt"; |
| 19 | 19 |
| 20 bool GetCrashServiceDirectory(std::wstring* dir) { | 20 bool GetCrashServiceDirectory(FilePath* dir) { |
| 21 std::wstring temp_dir; | 21 FilePath temp_dir; |
| 22 if (!file_util::GetTempDir(&temp_dir)) | 22 if (!file_util::GetTempDir(&temp_dir)) |
| 23 return false; | 23 return false; |
| 24 file_util::AppendToPath(&temp_dir, L"chrome_crashes"); | 24 temp_dir = temp_dir.Append(L"chrome_crashes"); |
| 25 if (!file_util::PathExists(temp_dir)) { | 25 if (!file_util::PathExists(temp_dir)) { |
| 26 if (!file_util::CreateDirectory(temp_dir)) | 26 if (!file_util::CreateDirectory(temp_dir)) |
| 27 return false; | 27 return false; |
| 28 } | 28 } |
| 29 *dir = temp_dir; | 29 *dir = temp_dir; |
| 30 return true; | 30 return true; |
| 31 } | 31 } |
| 32 | 32 |
| 33 } // namespace. | 33 } // namespace. |
| 34 | 34 |
| 35 int __stdcall wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd_line, | 35 int __stdcall wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd_line, |
| 36 int show_mode) { | 36 int show_mode) { |
| 37 // Manages the destruction of singletons. | 37 // Manages the destruction of singletons. |
| 38 base::AtExitManager exit_manager; | 38 base::AtExitManager exit_manager; |
| 39 | 39 |
| 40 CommandLine::Init(0, NULL); | 40 CommandLine::Init(0, NULL); |
| 41 | 41 |
| 42 // We use/create a directory under the user's temp folder, for logging. | 42 // We use/create a directory under the user's temp folder, for logging. |
| 43 std::wstring operating_dir; | 43 FilePath operating_dir; |
| 44 GetCrashServiceDirectory(&operating_dir); | 44 GetCrashServiceDirectory(&operating_dir); |
| 45 std::wstring log_file(operating_dir); | 45 FilePath log_file = operating_dir.Append(kStandardLogFile); |
| 46 file_util::AppendToPath(&log_file, kStandardLogFile); | |
| 47 | 46 |
| 48 // Logging to a file with pid, tid and timestamp. | 47 // Logging to a file with pid, tid and timestamp. |
| 49 logging::InitLogging(log_file.c_str(), logging::LOG_ONLY_TO_FILE, | 48 logging::InitLogging(log_file.value().c_str(), logging::LOG_ONLY_TO_FILE, |
| 50 logging::LOCK_LOG_FILE, logging::APPEND_TO_OLD_LOG_FILE); | 49 logging::LOCK_LOG_FILE, logging::APPEND_TO_OLD_LOG_FILE); |
| 51 logging::SetLogItems(true, true, true, false); | 50 logging::SetLogItems(true, true, true, false); |
| 52 | 51 |
| 53 LOG(INFO) << "session start. cmdline is [" << cmd_line << "]"; | 52 LOG(INFO) << "session start. cmdline is [" << cmd_line << "]"; |
| 54 | 53 |
| 55 CrashService crash_service(operating_dir); | 54 CrashService crash_service(operating_dir.ToWStringHack()); |
| 56 if (!crash_service.Initialize(::GetCommandLineW())) | 55 if (!crash_service.Initialize(::GetCommandLineW())) |
| 57 return 1; | 56 return 1; |
| 58 | 57 |
| 59 LOG(INFO) << "ready to process crash requests"; | 58 LOG(INFO) << "ready to process crash requests"; |
| 60 | 59 |
| 61 // Enter the message loop. | 60 // Enter the message loop. |
| 62 int retv = crash_service.ProcessingLoop(); | 61 int retv = crash_service.ProcessingLoop(); |
| 63 // Time to exit. | 62 // Time to exit. |
| 64 LOG(INFO) << "session end. return code is " << retv; | 63 LOG(INFO) << "session end. return code is " << retv; |
| 65 return retv; | 64 return retv; |
| 66 } | 65 } |
| OLD | NEW |