| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_CRASH_HANDLER_HOST_LINUXISH_H_ | |
| 6 #define CHROME_BROWSER_CRASH_HANDLER_HOST_LINUXISH_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "base/compiler_specific.h" | |
| 10 #include "base/message_loop.h" | |
| 11 | |
| 12 #if defined(USE_LINUX_BREAKPAD) | |
| 13 #include <sys/types.h> | |
| 14 | |
| 15 #include <string> | |
| 16 | |
| 17 #include "base/memory/scoped_ptr.h" | |
| 18 | |
| 19 struct BreakpadInfo; | |
| 20 | |
| 21 namespace base { | |
| 22 class Thread; | |
| 23 } | |
| 24 #endif // defined(USE_LINUX_BREAKPAD) | |
| 25 | |
| 26 template <typename T> struct DefaultSingletonTraits; | |
| 27 | |
| 28 // This is the base class for singleton objects which crash dump renderers and | |
| 29 // plugins on Linux or Android. We perform the crash dump from the browser | |
| 30 // because it allows us to be outside the sandbox. | |
| 31 // | |
| 32 // PluginCrashHandlerHostLinux and RendererCrashHandlerHostLinux are | |
| 33 // singletons that handle plugin and renderer crashes, respectively. | |
| 34 // | |
| 35 // Processes signal that they need to be dumped by sending a datagram over a | |
| 36 // UNIX domain socket. All processes of the same type share the client end of | |
| 37 // this socket which is installed in their descriptor table before exec. | |
| 38 class CrashHandlerHostLinux : public MessageLoopForIO::Watcher, | |
| 39 public MessageLoop::DestructionObserver { | |
| 40 public: | |
| 41 // Get the file descriptor which processes should be given in order to signal | |
| 42 // crashes to the browser. | |
| 43 int GetDeathSignalSocket() const { | |
| 44 return process_socket_; | |
| 45 } | |
| 46 | |
| 47 // MessagePumbLibevent::Watcher impl: | |
| 48 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; | |
| 49 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; | |
| 50 | |
| 51 // MessageLoop::DestructionObserver impl: | |
| 52 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; | |
| 53 | |
| 54 #if defined(USE_LINUX_BREAKPAD) | |
| 55 // Whether we are shutting down or not. | |
| 56 bool IsShuttingDown() const; | |
| 57 #endif | |
| 58 | |
| 59 protected: | |
| 60 CrashHandlerHostLinux(); | |
| 61 virtual ~CrashHandlerHostLinux(); | |
| 62 | |
| 63 #if defined(USE_LINUX_BREAKPAD) | |
| 64 // Only called in concrete subclasses. | |
| 65 void InitCrashUploaderThread(); | |
| 66 | |
| 67 std::string process_type_; | |
| 68 #endif | |
| 69 | |
| 70 private: | |
| 71 void Init(); | |
| 72 | |
| 73 #if defined(USE_LINUX_BREAKPAD) | |
| 74 // This is here on purpose to make CrashHandlerHostLinux abstract. | |
| 75 virtual void SetProcessType() = 0; | |
| 76 | |
| 77 // Do work on the FILE thread for OnFileCanReadWithoutBlocking(). | |
| 78 void WriteDumpFile(BreakpadInfo* info, | |
| 79 pid_t crashing_pid, | |
| 80 char* crash_context, | |
| 81 int signal_fd); | |
| 82 | |
| 83 // Continue OnFileCanReadWithoutBlocking()'s work on the IO thread. | |
| 84 void QueueCrashDumpTask(BreakpadInfo* info, int signal_fd); | |
| 85 #endif | |
| 86 | |
| 87 int process_socket_; | |
| 88 int browser_socket_; | |
| 89 | |
| 90 #if defined(USE_LINUX_BREAKPAD) | |
| 91 MessageLoopForIO::FileDescriptorWatcher file_descriptor_watcher_; | |
| 92 scoped_ptr<base::Thread> uploader_thread_; | |
| 93 bool shutting_down_; | |
| 94 #endif | |
| 95 | |
| 96 DISALLOW_COPY_AND_ASSIGN(CrashHandlerHostLinux); | |
| 97 }; | |
| 98 | |
| 99 class ExtensionCrashHandlerHostLinux : public CrashHandlerHostLinux { | |
| 100 public: | |
| 101 // Returns the singleton instance. | |
| 102 static ExtensionCrashHandlerHostLinux* GetInstance(); | |
| 103 | |
| 104 private: | |
| 105 friend struct DefaultSingletonTraits<ExtensionCrashHandlerHostLinux>; | |
| 106 ExtensionCrashHandlerHostLinux(); | |
| 107 virtual ~ExtensionCrashHandlerHostLinux(); | |
| 108 | |
| 109 #if defined(USE_LINUX_BREAKPAD) | |
| 110 virtual void SetProcessType() OVERRIDE; | |
| 111 #endif | |
| 112 | |
| 113 DISALLOW_COPY_AND_ASSIGN(ExtensionCrashHandlerHostLinux); | |
| 114 }; | |
| 115 | |
| 116 class GpuCrashHandlerHostLinux : public CrashHandlerHostLinux { | |
| 117 public: | |
| 118 // Returns the singleton instance. | |
| 119 static GpuCrashHandlerHostLinux* GetInstance(); | |
| 120 | |
| 121 private: | |
| 122 friend struct DefaultSingletonTraits<GpuCrashHandlerHostLinux>; | |
| 123 GpuCrashHandlerHostLinux(); | |
| 124 virtual ~GpuCrashHandlerHostLinux(); | |
| 125 | |
| 126 #if defined(USE_LINUX_BREAKPAD) | |
| 127 virtual void SetProcessType() OVERRIDE; | |
| 128 #endif | |
| 129 | |
| 130 DISALLOW_COPY_AND_ASSIGN(GpuCrashHandlerHostLinux); | |
| 131 }; | |
| 132 | |
| 133 class PluginCrashHandlerHostLinux : public CrashHandlerHostLinux { | |
| 134 public: | |
| 135 // Returns the singleton instance. | |
| 136 static PluginCrashHandlerHostLinux* GetInstance(); | |
| 137 | |
| 138 private: | |
| 139 friend struct DefaultSingletonTraits<PluginCrashHandlerHostLinux>; | |
| 140 PluginCrashHandlerHostLinux(); | |
| 141 virtual ~PluginCrashHandlerHostLinux(); | |
| 142 | |
| 143 #if defined(USE_LINUX_BREAKPAD) | |
| 144 virtual void SetProcessType() OVERRIDE; | |
| 145 #endif | |
| 146 | |
| 147 DISALLOW_COPY_AND_ASSIGN(PluginCrashHandlerHostLinux); | |
| 148 }; | |
| 149 | |
| 150 class PpapiCrashHandlerHostLinux : public CrashHandlerHostLinux { | |
| 151 public: | |
| 152 // Returns the singleton instance. | |
| 153 static PpapiCrashHandlerHostLinux* GetInstance(); | |
| 154 | |
| 155 private: | |
| 156 friend struct DefaultSingletonTraits<PpapiCrashHandlerHostLinux>; | |
| 157 PpapiCrashHandlerHostLinux(); | |
| 158 virtual ~PpapiCrashHandlerHostLinux(); | |
| 159 | |
| 160 #if defined(USE_LINUX_BREAKPAD) | |
| 161 virtual void SetProcessType() OVERRIDE; | |
| 162 #endif | |
| 163 | |
| 164 DISALLOW_COPY_AND_ASSIGN(PpapiCrashHandlerHostLinux); | |
| 165 }; | |
| 166 | |
| 167 class RendererCrashHandlerHostLinux : public CrashHandlerHostLinux { | |
| 168 public: | |
| 169 // Returns the singleton instance. | |
| 170 static RendererCrashHandlerHostLinux* GetInstance(); | |
| 171 | |
| 172 private: | |
| 173 friend struct DefaultSingletonTraits<RendererCrashHandlerHostLinux>; | |
| 174 RendererCrashHandlerHostLinux(); | |
| 175 virtual ~RendererCrashHandlerHostLinux(); | |
| 176 | |
| 177 #if defined(USE_LINUX_BREAKPAD) | |
| 178 virtual void SetProcessType() OVERRIDE; | |
| 179 #endif | |
| 180 | |
| 181 DISALLOW_COPY_AND_ASSIGN(RendererCrashHandlerHostLinux); | |
| 182 }; | |
| 183 | |
| 184 #endif // CHROME_BROWSER_CRASH_HANDLER_HOST_LINUXISH_H_ | |
| OLD | NEW |