summaryrefslogtreecommitdiffstats
path: root/chrome/browser/crash_handler_host_linux.h
blob: 5d5876321e85655b24a53d0f39694e6842e3b11d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_CRASH_HANDLER_HOST_LINUX_H_
#define CHROME_BROWSER_CRASH_HANDLER_HOST_LINUX_H_
#pragma once

#include "base/message_loop.h"

#if defined(USE_LINUX_BREAKPAD)
#include <sys/types.h>

#include <string>

#include "base/scoped_ptr.h"

class BreakpadInfo;

namespace base {
class Thread;
}
#endif  // defined(USE_LINUX_BREAKPAD)

template <typename T> struct DefaultSingletonTraits;

// This is the base class for singleton objects which crash dump renderers and
// plugins on Linux. We perform the crash dump from the browser because it
// allows us to be outside the sandbox.
//
// PluginCrashHandlerHostLinux and RendererCrashHandlerHostLinux are singletons
// that handle plugin and renderer crashes, respectively.
//
// Processes signal that they need to be dumped by sending a datagram over a
// UNIX domain socket. All processes of the same type share the client end of
// this socket which is installed in their descriptor table before exec.
class CrashHandlerHostLinux : public MessageLoopForIO::Watcher,
                              public MessageLoop::DestructionObserver {
 public:
  // Get the file descriptor which processes should be given in order to signal
  // crashes to the browser.
  int GetDeathSignalSocket() const {
    return process_socket_;
  }

  // MessagePumbLibevent::Watcher impl:
  virtual void OnFileCanWriteWithoutBlocking(int fd);
  virtual void OnFileCanReadWithoutBlocking(int fd);

  // MessageLoop::DestructionObserver impl:
  virtual void WillDestroyCurrentMessageLoop();

#if defined(USE_LINUX_BREAKPAD)
  // Whether we are shutting down or not.
  bool IsShuttingDown() const;
#endif

 protected:
  CrashHandlerHostLinux();
  virtual ~CrashHandlerHostLinux();

#if defined(USE_LINUX_BREAKPAD)
  // Only called in concrete subclasses.
  void InitCrashUploaderThread();

  std::string process_type_;
#endif

 private:
  void Init();

#if defined(USE_LINUX_BREAKPAD)
  // This is here on purpose to make CrashHandlerHostLinux abstract.
  virtual void SetProcessType() = 0;

  // Do work on the FILE thread for OnFileCanReadWithoutBlocking().
  void WriteDumpFile(BreakpadInfo* info,
                     pid_t crashing_pid,
                     char* crash_context,
                     int signal_fd);

  // Continue OnFileCanReadWithoutBlocking()'s work on the IO thread.
  void QueueCrashDumpTask(BreakpadInfo* info, int signal_fd);
#endif

  int process_socket_;
  int browser_socket_;

#if defined(USE_LINUX_BREAKPAD)
  MessageLoopForIO::FileDescriptorWatcher file_descriptor_watcher_;
  scoped_ptr<base::Thread> uploader_thread_;
  bool shutting_down_;
#endif

  DISALLOW_COPY_AND_ASSIGN(CrashHandlerHostLinux);
};

class GpuCrashHandlerHostLinux : public CrashHandlerHostLinux {
 public:
  // Returns the singleton instance.
  static GpuCrashHandlerHostLinux* GetInstance();

 private:
  friend struct DefaultSingletonTraits<GpuCrashHandlerHostLinux>;
  GpuCrashHandlerHostLinux();
  virtual ~GpuCrashHandlerHostLinux();

#if defined(USE_LINUX_BREAKPAD)
  virtual void SetProcessType();
#endif

  DISALLOW_COPY_AND_ASSIGN(GpuCrashHandlerHostLinux);
};

class PluginCrashHandlerHostLinux : public CrashHandlerHostLinux {
 public:
  // Returns the singleton instance.
  static PluginCrashHandlerHostLinux* GetInstance();

 private:
  friend struct DefaultSingletonTraits<PluginCrashHandlerHostLinux>;
  PluginCrashHandlerHostLinux();
  virtual ~PluginCrashHandlerHostLinux();

#if defined(USE_LINUX_BREAKPAD)
  virtual void SetProcessType();
#endif

  DISALLOW_COPY_AND_ASSIGN(PluginCrashHandlerHostLinux);
};

class RendererCrashHandlerHostLinux : public CrashHandlerHostLinux {
 public:
  // Returns the singleton instance.
  static RendererCrashHandlerHostLinux* GetInstance();

 private:
  friend struct DefaultSingletonTraits<RendererCrashHandlerHostLinux>;
  RendererCrashHandlerHostLinux();
  virtual ~RendererCrashHandlerHostLinux();

#if defined(USE_LINUX_BREAKPAD)
  virtual void SetProcessType();
#endif

  DISALLOW_COPY_AND_ASSIGN(RendererCrashHandlerHostLinux);
};

#endif  // CHROME_BROWSER_CRASH_HANDLER_HOST_LINUX_H_