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

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

Issue 1310313004: [Chromecast] Move SynchronizedMinidumpManager ratelimit logic to child classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Revert SynchronizedMinidumpManagerSimple name. Created 5 years, 3 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> 8 #include <time.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 28 matching lines...) Expand all
39 // that producers to this file do not need to understand json. 39 // that producers to this file do not need to understand json.
40 // 40 //
41 // Current external producers: 41 // Current external producers:
42 // + watchdog 42 // + watchdog
43 // 43 //
44 // 44 //
45 // The metadata file is a separate file containing a json dictionary. 45 // The metadata file is a separate file containing a json dictionary.
46 // 46 //
47 class SynchronizedMinidumpManager { 47 class SynchronizedMinidumpManager {
48 public: 48 public:
49 // Max number of dumps allowed in lockfile.
50 static const int kMaxLockfileDumps;
51
52 // Length of a ratelimit period in seconds. 49 // Length of a ratelimit period in seconds.
53 static const int kRatelimitPeriodSeconds; 50 static const int kRatelimitPeriodSeconds;
54 51
55 // Number of dumps allowed per period. 52 // Number of dumps allowed per period.
56 static const int kRatelimitPeriodMaxDumps; 53 static const int kRatelimitPeriodMaxDumps;
57 54
58 virtual ~SynchronizedMinidumpManager(); 55 virtual ~SynchronizedMinidumpManager();
59 56
60 // Returns whether this object's file locking method is nonblocking or not. 57 // Returns whether this object's file locking method is nonblocking or not.
61 bool non_blocking() { return non_blocking_; } 58 bool non_blocking() { return non_blocking_; }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // Remove the lockfile entry at |index| in the current in memory 90 // Remove the lockfile entry at |index| in the current in memory
94 // representation of the lockfile. If the index is invalid returns -1. 91 // representation of the lockfile. If the index is invalid returns -1.
95 // Otherwise returns 0. 92 // Otherwise returns 0.
96 int RemoveEntryFromLockFile(int index); 93 int RemoveEntryFromLockFile(int index);
97 94
98 // Get the number of un-uploaded dumps in the dump_path directory. 95 // Get the number of un-uploaded dumps in the dump_path directory.
99 // If delete_all_dumps is true, also delete all these files, this is used to 96 // If delete_all_dumps is true, also delete all these files, this is used to
100 // clean lingering dump files. 97 // clean lingering dump files.
101 int GetNumDumps(bool delete_all_dumps); 98 int GetNumDumps(bool delete_all_dumps);
102 99
100 // Increment the number of dumps in the current ratelimit period.
101 // Returns 0 on success, < 0 on error.
102 int IncrementRatelimitPeriodDumps();
slan 2015/09/09 19:08:11 This name is confusing to me. Perhaps IncrementNum
bcf_google 2015/09/09 21:20:29 Done.
103
104 // Returns true when dumps uploaded in current rate limit period is less than
105 // |kRatelimitPeriodMaxDumps|. Resets rate limit period if period time has
106 // elapsed.
107 bool CanUploadDump();
108
103 // If true, the flock on the lockfile will be nonblocking. 109 // If true, the flock on the lockfile will be nonblocking.
104 bool non_blocking_; 110 bool non_blocking_;
105 111
106 // Cached path for the minidumps directory. 112 // Cached path for the minidumps directory.
107 const base::FilePath dump_path_; 113 const base::FilePath dump_path_;
108 114
109 private: 115 private:
110 // Acquire the lock file. Blocks if another process holds it, or if called 116 // Acquire the lock file. Blocks if another process holds it, or if called
111 // a second time by the same process. Returns the fd of the lockfile if 117 // a second time by the same process. Returns the fd of the lockfile if
112 // successful, or -1 if failed. 118 // successful, or -1 if failed.
113 int AcquireLockFile(); 119 int AcquireLockFile();
114 120
115 // Parse the lockfile and metadata file, populating |dumps_| and |metadata_| 121 // Parse the lockfile and metadata file, populating |dumps_| and |metadata_|
116 // for modifier functions to use. Return -1 if an error occurred. Otherwise, 122 // for modifier functions to use. Return -1 if an error occurred. Otherwise,
117 // return 0. This must not be called unless |this| has acquired the lock. 123 // return 0. This must not be called unless |this| has acquired the lock.
118 int ParseFiles(); 124 int ParseFiles();
119 125
120 // Write deserialized |dumps| to |lockfile_path_| and the deserialized 126 // Write deserialized |dumps| to |lockfile_path_| and the deserialized
121 // |metadata| to |metadata_path_|. 127 // |metadata| to |metadata_path_|.
122 int WriteFiles(const base::ListValue* dumps, const base::Value* metadata); 128 int WriteFiles(const base::ListValue* dumps, const base::Value* metadata);
123 129
124 // Creates an empty lock file and an initialized metadata file. 130 // Creates an empty lock file and an initialized metadata file.
125 int InitializeFiles(); 131 int InitializeFiles();
126 132
127 // Release the lock file with the associated *fd*. 133 // Release the lock file with the associated *fd*.
128 void ReleaseLockFile(); 134 void ReleaseLockFile();
129 135
130 // Returns true if |num_dumps| can be written to the lockfile. We can write
131 // the dumps if the number of dumps in the lockfile after |num_dumps| is added
132 // is less than or equal to |kMaxLockfileDumps| and the number of dumps in the
133 // current ratelimit period after |num_dumps| is added is less than or equal
134 // to |kRatelimitPeriodMaxDumps|.
135 bool CanWriteDumps(int num_dumps);
136
137 const std::string lockfile_path_; 136 const std::string lockfile_path_;
138 const std::string metadata_path_; 137 const std::string metadata_path_;
139 int lockfile_fd_; 138 int lockfile_fd_;
140 scoped_ptr<base::Value> metadata_; 139 scoped_ptr<base::Value> metadata_;
141 scoped_ptr<base::ListValue> dumps_; 140 scoped_ptr<base::ListValue> dumps_;
142 141
143 DISALLOW_COPY_AND_ASSIGN(SynchronizedMinidumpManager); 142 DISALLOW_COPY_AND_ASSIGN(SynchronizedMinidumpManager);
144 }; 143 };
145 144
146 } // namespace chromecast 145 } // namespace chromecast
147 146
148 #endif // CHROMECAST_CRASH_LINUX_SYNCHRONIZED_MINIDUMP_MANAGER_H_ 147 #endif // CHROMECAST_CRASH_LINUX_SYNCHRONIZED_MINIDUMP_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698