OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_BROWSER_ANDROID_CRASH_DUMP_MANAGER_H_ |
| 6 #define CHROME_BROWSER_ANDROID_CRASH_DUMP_MANAGER_H_ |
| 7 |
| 8 #include <map> |
| 9 |
| 10 #include "base/file_path.h" |
| 11 #include "base/memory/singleton.h" |
| 12 #include "base/platform_file.h" |
| 13 #include "base/synchronization/lock.h" |
| 14 #include "content/public/browser/notification_observer.h" |
| 15 #include "content/public/browser/notification_registrar.h" |
| 16 |
| 17 namespace content { |
| 18 class RenderProcessHost; |
| 19 } |
| 20 |
| 21 // This class manages the crash minidumps. |
| 22 // On Android, because of process isolation, each renderer process runs with a |
| 23 // different UID. As a result, we cannot generate the minidumps in the browser |
| 24 // (as the browser process does not have access to some system files for the |
| 25 // crashed process). So the minidump is generated in the renderer process. |
| 26 // Since the isolated process cannot open files, we provide it on creation with |
| 27 // a file descriptor where to write the minidump in the event of a crash. |
| 28 // This class creates these file descriptors and associates them with render |
| 29 // processes and take the appropriate action when the render process terminates. |
| 30 class CrashDumpManager : public content::NotificationObserver { |
| 31 public: |
| 32 // Should be created on the UI thread. |
| 33 CrashDumpManager(); |
| 34 virtual ~CrashDumpManager(); |
| 35 |
| 36 // Returns a file descriptor that should be used by a render process to |
| 37 // generate a minidump. |
| 38 // The returned FD is associated with the actual RenderProcessHost with the |
| 39 // NOTIFICATION_RENDERER_PROCESS_CREATED notification. |
| 40 int CreateMinidumpFile(); |
| 41 |
| 42 private: |
| 43 struct MinidumpInfo { |
| 44 MinidumpInfo() : file(base::kInvalidPlatformFileValue) {} |
| 45 base::PlatformFile file; |
| 46 FilePath path; |
| 47 int pid; |
| 48 }; |
| 49 |
| 50 static void ProcessMinidump(const MinidumpInfo& minidump); |
| 51 |
| 52 // NotificationObserver implementation: |
| 53 virtual void Observe(int type, |
| 54 const content::NotificationSource& source, |
| 55 const content::NotificationDetails& details) OVERRIDE; |
| 56 |
| 57 content::NotificationRegistrar notification_registrar_; |
| 58 |
| 59 typedef std::map<content::RenderProcessHost*, MinidumpInfo> RPHToMinidumpInfo; |
| 60 RPHToMinidumpInfo rph_to_minidump_info_; |
| 61 |
| 62 typedef std::map<base::PlatformFile, FilePath> FileToPath; |
| 63 // This map should only be accessed with its lock aquired as it is accessed |
| 64 // from the PROCESS_LAUNCHER and UI threads. |
| 65 FileToPath file_to_path_; |
| 66 base::Lock file_to_path_lock_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(CrashDumpManager); |
| 69 }; |
| 70 |
| 71 #endif // CHROME_BROWSER_ANDROID_CRASH_DUMP_MANAGER_H_ |
OLD | NEW |