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

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

Issue 2203123003: [Chromecast] Remove usage of nonreentrant functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: slan@ comments Created 4 years, 4 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
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>
9
10 #include <string>
11
12 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
13 #include "base/macros.h" 9 #include "base/macros.h"
14 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
15 #include "base/values.h" 11 #include "base/values.h"
16 #include "chromecast/crash/linux/dump_info.h" 12 #include "chromecast/crash/linux/dump_info.h"
17 13
18 namespace chromecast { 14 namespace chromecast {
19 15
20 // Abstract base class for mutually-exclusive minidump handling. Ensures 16 // Abstract base class for mutually-exclusive minidump handling. Ensures
21 // synchronized access among instances of this class to the minidumps directory 17 // synchronized access among instances of this class to the minidumps directory
(...skipping 25 matching lines...) Expand all
47 class SynchronizedMinidumpManager { 43 class SynchronizedMinidumpManager {
48 public: 44 public:
49 // Length of a ratelimit period in seconds. 45 // Length of a ratelimit period in seconds.
50 static const int kRatelimitPeriodSeconds; 46 static const int kRatelimitPeriodSeconds;
51 47
52 // Number of dumps allowed per period. 48 // Number of dumps allowed per period.
53 static const int kRatelimitPeriodMaxDumps; 49 static const int kRatelimitPeriodMaxDumps;
54 50
55 virtual ~SynchronizedMinidumpManager(); 51 virtual ~SynchronizedMinidumpManager();
56 52
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: 53 protected:
64 SynchronizedMinidumpManager(); 54 SynchronizedMinidumpManager();
65 55
66 // Acquires the lock, calls DoWork(), then releases the lock when DoWork() 56 // Acquires the lock, calls DoWork(), then releases the lock when DoWork()
67 // returns. Derived classes should expose a method which calls this. Returns 57 // 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. 58 // the status of DoWork(), or false if the lock was not successfully acquired.
69 int AcquireLockAndDoWork(); 59 bool AcquireLockAndDoWork();
70 60
71 // Derived classes must implement this method. It will be called from 61 // Derived classes must implement this method. It will be called from
72 // DoWorkLocked after the lock has been successfully acquired. The lockfile 62 // DoWorkLocked after the lock has been successfully acquired. The lockfile
73 // shall be accessed and mutated only through the methods below. All other 63 // shall be accessed and mutated only through the methods below. All other
74 // files shall be managed as needed by the derived class. 64 // files shall be managed as needed by the derived class.
75 virtual int DoWork() = 0; 65 virtual bool DoWork() = 0;
76 66
77 // Get the current dumps in the lockfile. 67 // Get the current dumps in the lockfile.
78 ScopedVector<DumpInfo> GetDumps(); 68 ScopedVector<DumpInfo> GetDumps();
79 69
80 // Set |dumps| as the dumps in |lockfile_|, replacing current list of dumps. 70 // Set |dumps| as the dumps in |lockfile_|, replacing current list of dumps.
81 int SetCurrentDumps(const ScopedVector<DumpInfo>& dumps); 71 bool SetCurrentDumps(const ScopedVector<DumpInfo>& dumps);
82 72
83 // Serialize |dump_info| and append it to the lockfile. Note that the child 73 // Serialize |dump_info| and append it to the lockfile. Note that the child
84 // class must only call this inside DoWork(). This should be the only method 74 // class must only call this inside DoWork(). This should be the only method
85 // used to write to the lockfile. Only call this if the minidump has been 75 // used to write to the lockfile. Only call this if the minidump has been
86 // generated in the minidumps directory successfully. Returns 0 on success, 76 // generated in the minidumps directory successfully. Returns true on success,
87 // -1 otherwise. 77 // false otherwise.
88 int AddEntryToLockFile(const DumpInfo& dump_info); 78 bool AddEntryToLockFile(const DumpInfo& dump_info);
89 79
90 // Remove the lockfile entry at |index| in the current in memory 80 // Remove the lockfile entry at |index| in the current in memory
91 // representation of the lockfile. If the index is invalid returns -1. 81 // representation of the lockfile. If the index is invalid returns false,
92 // Otherwise returns 0. 82 // otherwise returns true.
93 int RemoveEntryFromLockFile(int index); 83 bool RemoveEntryFromLockFile(int index);
94 84
95 // Get the number of un-uploaded dumps in the dump_path directory. 85 // Get the number of un-uploaded dumps in the dump_path directory.
96 // If delete_all_dumps is true, also delete all these files, this is used to 86 // If delete_all_dumps is true, also delete all these files, this is used to
97 // clean lingering dump files. 87 // clean lingering dump files.
98 int GetNumDumps(bool delete_all_dumps); 88 int GetNumDumps(bool delete_all_dumps);
99 89
100 // Increment the number of dumps in the current ratelimit period. 90 // Increment the number of dumps in the current ratelimit period.
101 // Returns 0 on success, < 0 on error. 91 // Returns true on success, false on error.
102 int IncrementNumDumpsInCurrentPeriod(); 92 bool IncrementNumDumpsInCurrentPeriod();
103 93
104 // Returns true when dumps uploaded in current rate limit period is less than 94 // Returns true when dumps uploaded in current rate limit period is less than
105 // |kRatelimitPeriodMaxDumps|. Resets rate limit period if period time has 95 // |kRatelimitPeriodMaxDumps|. Resets rate limit period if period time has
106 // elapsed. 96 // elapsed.
107 bool CanUploadDump(); 97 bool CanUploadDump();
108 98
109 // Returns true when there are dumps in the lockfile or extra files in the 99 // Returns true when there are dumps in the lockfile or extra files in the
110 // dump directory, false otherwise. 100 // dump directory, false otherwise.
111 // Used to avoid unnecessary file locks in consumers. 101 // Used to avoid unnecessary file locks in consumers.
112 bool HasDumps(); 102 bool HasDumps();
113 103
114 // If true, the flock on the lockfile will be nonblocking.
115 bool non_blocking_;
116
117 // Cached path for the minidumps directory. 104 // Cached path for the minidumps directory.
118 const base::FilePath dump_path_; 105 const base::FilePath dump_path_;
119 106
120 private: 107 private:
121 // Acquire the lock file. Blocks if another process holds it, or if called 108 // 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 109 // a second time by the same process. Returns true if successful, or false
123 // successful, or -1 if failed. 110 // otherwise.
124 int AcquireLockFile(); 111 bool AcquireLockFile();
125 112
126 // Parse the lockfile and metadata file, populating |dumps_| and |metadata_| 113 // Parse the lockfile and metadata file, populating |dumps_| and |metadata_|
127 // for modifier functions to use. Return -1 if an error occurred. Otherwise, 114 // for modifier functions to use. Returns false if an error occurred,
128 // return 0. This must not be called unless |this| has acquired the lock. 115 // otherwise returns true. This must not be called unless |this| has acquired
129 int ParseFiles(); 116 // the lock.
117 bool ParseFiles();
130 118
131 // Write deserialized |dumps| to |lockfile_path_| and the deserialized 119 // Write deserialized |dumps| to |lockfile_path_| and the deserialized
132 // |metadata| to |metadata_path_|. 120 // |metadata| to |metadata_path_|.
133 int WriteFiles(const base::ListValue* dumps, const base::Value* metadata); 121 bool WriteFiles(const base::ListValue* dumps, const base::Value* metadata);
134 122
135 // Creates an empty lock file and an initialized metadata file. 123 // Creates an empty lock file and an initialized metadata file.
136 int InitializeFiles(); 124 bool InitializeFiles();
137 125
138 // Release the lock file with the associated *fd*. 126 // Release the lock file with the associated *fd*.
139 void ReleaseLockFile(); 127 void ReleaseLockFile();
140 128
141 const std::string lockfile_path_; 129 const base::FilePath lockfile_path_;
142 const std::string metadata_path_; 130 const base::FilePath metadata_path_;
143 int lockfile_fd_; 131 int lockfile_fd_;
144 std::unique_ptr<base::Value> metadata_; 132 std::unique_ptr<base::Value> metadata_;
145 std::unique_ptr<base::ListValue> dumps_; 133 std::unique_ptr<base::ListValue> dumps_;
146 134
147 DISALLOW_COPY_AND_ASSIGN(SynchronizedMinidumpManager); 135 DISALLOW_COPY_AND_ASSIGN(SynchronizedMinidumpManager);
148 }; 136 };
149 137
150 } // namespace chromecast 138 } // namespace chromecast
151 139
152 #endif // CHROMECAST_CRASH_LINUX_SYNCHRONIZED_MINIDUMP_MANAGER_H_ 140 #endif // CHROMECAST_CRASH_LINUX_SYNCHRONIZED_MINIDUMP_MANAGER_H_
OLDNEW
« no previous file with comments | « chromecast/crash/linux/minidump_writer.cc ('k') | chromecast/crash/linux/synchronized_minidump_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698