| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROMECAST_CRASH_LINUX_SYNCHRONIZED_MINIDUMP_MANAGER_H_ | 5 #ifndef CHROMECAST_CRASH_LINUX_SYNCHRONIZED_MINIDUMP_MANAGER_H_ |
| 6 #define CHROMECAST_CRASH_LINUX_SYNCHRONIZED_MINIDUMP_MANAGER_H_ | 6 #define CHROMECAST_CRASH_LINUX_SYNCHRONIZED_MINIDUMP_MANAGER_H_ |
| 7 | 7 |
| 8 #include <time.h> | 8 #include <time.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/files/file.h" |
| 12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 13 #include "base/macros.h" | 14 #include "base/macros.h" |
| 14 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 15 #include "base/values.h" | 16 #include "base/values.h" |
| 16 #include "chromecast/crash/linux/dump_info.h" | 17 #include "chromecast/crash/linux/dump_info.h" |
| 17 | 18 |
| 18 namespace chromecast { | 19 namespace chromecast { |
| 19 | 20 |
| 20 // Abstract base class for mutually-exclusive minidump handling. Ensures | 21 // Abstract base class for mutually-exclusive minidump handling. Ensures |
| 21 // synchronized access among instances of this class to the minidumps directory | 22 // synchronized access among instances of this class to the minidumps directory |
| (...skipping 25 matching lines...) Expand all Loading... |
| 47 class SynchronizedMinidumpManager { | 48 class SynchronizedMinidumpManager { |
| 48 public: | 49 public: |
| 49 // Length of a ratelimit period in seconds. | 50 // Length of a ratelimit period in seconds. |
| 50 static const int kRatelimitPeriodSeconds; | 51 static const int kRatelimitPeriodSeconds; |
| 51 | 52 |
| 52 // Number of dumps allowed per period. | 53 // Number of dumps allowed per period. |
| 53 static const int kRatelimitPeriodMaxDumps; | 54 static const int kRatelimitPeriodMaxDumps; |
| 54 | 55 |
| 55 virtual ~SynchronizedMinidumpManager(); | 56 virtual ~SynchronizedMinidumpManager(); |
| 56 | 57 |
| 57 // Returns whether this object's file locking method is nonblocking or not. | |
| 58 bool non_blocking() { return non_blocking_; } | |
| 59 | |
| 60 // Sets the file locking mechansim to be nonblocking or not. | |
| 61 void set_non_blocking(bool non_blocking) { non_blocking_ = non_blocking; } | |
| 62 | |
| 63 protected: | 58 protected: |
| 64 SynchronizedMinidumpManager(); | 59 SynchronizedMinidumpManager(); |
| 65 | 60 |
| 66 // Acquires the lock, calls DoWork(), then releases the lock when DoWork() | 61 // Acquires the lock, calls DoWork(), then releases the lock when DoWork() |
| 67 // returns. Derived classes should expose a method which calls this. Returns | 62 // returns. Derived classes should expose a method which calls this. Returns |
| 68 // the status of DoWork(), or -1 if the lock was not successfully acquired. | 63 // the status of DoWork(), or -1 if the lock was not successfully acquired. |
| 69 int AcquireLockAndDoWork(); | 64 int AcquireLockAndDoWork(); |
| 70 | 65 |
| 71 // Derived classes must implement this method. It will be called from | 66 // Derived classes must implement this method. It will be called from |
| 72 // DoWorkLocked after the lock has been successfully acquired. The lockfile | 67 // DoWorkLocked after the lock has been successfully acquired. The lockfile |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // Returns true when dumps uploaded in current rate limit period is less than | 99 // Returns true when dumps uploaded in current rate limit period is less than |
| 105 // |kRatelimitPeriodMaxDumps|. Resets rate limit period if period time has | 100 // |kRatelimitPeriodMaxDumps|. Resets rate limit period if period time has |
| 106 // elapsed. | 101 // elapsed. |
| 107 bool CanUploadDump(); | 102 bool CanUploadDump(); |
| 108 | 103 |
| 109 // Returns true when there are dumps in the lockfile or extra files in the | 104 // Returns true when there are dumps in the lockfile or extra files in the |
| 110 // dump directory, false otherwise. | 105 // dump directory, false otherwise. |
| 111 // Used to avoid unnecessary file locks in consumers. | 106 // Used to avoid unnecessary file locks in consumers. |
| 112 bool HasDumps(); | 107 bool HasDumps(); |
| 113 | 108 |
| 114 // If true, the flock on the lockfile will be nonblocking. | |
| 115 bool non_blocking_; | |
| 116 | |
| 117 // Cached path for the minidumps directory. | 109 // Cached path for the minidumps directory. |
| 118 const base::FilePath dump_path_; | 110 const base::FilePath dump_path_; |
| 119 | 111 |
| 120 private: | 112 private: |
| 121 // Acquire the lock file. Blocks if another process holds it, or if called | 113 // Acquire the lock file. Blocks if another process holds it, or if called |
| 122 // a second time by the same process. Returns the fd of the lockfile if | 114 // a second time by the same process. Returns the fd of the lockfile if |
| 123 // successful, or -1 if failed. | 115 // successful, or -1 if failed. |
| 124 int AcquireLockFile(); | 116 int AcquireLockFile(); |
| 125 | 117 |
| 126 // Parse the lockfile and metadata file, populating |dumps_| and |metadata_| | 118 // Parse the lockfile and metadata file, populating |dumps_| and |metadata_| |
| 127 // for modifier functions to use. Return -1 if an error occurred. Otherwise, | 119 // for modifier functions to use. Return -1 if an error occurred. Otherwise, |
| 128 // return 0. This must not be called unless |this| has acquired the lock. | 120 // return 0. This must not be called unless |this| has acquired the lock. |
| 129 int ParseFiles(); | 121 int ParseFiles(); |
| 130 | 122 |
| 131 // Write deserialized |dumps| to |lockfile_path_| and the deserialized | 123 // Write deserialized |dumps| to |lockfile_path_| and the deserialized |
| 132 // |metadata| to |metadata_path_|. | 124 // |metadata| to |metadata_path_|. |
| 133 int WriteFiles(const base::ListValue* dumps, const base::Value* metadata); | 125 int WriteFiles(const base::ListValue* dumps, const base::Value* metadata); |
| 134 | 126 |
| 135 // Creates an empty lock file and an initialized metadata file. | 127 // Creates an empty lock file and an initialized metadata file. |
| 136 int InitializeFiles(); | 128 int InitializeFiles(); |
| 137 | 129 |
| 138 // Release the lock file with the associated *fd*. | 130 // Release the lock file with the associated *fd*. |
| 139 void ReleaseLockFile(); | 131 void ReleaseLockFile(); |
| 140 | 132 |
| 141 const std::string lockfile_path_; | 133 const base::FilePath lockfile_path_; |
| 142 const std::string metadata_path_; | 134 const base::FilePath metadata_path_; |
| 143 int lockfile_fd_; | 135 bool lock_held_; |
| 144 std::unique_ptr<base::Value> metadata_; | 136 std::unique_ptr<base::Value> metadata_; |
| 145 std::unique_ptr<base::ListValue> dumps_; | 137 std::unique_ptr<base::ListValue> dumps_; |
| 146 | 138 |
| 147 DISALLOW_COPY_AND_ASSIGN(SynchronizedMinidumpManager); | 139 DISALLOW_COPY_AND_ASSIGN(SynchronizedMinidumpManager); |
| 148 }; | 140 }; |
| 149 | 141 |
| 150 } // namespace chromecast | 142 } // namespace chromecast |
| 151 | 143 |
| 152 #endif // CHROMECAST_CRASH_LINUX_SYNCHRONIZED_MINIDUMP_MANAGER_H_ | 144 #endif // CHROMECAST_CRASH_LINUX_SYNCHRONIZED_MINIDUMP_MANAGER_H_ |
| OLD | NEW |