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