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

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

Issue 1154383006: Adding crash utilities to chromecast/crash. (Closed) Base URL: https://eureka-internal.googlesource.com/chromium/src@master
Patch Set: 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
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_MANAGER_H_
6 #define CHROMECAST_CRASH_LINUX_MINIDUMP_MANAGER_H_
7
8 #include <string>
9
10 #include "base/files/file_path.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_vector.h"
13
14 namespace chromecast {
15
16 class DumpInfo;
17
18 // Abstract class for minidump handling. Ensures synchronized access to the
19 // minidumps directory using a lock on a file. The "lockfile" holds serialized
20 // metadata about each of the minidumps in the directory. Derived classes should
21 // not read of write to this file. Instead, use protected methods to query and
22 // modify the metadata, but only within the implementation of DoWork().
23 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
24 public:
25 virtual ~MinidumpManager();
26
27 // Acquires file lock, calls doWork(), then releases file lock.
28 // Returns the status of doWork(), or -1 if the lock could not be acquired.
29 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
30
31 // Returns whether this object's file locking method is nonblocking or not.
32 bool nonblocking() { return nonblocking_; }
alokp 2015/06/15 17:51:49 nit: non_blocking.
slan 2015/06/16 14:57:49 Done.
33
34 // Sets the file locking mechansim to be nonblocking or not.
35 void SetNonblocking(bool nonblocking) { nonblocking_ = nonblocking; }
alokp 2015/06/15 17:51:49 set_non_blocking
slan 2015/06/16 14:57:49 Done.
36
37 protected:
38 MinidumpManager();
39
40 // Overriden by child classes doing a specific operation to minidumps
41 virtual int DoWork() = 0;
42
43 // Access the container holding all the metadata for the dumps. Note that
44 // the child class mucst only call this inside DoWork(). This is lazy. If the
45 // lockfile has not been parsed yet, it will be parsed when this is called.
46 const ScopedVector<DumpInfo>& GetDumpMetadata();
47
48 // Serialize |dump_info| and append it to the lockfile. Note that the child
49 // class must only call this inside DoWork(). This should be the only method
50 // used to write to the lockfile. Only call this if the minidump has been
51 // generated in the minidumps directory successfully.
52 // Returns 0 on success, -1 otherwise.
53 int AddEntryToLockFile(const DumpInfo& dump_info);
54
55 // Remove the lockfile entry at |index| in the container returned by
56 // GetDumpMetadata(). If the index is invalid or an IO error occurred, returns
57 // -1. Otherwise returns 0. When this function returns, both the in-memory
58 // containter returned by GetDumpMetadata and the persistent lockfile are
59 // current.
60 int RemoveEntryFromLockFile(int index);
61
62 // Get the number of un-uploaded dumps in the dump_path directory.
63 // If delete_all_dumps is true, also delete all these files, this is used to
64 // clean lingering dump files.
65 int GetNumDumps(bool delete_all_dumps);
66
67 // TODO(slan): Remove this accessor. All I/O on the lockfile in inherited
68 // classes should be done via GetDumpMetadata(), AddEntryToLockFile(), and
69 // RemoveEntryFromLockFile().
70 const std::string& lockfile_path() { return lockfile_path_; }
71
72 // If true, the flock on the lockfile will be nonblocking
73 bool nonblocking_;
74
75 // Cached path for the minidumps directory.
76 base::FilePath dump_path_;
77
78 private:
79 // Acquire the lock file. Blocks if another process holds it, or if called
80 // a second time by the same process. Returns the fd of the lockfile if
81 // successful, or -1 if failed.
82 int AcquireLockFile();
83
84 // Parse the lockfile, populating |dumps_| for descendants to use. Return -1
85 // if an error occurred. Otherwise, return 0. This must not be called unless
86 // |this| has acquired the lock.
87 int ParseLockFile();
88
89 // Release the lock file with the associated *fd*.
90 void ReleaseLockFile();
91
92 std::string lockfile_path_;
93 int lockfile_fd_;
94 scoped_ptr<ScopedVector<DumpInfo> > dump_metadata_;
95
96 DISALLOW_COPY_AND_ASSIGN(MinidumpManager);
97 };
98
99 } // namespace chromecast
100
101 #endif // CHROMECAST_CRASH_LINUX_MINIDUMP_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698