Chromium Code Reviews| Index: chromecast/crash/linux/minidump_manager.h |
| diff --git a/chromecast/crash/linux/minidump_manager.h b/chromecast/crash/linux/minidump_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..727ccf894e01c976a83579258db2fb7db6cd7875 |
| --- /dev/null |
| +++ b/chromecast/crash/linux/minidump_manager.h |
| @@ -0,0 +1,101 @@ |
| +// 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_MANAGER_H_ |
| +#define CHROMECAST_CRASH_LINUX_MINIDUMP_MANAGER_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/files/file_path.h" |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_vector.h" |
| + |
| +namespace chromecast { |
| + |
| +class DumpInfo; |
| + |
| +// Abstract class for minidump handling. Ensures synchronized access to the |
| +// minidumps directory using a lock on a file. The "lockfile" holds serialized |
| +// metadata about each of the minidumps in the directory. Derived classes should |
| +// not read of write to this file. Instead, use protected methods to query and |
| +// modify the metadata, but only within the implementation of DoWork(). |
| +class MinidumpManager { |
|
alokp
2015/06/15 17:51:49
It is not clear from the class name what this clas
slan
2015/06/16 14:57:49
Renamed to SynchronizedMinidumpManager
|
| + public: |
| + virtual ~MinidumpManager(); |
| + |
| + // Acquires file lock, calls doWork(), then releases file lock. |
| + // Returns the status of doWork(), or -1 if the lock could not be acquired. |
| + int DoWorkLocked(); |
|
alokp
2015/06/15 17:51:48
I would rename this to what this function actually
slan
2015/06/16 14:57:49
DoWorkLocked() is now AcquireLockAndDoWork(), a pr
|
| + |
| + // Returns whether this object's file locking method is nonblocking or not. |
| + bool nonblocking() { return nonblocking_; } |
|
alokp
2015/06/15 17:51:49
nit: non_blocking.
slan
2015/06/16 14:57:49
Done.
|
| + |
| + // Sets the file locking mechansim to be nonblocking or not. |
| + void SetNonblocking(bool nonblocking) { nonblocking_ = nonblocking; } |
|
alokp
2015/06/15 17:51:49
set_non_blocking
slan
2015/06/16 14:57:49
Done.
|
| + |
| + protected: |
| + MinidumpManager(); |
| + |
| + // Overriden by child classes doing a specific operation to minidumps |
| + virtual int DoWork() = 0; |
| + |
| + // Access the container holding all the metadata for the dumps. Note that |
| + // the child class mucst only call this inside DoWork(). This is lazy. If the |
| + // lockfile has not been parsed yet, it will be parsed when this is called. |
| + const ScopedVector<DumpInfo>& GetDumpMetadata(); |
| + |
| + // Serialize |dump_info| and append it to the lockfile. Note that the child |
| + // class must only call this inside DoWork(). This should be the only method |
| + // used to write to the lockfile. Only call this if the minidump has been |
| + // generated in the minidumps directory successfully. |
| + // Returns 0 on success, -1 otherwise. |
| + int AddEntryToLockFile(const DumpInfo& dump_info); |
| + |
| + // Remove the lockfile entry at |index| in the container returned by |
| + // GetDumpMetadata(). If the index is invalid or an IO error occurred, returns |
| + // -1. Otherwise returns 0. When this function returns, both the in-memory |
| + // containter returned by GetDumpMetadata and the persistent lockfile are |
| + // current. |
| + int RemoveEntryFromLockFile(int index); |
| + |
| + // Get the number of un-uploaded dumps in the dump_path directory. |
| + // If delete_all_dumps is true, also delete all these files, this is used to |
| + // clean lingering dump files. |
| + int GetNumDumps(bool delete_all_dumps); |
| + |
| + // TODO(slan): Remove this accessor. All I/O on the lockfile in inherited |
| + // classes should be done via GetDumpMetadata(), AddEntryToLockFile(), and |
| + // RemoveEntryFromLockFile(). |
| + const std::string& lockfile_path() { return lockfile_path_; } |
| + |
| + // If true, the flock on the lockfile will be nonblocking |
| + bool nonblocking_; |
| + |
| + // Cached path for the minidumps directory. |
| + base::FilePath dump_path_; |
| + |
| + private: |
| + // Acquire the lock file. Blocks if another process holds it, or if called |
| + // a second time by the same process. Returns the fd of the lockfile if |
| + // successful, or -1 if failed. |
| + int AcquireLockFile(); |
| + |
| + // Parse the lockfile, populating |dumps_| for descendants to use. Return -1 |
| + // if an error occurred. Otherwise, return 0. This must not be called unless |
| + // |this| has acquired the lock. |
| + int ParseLockFile(); |
| + |
| + // Release the lock file with the associated *fd*. |
| + void ReleaseLockFile(); |
| + |
| + std::string lockfile_path_; |
| + int lockfile_fd_; |
| + scoped_ptr<ScopedVector<DumpInfo> > dump_metadata_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MinidumpManager); |
| +}; |
| + |
| +} // namespace chromecast |
| + |
| +#endif // CHROMECAST_CRASH_LINUX_MINIDUMP_MANAGER_H_ |