OLD | NEW |
(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_manager.h" |
| 13 #include "chromecast/crash/linux/minidump_params.h" |
| 14 |
| 15 namespace chromecast { |
| 16 |
| 17 class MinidumpGenerator; |
| 18 |
| 19 // Class for writing a minidump. |
| 20 class MinidumpWriter : public MinidumpManager { |
| 21 public: |
| 22 typedef base::Callback<int(const std::string&)> DumpStateCallback; |
| 23 |
| 24 // Constructs a writer for a minidump. If |minidump_filename| is absolute, it |
| 25 // must be a path to a file in the |dump_path_| directory. Otherwise, it |
| 26 // should be a filename only, in which case, |minidump_generator| creates |
| 27 // a minidump at $HOME/minidumps/|minidump_filename|. |params| describes the |
| 28 // minidump metadata. |dump_state_cb| is Run() to generate a log dump. Please |
| 29 // see the comments on |dump_state_cb_| below for details about this |
| 30 // parameter. |
| 31 // This does not take ownership of |minidump_generator|. |
| 32 MinidumpWriter(MinidumpGenerator* minidump_generator, |
| 33 const std::string& minidump_filename, |
| 34 const MinidumpParams& params, |
| 35 const base::Callback<int(const std::string&)>& dump_state_cb); |
| 36 |
| 37 // Like the constructor above, but the default implementation of |
| 38 // |dump_state_cb_| is used inside DoWork(). |
| 39 MinidumpWriter(MinidumpGenerator* minidump_generator, |
| 40 const std::string& minidump_filename, |
| 41 const MinidumpParams& params); |
| 42 |
| 43 ~MinidumpWriter() override; |
| 44 |
| 45 int max_dumps() const { return max_dumps_; } |
| 46 int max_recent_dumps() const { return max_recent_dumps_; } |
| 47 const base::TimeDelta& dump_interval() const { return dump_interval_; }; |
| 48 |
| 49 protected: |
| 50 // MinidumpManager implementation: |
| 51 int DoWork() override; |
| 52 |
| 53 private: |
| 54 // Returns true if we can write another dump, false otherwise. We can write |
| 55 // another dump if the number of minidumps is strictly less than |max_dumps_| |
| 56 // and the number of minidumps which occurred within the last |dump_interval_| |
| 57 // is strictly less than |max_recent_dumps_|. |
| 58 bool CanWriteDump(); |
| 59 |
| 60 MinidumpGenerator* const minidump_generator_; |
| 61 base::FilePath minidump_path_; |
| 62 const MinidumpParams params_; |
| 63 |
| 64 const int max_dumps_; |
| 65 const base::TimeDelta dump_interval_; |
| 66 const int max_recent_dumps_; |
| 67 |
| 68 // This callback is Run() to dump a log to |minidump_path_|.txt.gz, taking |
| 69 // |minidump_path_| as a parameter. It returns 0 on success, and a negative |
| 70 // integer otherwise. If a callback is not passed in the constructor, the |
| 71 // default implemementaion is used. |
| 72 DumpStateCallback dump_state_cb_; |
| 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(MinidumpWriter); |
| 75 }; |
| 76 |
| 77 } // namespace chromecast |
| 78 |
| 79 #endif // CHROMECAST_CRASH_LINUX_MINIDUMP_WRITER_H_ |
OLD | NEW |