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_MINIDUMP_MANAGER_H_ |
| 6 #define CHROMECAST_CRASH_MINIDUMP_MANAGER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/macros.h" |
| 11 |
| 12 namespace chromecast { |
| 13 |
| 14 // Abstract class for minidump handling. Ensures synchronized access to |
| 15 // minidumps using a file lock. |
| 16 class MinidumpManager { |
| 17 public: |
| 18 virtual ~MinidumpManager(); |
| 19 |
| 20 // Acquires file lock, calls doWork(), then releases file lock. |
| 21 // Returns the status of doWork(), or -1 if the lock could not be acquired. |
| 22 int DoWorkLocked(); |
| 23 |
| 24 // Returns whether this object's file locking method is nonblocking or not. |
| 25 bool nonblocking() { return nonblocking_; } |
| 26 |
| 27 // Sets the file locking mechansim to be nonblocking or not. |
| 28 void SetNonblocking(bool nonblocking) { nonblocking_ = nonblocking; } |
| 29 |
| 30 protected: |
| 31 MinidumpManager(); |
| 32 |
| 33 // Overriden by child classes doing a specific operation to minidumps |
| 34 virtual int DoWork() = 0; |
| 35 |
| 36 // Get the number of un-uploaded dumps in the dump_path directory. |
| 37 // If delete_all_dumps is true, also delete all these files, this is used to |
| 38 // clean lingering dump files. |
| 39 int GetNumDumps(bool delete_all_dumps); |
| 40 |
| 41 // If true, the flock on the lockfile will be nonblocking |
| 42 bool nonblocking_; |
| 43 |
| 44 // cached string storing the dump path directory retrieved from system |
| 45 // properties, or empty string if property does not exist |
| 46 std::string dump_path_; |
| 47 |
| 48 // cached string storing the lockfile path |
| 49 std::string lockfile_path_; |
| 50 |
| 51 private: |
| 52 // Acquire the lock file. Blocks if another process holds it, or if called |
| 53 // a second time by the same process. Returns the fd of the lockfile if |
| 54 // successful, or -1 if failed. |
| 55 int AcquireLockFile(); |
| 56 // Release the lock file with the associated *fd*. |
| 57 void ReleaseLockFile(); |
| 58 |
| 59 // the lockfile fd, or -1 if not open |
| 60 int lockfile_fd_; |
| 61 |
| 62 DISALLOW_COPY_AND_ASSIGN(MinidumpManager); |
| 63 }; |
| 64 |
| 65 } // namespace chromecast |
| 66 |
| 67 #endif // CHROMECAST_CRASH_MINIDUMP_MANAGER_H_ |
OLD | NEW |