Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: chromecast/crash/linux/minidump_writer.h

Issue 1154383006: Adding crash utilities to chromecast/crash. (Closed) Base URL: https://eureka-internal.googlesource.com/chromium/src@master
Patch Set: cast_shell_unittests not built for android Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chromecast/crash/linux/minidump_params.cc ('k') | chromecast/crash/linux/minidump_writer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 CHROMECAST_CRASH_LINUX_MINIDUMP_WRITER_H_
6 #define CHROMECAST_CRASH_LINUX_MINIDUMP_WRITER_H_
7
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"
14
15 namespace chromecast {
16
17 class MinidumpGenerator;
18
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;
24
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);
37
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);
43
44 ~MinidumpWriter() override;
45
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(); }
50
51 int max_dumps() const { return max_dumps_; }
52 int max_recent_dumps() const { return max_recent_dumps_; }
53 const base::TimeDelta& dump_interval() const { return dump_interval_; };
54
55 protected:
56 // MinidumpManager implementation:
57 int DoWork() override;
58
59 private:
60 // Returns true if we can write another dump, false otherwise. We can write
61 // another dump if the number of minidumps is strictly less than |max_dumps_|
62 // and the number of minidumps which occurred within the last |dump_interval_|
63 // is strictly less than |max_recent_dumps_|.
64 bool CanWriteDump();
65
66 MinidumpGenerator* const minidump_generator_;
67 base::FilePath minidump_path_;
68 const MinidumpParams params_;
69
70 const int max_dumps_;
71 const base::TimeDelta dump_interval_;
72 const int max_recent_dumps_;
73
74 // This callback is Run() to dump a log to |minidump_path_|.txt.gz, taking
75 // |minidump_path_| as a parameter. It returns 0 on success, and a negative
76 // integer otherwise. If a callback is not passed in the constructor, the
77 // default implemementaion is used.
78 DumpStateCallback dump_state_cb_;
79
80 DISALLOW_COPY_AND_ASSIGN(MinidumpWriter);
81 };
82
83 } // namespace chromecast
84
85 #endif // CHROMECAST_CRASH_LINUX_MINIDUMP_WRITER_H_
OLDNEW
« no previous file with comments | « chromecast/crash/linux/minidump_params.cc ('k') | chromecast/crash/linux/minidump_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698