OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_MICRO_DUMP_MANAGER_ANDROID_H_ | |
6 #define COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_MICRO_DUMP_MANAGER_ANDROID_H_ | |
7 | |
8 #include <map> | |
9 #include <memory> | |
10 | |
11 #include "base/files/scoped_file.h" | |
12 #include "base/memory/singleton.h" | |
13 #include "base/memory/weak_ptr.h" | |
14 #include "base/process/kill.h" | |
15 #include "base/sync_socket.h" | |
16 #include "base/synchronization/lock.h" | |
17 #include "content/public/browser/notification_observer.h" | |
18 #include "content/public/browser/notification_registrar.h" | |
19 | |
20 namespace breakpad { | |
21 | |
22 // This class manages behavior of the browser on renderer crashes when | |
23 // microdumps are used for capturing the crash stack. Normally, in this case | |
24 // the browser doesn't need to do much, because a microdump is written into | |
25 // Android log by the renderer process itself. However, the browser may need to | |
26 // crash itself on a renderer crash. Since on Android renderers are not child | |
27 // processes of the browser, it can't access the exit code. Instead, the browser | |
28 // uses a dedicated pipe in order to receive the information about the renderer | |
29 // crash status. | |
30 class CrashMicroDumpManager : public content::NotificationObserver { | |
31 public: | |
32 // There is only a single instance of CrashMicroDumpManager per browser | |
33 // process. It needs to be created on the UI thread. | |
34 static CrashMicroDumpManager* GetInstance(); | |
35 | |
36 // Returns a pipe that should be used to transfer termination cause of | |
37 // |child_process_id|. | |
38 base::ScopedFD CreateCrashInfoChannel(int child_process_id); | |
39 | |
40 private: | |
41 friend struct base::DefaultSingletonTraits<CrashMicroDumpManager>; | |
42 | |
43 CrashMicroDumpManager(); | |
44 ~CrashMicroDumpManager() override; | |
45 | |
46 // NotificationObserver implementation: | |
47 void Observe(int type, | |
48 const content::NotificationSource& source, | |
49 const content::NotificationDetails& details) override; | |
50 | |
51 // Called on child process exit (including crash). | |
52 void HandleChildTerminationOnFileThread( | |
53 int child_process_id, | |
54 base::TerminationStatus termination_status); | |
55 | |
56 content::NotificationRegistrar notification_registrar_; | |
57 | |
58 // This map should only be accessed with its lock aquired as it is accessed | |
59 // from the PROCESS_LAUNCHER, FILE, and UI threads. | |
60 base::Lock child_process_id_to_pipe_lock_; | |
61 std::map<int, std::unique_ptr<base::SyncSocket>> child_process_id_to_pipe_; | |
62 base::WeakPtrFactory<CrashMicroDumpManager> weak_factory_; | |
63 | |
64 DISALLOW_COPY_AND_ASSIGN(CrashMicroDumpManager); | |
65 }; | |
66 | |
67 } // namespace breakpad | |
68 | |
69 #endif // COMPONENTS_CRASH_CONTENT_BROWSER_CRASH_MICRO_DUMP_MANAGER_ANDROID_H_ | |
OLD | NEW |