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

Side by Side Diff: webrtc/base/filerotatingstream.h

Issue 2935933007: Delete class DirectoryIterator and FileRotatingStream read support. (Closed)
Patch Set: Drop an RTC_NOTREACHED. Created 3 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
« no previous file with comments | « no previous file | webrtc/base/filerotatingstream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2015 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 void SetMaxFileSize(size_t size) { max_file_size_ = size; } 76 void SetMaxFileSize(size_t size) { max_file_size_ = size; }
77 77
78 size_t GetRotationIndex() const { return rotation_index_; } 78 size_t GetRotationIndex() const { return rotation_index_; }
79 79
80 void SetRotationIndex(size_t index) { rotation_index_ = index; } 80 void SetRotationIndex(size_t index) { rotation_index_ = index; }
81 81
82 virtual void OnRotation() {} 82 virtual void OnRotation() {}
83 83
84 private: 84 private:
85 enum Mode { kRead, kWrite };
86
87 FileRotatingStream(const std::string& dir_path,
88 const std::string& file_prefix,
89 size_t max_file_size,
90 size_t num_files,
91 Mode mode);
92
93 bool OpenCurrentFile(); 85 bool OpenCurrentFile();
94 void CloseCurrentFile(); 86 void CloseCurrentFile();
95 87
96 // Rotates the files by creating a new current file, renaming the 88 // Rotates the files by creating a new current file, renaming the
97 // existing files, and deleting the oldest one. e.g. 89 // existing files, and deleting the oldest one. e.g.
98 // file_0 -> file_1 90 // file_0 -> file_1
99 // file_1 -> file_2 91 // file_1 -> file_2
100 // file_2 -> delete 92 // file_2 -> delete
101 // create new file_0 93 // create new file_0
102 void RotateFiles(); 94 void RotateFiles();
103 95
104 // Returns a list of file names in the directory beginning with the prefix. 96 // Returns a list of file names in the directory beginning with the prefix.
105 std::vector<std::string> GetFilesWithPrefix() const; 97 std::vector<std::string> GetFilesWithPrefix() const;
106 // Private version of GetFilePath. 98 // Private version of GetFilePath.
107 std::string GetFilePath(size_t index, size_t num_files) const; 99 std::string GetFilePath(size_t index, size_t num_files) const;
108 100
109 const std::string dir_path_; 101 const std::string dir_path_;
110 const std::string file_prefix_; 102 const std::string file_prefix_;
111 const Mode mode_;
112 103
113 // FileStream is used to write to the current file. 104 // FileStream is used to write to the current file.
114 std::unique_ptr<FileStream> file_stream_; 105 std::unique_ptr<FileStream> file_stream_;
115 // Convenience storage for file names so we don't generate them over and over. 106 // Convenience storage for file names so we don't generate them over and over.
116 std::vector<std::string> file_names_; 107 std::vector<std::string> file_names_;
117 size_t max_file_size_; 108 size_t max_file_size_;
118 size_t current_file_index_; 109 size_t current_file_index_;
119 // The rotation index indicates the index of the file that will be 110 // The rotation index indicates the index of the file that will be
120 // deleted first on rotation. Indices lower than this index will be rotated. 111 // deleted first on rotation. Indices lower than this index will be rotated.
121 size_t rotation_index_; 112 size_t rotation_index_;
(...skipping 14 matching lines...) Expand all
136 // 127 //
137 // This implementation simply writes to a single file until 128 // This implementation simply writes to a single file until
138 // |max_total_log_size| / 2 bytes are written to it, and subsequently writes to 129 // |max_total_log_size| / 2 bytes are written to it, and subsequently writes to
139 // a set of rotating files. We do this by inheriting FileRotatingStream and 130 // a set of rotating files. We do this by inheriting FileRotatingStream and
140 // setting the appropriate internal variables so that we don't delete the last 131 // setting the appropriate internal variables so that we don't delete the last
141 // (earliest) file on rotate, and that that file's size is bigger. 132 // (earliest) file on rotate, and that that file's size is bigger.
142 // 133 //
143 // Open() must be called before using this stream. 134 // Open() must be called before using this stream.
144 class CallSessionFileRotatingStream : public FileRotatingStream { 135 class CallSessionFileRotatingStream : public FileRotatingStream {
145 public: 136 public:
146 // Use this constructor for reading a directory previously written to with
147 // this stream.
148 explicit CallSessionFileRotatingStream(const std::string& dir_path);
149 // Use this constructor for writing to a directory. Files in the directory 137 // Use this constructor for writing to a directory. Files in the directory
150 // matching what's used by the stream will be deleted. |max_total_log_size| 138 // matching what's used by the stream will be deleted. |max_total_log_size|
151 // must be at least 4. 139 // must be at least 4.
152 CallSessionFileRotatingStream(const std::string& dir_path, 140 CallSessionFileRotatingStream(const std::string& dir_path,
153 size_t max_total_log_size); 141 size_t max_total_log_size);
154 ~CallSessionFileRotatingStream() override {} 142 ~CallSessionFileRotatingStream() override {}
155 143
156 protected: 144 protected:
157 void OnRotation() override; 145 void OnRotation() override;
158 146
159 private: 147 private:
160 static size_t GetRotatingLogSize(size_t max_total_log_size); 148 static size_t GetRotatingLogSize(size_t max_total_log_size);
161 static size_t GetNumRotatingLogFiles(size_t max_total_log_size); 149 static size_t GetNumRotatingLogFiles(size_t max_total_log_size);
162 static const char* kLogPrefix; 150 static const char* kLogPrefix;
163 static const size_t kRotatingLogFileDefaultSize; 151 static const size_t kRotatingLogFileDefaultSize;
164 152
165 const size_t max_total_log_size_; 153 const size_t max_total_log_size_;
166 size_t num_rotations_; 154 size_t num_rotations_;
167 155
168 RTC_DISALLOW_COPY_AND_ASSIGN(CallSessionFileRotatingStream); 156 RTC_DISALLOW_COPY_AND_ASSIGN(CallSessionFileRotatingStream);
169 }; 157 };
170 158
171 } // namespace rtc 159 } // namespace rtc
172 160
173 #endif // WEBRTC_BASE_FILEROTATINGSTREAM_H_ 161 #endif // WEBRTC_BASE_FILEROTATINGSTREAM_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/base/filerotatingstream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698