• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2010 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 <windows.h>
6 #include <stdlib.h>
7 #include <tchar.h>
8 
9 #include "base/at_exit.h"
10 #include "base/command_line.h"
11 #include "base/file_util.h"
12 #include "base/logging.h"
13 #include "base/path_service.h"
14 #include "chrome/common/chrome_constants.h"
15 #include "chrome/common/chrome_paths.h"
16 #include "components/breakpad/tools/crash_service.h"
17 
18 namespace {
19 
20 const wchar_t kStandardLogFile[] = L"operation_log.txt";
21 
GetCrashServiceDirectory(base::FilePath * dir)22 bool GetCrashServiceDirectory(base::FilePath* dir) {
23   base::FilePath temp_dir;
24   if (!base::GetTempDir(&temp_dir))
25     return false;
26   temp_dir = temp_dir.Append(L"chrome_crashes");
27   if (!base::PathExists(temp_dir)) {
28     if (!base::CreateDirectory(temp_dir))
29       return false;
30   }
31   *dir = temp_dir;
32   return true;
33 }
34 
35 }  // namespace.
36 
wWinMain(HINSTANCE instance,HINSTANCE,wchar_t * cmd_line,int show_mode)37 int __stdcall wWinMain(HINSTANCE instance, HINSTANCE, wchar_t* cmd_line,
38                        int show_mode) {
39   // Manages the destruction of singletons.
40   base::AtExitManager exit_manager;
41 
42   CommandLine::Init(0, NULL);
43 
44   chrome::RegisterPathProvider();
45 
46   // We use/create a directory under the user's temp folder, for logging.
47   base::FilePath operating_dir;
48   GetCrashServiceDirectory(&operating_dir);
49   base::FilePath log_file = operating_dir.Append(kStandardLogFile);
50 
51   // Logging to stderr (to help with debugging failures on the
52   // buildbots) and to a file.
53   logging::LoggingSettings settings;
54   settings.logging_dest = logging::LOG_TO_ALL;
55   settings.log_file = log_file.value().c_str();
56   logging::InitLogging(settings);
57   // Logging with pid, tid and timestamp.
58   logging::SetLogItems(true, true, true, false);
59 
60   VLOG(1) << "session start. cmdline is [" << cmd_line << "]";
61 
62   base::FilePath dumps_path;
63   if (!PathService::Get(chrome::DIR_CRASH_DUMPS, &dumps_path)) {
64     LOG(ERROR) << "could not get DIR_CRASH_DUMPS";
65     return 1;
66   }
67 
68   breakpad::CrashService crash_service;
69   if (!crash_service.Initialize(operating_dir, dumps_path))
70     return 1;
71 
72   VLOG(1) << "ready to process crash requests";
73 
74   // Enter the message loop.
75   int retv = crash_service.ProcessingLoop();
76   // Time to exit.
77   VLOG(1) << "session end. return code is " << retv;
78   return retv;
79 }
80