Roll src/third_party/WebKit 9f7fb92:f103b33 (svn 202621:202622)
[chromium-blink-merge.git] / components / crash / content / browser / crash_handler_host_linux.h
blob92ef522ed412e516607653f25a9966ffd8b8f00a
1 // Copyright 2013 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 COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_HANDLER_HOST_LINUX_H_
6 #define COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_HANDLER_HOST_LINUX_H_
8 #include <sys/types.h>
10 #include <string>
12 #include "base/compiler_specific.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop.h"
16 #include "base/threading/sequenced_worker_pool.h"
18 namespace base {
19 class Thread;
22 namespace breakpad {
24 struct BreakpadInfo;
26 // This is the host for processes which run breakpad inside the sandbox on
27 // Linux or Android. We perform the crash dump from the browser because it
28 // allows us to be outside the sandbox.
30 // Processes signal that they need to be dumped by sending a datagram over a
31 // UNIX domain socket. All processes of the same type share the client end of
32 // this socket which is installed in their descriptor table before exec.
33 class CrashHandlerHostLinux : public base::MessageLoopForIO::Watcher,
34 public base::MessageLoop::DestructionObserver {
35 public:
36 CrashHandlerHostLinux(const std::string& process_type,
37 const base::FilePath& dumps_path,
38 bool upload);
39 ~CrashHandlerHostLinux() override;
41 // Starts the uploader thread. Must be called immediately after creating the
42 // class.
43 void StartUploaderThread();
45 // Get the file descriptor which processes should be given in order to signal
46 // crashes to the browser.
47 int GetDeathSignalSocket() const {
48 return process_socket_;
51 // MessagePumbLibevent::Watcher impl:
52 void OnFileCanWriteWithoutBlocking(int fd) override;
53 void OnFileCanReadWithoutBlocking(int fd) override;
55 // MessageLoop::DestructionObserver impl:
56 void WillDestroyCurrentMessageLoop() override;
58 // Whether we are shutting down or not.
59 bool IsShuttingDown() const;
61 private:
62 void Init();
64 // Do work in a sequenced worker pool for OnFileCanReadWithoutBlocking().
65 void WriteDumpFile(scoped_ptr<BreakpadInfo> info,
66 scoped_ptr<char[]> crash_context,
67 pid_t crashing_pid,
68 int signal_fd);
70 // Continue OnFileCanReadWithoutBlocking()'s work on the IO thread.
71 void QueueCrashDumpTask(scoped_ptr<BreakpadInfo> info, int signal_fd);
73 std::string process_type_;
74 base::FilePath dumps_path_;
75 bool upload_;
77 int process_socket_;
78 int browser_socket_;
80 base::MessageLoopForIO::FileDescriptorWatcher file_descriptor_watcher_;
81 scoped_ptr<base::Thread> uploader_thread_;
82 bool shutting_down_;
84 // Unique sequence token so that writing crash dump won't be blocked
85 // by other tasks.
86 base::SequencedWorkerPool::SequenceToken worker_pool_token_;
88 DISALLOW_COPY_AND_ASSIGN(CrashHandlerHostLinux);
91 } // namespace breakpad
93 #endif // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_HANDLER_HOST_LINUX_H_