Allow the externalfile scheme to be whitelisted as an allowed scheme for component...
[chromium-blink-merge.git] / components / crash / browser / crash_dump_manager_android.h
blobd7ae5c81df6f3766e573b8851446140437a81e2a
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_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_
6 #define COMPONENTS_CRASH_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_
8 #include <map>
10 #include "base/files/file.h"
11 #include "base/files/file_path.h"
12 #include "base/process/process.h"
13 #include "base/synchronization/lock.h"
14 #include "content/public/browser/browser_child_process_observer.h"
15 #include "content/public/browser/notification_observer.h"
16 #include "content/public/browser/notification_registrar.h"
18 namespace content {
19 class RenderProcessHost;
22 namespace breakpad {
24 // This class manages the crash minidumps.
25 // On Android, because of process isolation, each renderer process runs with a
26 // different UID. As a result, we cannot generate the minidumps in the browser
27 // (as the browser process does not have access to some system files for the
28 // crashed process). So the minidump is generated in the renderer process.
29 // Since the isolated process cannot open files, we provide it on creation with
30 // a file descriptor where to write the minidump in the event of a crash.
31 // This class creates these file descriptors and associates them with render
32 // processes and take the appropriate action when the render process terminates.
33 class CrashDumpManager : public content::BrowserChildProcessObserver,
34 public content::NotificationObserver {
35 public:
36 // The embedder should create a single instance of the CrashDumpManager.
37 static CrashDumpManager* GetInstance();
39 // Should be created on the UI thread.
40 explicit CrashDumpManager(const base::FilePath& crash_dump_dir);
42 ~CrashDumpManager() override;
44 // Returns a file that should be used to generate a minidump for the process
45 // |child_process_id|.
46 base::File CreateMinidumpFile(int child_process_id);
48 private:
49 typedef std::map<int, base::FilePath> ChildProcessIDToMinidumpPath;
51 static void ProcessMinidump(const base::FilePath& minidump_path,
52 base::ProcessHandle pid);
54 // content::BrowserChildProcessObserver implementation:
55 void BrowserChildProcessHostDisconnected(
56 const content::ChildProcessData& data) override;
57 void BrowserChildProcessCrashed(
58 const content::ChildProcessData& data) override;
60 // NotificationObserver implementation:
61 void Observe(int type,
62 const content::NotificationSource& source,
63 const content::NotificationDetails& details) override;
65 // Called on child process exit (including crash).
66 void OnChildExit(int child_process_id, base::ProcessHandle pid);
68 content::NotificationRegistrar notification_registrar_;
70 // This map should only be accessed with its lock aquired as it is accessed
71 // from the PROCESS_LAUNCHER and UI threads.
72 base::Lock child_process_id_to_minidump_path_lock_;
73 ChildProcessIDToMinidumpPath child_process_id_to_minidump_path_;
75 base::FilePath crash_dump_dir_;
77 static CrashDumpManager* instance_;
79 DISALLOW_COPY_AND_ASSIGN(CrashDumpManager);
82 } // namespace breakpad
84 #endif // COMPONENTS_CRASH_BROWSER_CRASH_DUMP_MANAGER_ANDROID_H_