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.
5 #ifndef CHROME_BROWSER_CRASH_HANDLER_HOST_LINUX_H_
6 #define CHROME_BROWSER_CRASH_HANDLER_HOST_LINUX_H_
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_loop.h"
22 template <typename T
> struct DefaultSingletonTraits
;
24 // This is the base class for singleton objects which crash dump renderers and
25 // plugins on Linux or Android. We perform the crash dump from the browser
26 // because it allows us to be outside the sandbox.
28 // PluginCrashHandlerHostLinux and RendererCrashHandlerHostLinux are
29 // singletons that handle plugin and renderer crashes, respectively.
31 // Processes signal that they need to be dumped by sending a datagram over a
32 // UNIX domain socket. All processes of the same type share the client end of
33 // this socket which is installed in their descriptor table before exec.
34 class CrashHandlerHostLinux
: public base::MessageLoopForIO::Watcher
,
35 public base::MessageLoop::DestructionObserver
{
37 // Get the file descriptor which processes should be given in order to signal
38 // crashes to the browser.
39 int GetDeathSignalSocket() const {
40 return process_socket_
;
43 // MessagePumbLibevent::Watcher impl:
44 virtual void OnFileCanWriteWithoutBlocking(int fd
) OVERRIDE
;
45 virtual void OnFileCanReadWithoutBlocking(int fd
) OVERRIDE
;
47 // MessageLoop::DestructionObserver impl:
48 virtual void WillDestroyCurrentMessageLoop() OVERRIDE
;
50 // Whether we are shutting down or not.
51 bool IsShuttingDown() const;
54 CrashHandlerHostLinux();
55 virtual ~CrashHandlerHostLinux();
57 // Only called in concrete subclasses.
58 void InitCrashUploaderThread();
60 std::string process_type_
;
65 // This is here on purpose to make CrashHandlerHostLinux abstract.
66 virtual void SetProcessType() = 0;
68 // Do work on the FILE thread for OnFileCanReadWithoutBlocking().
69 void WriteDumpFile(BreakpadInfo
* info
,
74 // Continue OnFileCanReadWithoutBlocking()'s work on the IO thread.
75 void QueueCrashDumpTask(BreakpadInfo
* info
, int signal_fd
);
80 base::MessageLoopForIO::FileDescriptorWatcher file_descriptor_watcher_
;
81 scoped_ptr
<base::Thread
> uploader_thread_
;
84 #if defined(ADDRESS_SANITIZER)
85 char* asan_report_str_
;
88 DISALLOW_COPY_AND_ASSIGN(CrashHandlerHostLinux
);
91 class ExtensionCrashHandlerHostLinux
: public CrashHandlerHostLinux
{
93 // Returns the singleton instance.
94 static ExtensionCrashHandlerHostLinux
* GetInstance();
97 friend struct DefaultSingletonTraits
<ExtensionCrashHandlerHostLinux
>;
98 ExtensionCrashHandlerHostLinux();
99 virtual ~ExtensionCrashHandlerHostLinux();
101 virtual void SetProcessType() OVERRIDE
;
103 DISALLOW_COPY_AND_ASSIGN(ExtensionCrashHandlerHostLinux
);
106 class GpuCrashHandlerHostLinux
: public CrashHandlerHostLinux
{
108 // Returns the singleton instance.
109 static GpuCrashHandlerHostLinux
* GetInstance();
112 friend struct DefaultSingletonTraits
<GpuCrashHandlerHostLinux
>;
113 GpuCrashHandlerHostLinux();
114 virtual ~GpuCrashHandlerHostLinux();
116 virtual void SetProcessType() OVERRIDE
;
118 DISALLOW_COPY_AND_ASSIGN(GpuCrashHandlerHostLinux
);
121 class PluginCrashHandlerHostLinux
: public CrashHandlerHostLinux
{
123 // Returns the singleton instance.
124 static PluginCrashHandlerHostLinux
* GetInstance();
127 friend struct DefaultSingletonTraits
<PluginCrashHandlerHostLinux
>;
128 PluginCrashHandlerHostLinux();
129 virtual ~PluginCrashHandlerHostLinux();
131 virtual void SetProcessType() OVERRIDE
;
133 DISALLOW_COPY_AND_ASSIGN(PluginCrashHandlerHostLinux
);
136 class PpapiCrashHandlerHostLinux
: public CrashHandlerHostLinux
{
138 // Returns the singleton instance.
139 static PpapiCrashHandlerHostLinux
* GetInstance();
142 friend struct DefaultSingletonTraits
<PpapiCrashHandlerHostLinux
>;
143 PpapiCrashHandlerHostLinux();
144 virtual ~PpapiCrashHandlerHostLinux();
146 virtual void SetProcessType() OVERRIDE
;
148 DISALLOW_COPY_AND_ASSIGN(PpapiCrashHandlerHostLinux
);
151 class RendererCrashHandlerHostLinux
: public CrashHandlerHostLinux
{
153 // Returns the singleton instance.
154 static RendererCrashHandlerHostLinux
* GetInstance();
157 friend struct DefaultSingletonTraits
<RendererCrashHandlerHostLinux
>;
158 RendererCrashHandlerHostLinux();
159 virtual ~RendererCrashHandlerHostLinux();
161 virtual void SetProcessType() OVERRIDE
;
163 DISALLOW_COPY_AND_ASSIGN(RendererCrashHandlerHostLinux
);
166 #endif // CHROME_BROWSER_CRASH_HANDLER_HOST_LINUX_H_