1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMECAST_CRASH_LINUX_MINIDUMP_WRITER_H_
#define CHROMECAST_CRASH_LINUX_MINIDUMP_WRITER_H_
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/time/time.h"
#include "chromecast/crash/linux/minidump_params.h"
#include "chromecast/crash/linux/synchronized_minidump_manager.h"
namespace chromecast {
class MinidumpGenerator;
// Class for writing a minidump with synchronized access to the minidumps
// directory.
class MinidumpWriter : public SynchronizedMinidumpManager {
public:
typedef base::Callback<int(const std::string&)> DumpStateCallback;
// Constructs a writer for a minidump. If |minidump_filename| is absolute, it
// must be a path to a file in the |dump_path_| directory. Otherwise, it
// should be a filename only, in which case, |minidump_generator| creates
// a minidump at $HOME/minidumps/|minidump_filename|. |params| describes the
// minidump metadata. |dump_state_cb| is Run() to generate a log dump. Please
// see the comments on |dump_state_cb_| below for details about this
// parameter.
// This does not take ownership of |minidump_generator|.
MinidumpWriter(MinidumpGenerator* minidump_generator,
const std::string& minidump_filename,
const MinidumpParams& params,
const base::Callback<int(const std::string&)>& dump_state_cb);
// Like the constructor above, but the default implementation of
// |dump_state_cb_| is used inside DoWork().
MinidumpWriter(MinidumpGenerator* minidump_generator,
const std::string& minidump_filename,
const MinidumpParams& params);
~MinidumpWriter() override;
// Acquires exclusive access to the minidumps directory and generates a
// minidump and a log to be uploaded later. Returns 0 if successful, -1
// otherwise.
int Write() { return AcquireLockAndDoWork(); }
protected:
// MinidumpManager implementation:
int DoWork() override;
private:
MinidumpGenerator* const minidump_generator_;
base::FilePath minidump_path_;
const MinidumpParams params_;
// This callback is Run() to dump a log to |minidump_path_|.txt.gz, taking
// |minidump_path_| as a parameter. It returns 0 on success, and a negative
// integer otherwise. If a callback is not passed in the constructor, the
// default implemementaion is used.
DumpStateCallback dump_state_cb_;
DISALLOW_COPY_AND_ASSIGN(MinidumpWriter);
};
} // namespace chromecast
#endif // CHROMECAST_CRASH_LINUX_MINIDUMP_WRITER_H_
|