Add ICU message format support
[chromium-blink-merge.git] / chromecast / crash / linux / minidump_writer.h
blobe37dbaffb716c496cce5aeae89d34a3f49d696d1
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.
5 #ifndef CHROMECAST_CRASH_LINUX_MINIDUMP_WRITER_H_
6 #define CHROMECAST_CRASH_LINUX_MINIDUMP_WRITER_H_
8 #include "base/callback.h"
9 #include "base/files/file_path.h"
10 #include "base/macros.h"
11 #include "base/time/time.h"
12 #include "chromecast/crash/linux/minidump_params.h"
13 #include "chromecast/crash/linux/synchronized_minidump_manager.h"
15 namespace chromecast {
17 class MinidumpGenerator;
19 // Class for writing a minidump with synchronized access to the minidumps
20 // directory.
21 class MinidumpWriter : public SynchronizedMinidumpManager {
22 public:
23 typedef base::Callback<int(const std::string&)> DumpStateCallback;
25 // Constructs a writer for a minidump. If |minidump_filename| is absolute, it
26 // must be a path to a file in the |dump_path_| directory. Otherwise, it
27 // should be a filename only, in which case, |minidump_generator| creates
28 // a minidump at $HOME/minidumps/|minidump_filename|. |params| describes the
29 // minidump metadata. |dump_state_cb| is Run() to generate a log dump. Please
30 // see the comments on |dump_state_cb_| below for details about this
31 // parameter.
32 // This does not take ownership of |minidump_generator|.
33 MinidumpWriter(MinidumpGenerator* minidump_generator,
34 const std::string& minidump_filename,
35 const MinidumpParams& params,
36 const base::Callback<int(const std::string&)>& dump_state_cb);
38 // Like the constructor above, but the default implementation of
39 // |dump_state_cb_| is used inside DoWork().
40 MinidumpWriter(MinidumpGenerator* minidump_generator,
41 const std::string& minidump_filename,
42 const MinidumpParams& params);
44 ~MinidumpWriter() override;
46 // Acquires exclusive access to the minidumps directory and generates a
47 // minidump and a log to be uploaded later. Returns 0 if successful, -1
48 // otherwise.
49 int Write() { return AcquireLockAndDoWork(); }
51 protected:
52 // MinidumpManager implementation:
53 int DoWork() override;
55 private:
56 MinidumpGenerator* const minidump_generator_;
57 base::FilePath minidump_path_;
58 const MinidumpParams params_;
60 // This callback is Run() to dump a log to |minidump_path_|.txt.gz, taking
61 // |minidump_path_| as a parameter. It returns 0 on success, and a negative
62 // integer otherwise. If a callback is not passed in the constructor, the
63 // default implemementaion is used.
64 DumpStateCallback dump_state_cb_;
66 DISALLOW_COPY_AND_ASSIGN(MinidumpWriter);
69 } // namespace chromecast
71 #endif // CHROMECAST_CRASH_LINUX_MINIDUMP_WRITER_H_