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

Side by Side Diff: base/files/important_file_writer.h

Issue 2920223002: Add additional histograms with suffixes to ImportantFileWriter. (Closed)
Patch Set: Fix histogram suffix to use string reference instead of StringPiece. 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 | base/files/important_file_writer.cc » ('j') | base/files/important_file_writer.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 BASE_FILES_IMPORTANT_FILE_WRITER_H_ 5 #ifndef BASE_FILES_IMPORTANT_FILE_WRITER_H_
6 #define BASE_FILES_IMPORTANT_FILE_WRITER_H_ 6 #define BASE_FILES_IMPORTANT_FILE_WRITER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // ImportantFileWriter has been created. 46 // ImportantFileWriter has been created.
47 virtual bool SerializeData(std::string* data) = 0; 47 virtual bool SerializeData(std::string* data) = 0;
48 48
49 protected: 49 protected:
50 virtual ~DataSerializer() {} 50 virtual ~DataSerializer() {}
51 }; 51 };
52 52
53 // Save |data| to |path| in an atomic manner. Blocks and writes data on the 53 // Save |data| to |path| in an atomic manner. Blocks and writes data on the
54 // current thread. Does not guarantee file integrity across system crash (see 54 // current thread. Does not guarantee file integrity across system crash (see
55 // the class comment above). 55 // the class comment above).
56 static bool WriteFileAtomically(const FilePath& path, StringPiece data); 56 static bool WriteFileAtomically(
57 const FilePath& path,
58 StringPiece data,
59 const std::string& histogram_suffix = std::string());
dcheng 2017/06/19 20:27:55 OK, I misread the code and thought this was an int
xaerox 2017/06/20 04:21:00 Done.
57 60
58 // Initialize the writer. 61 // Initialize the writer.
59 // |path| is the name of file to write. 62 // |path| is the name of file to write.
60 // |task_runner| is the SequencedTaskRunner instance where on which we will 63 // |task_runner| is the SequencedTaskRunner instance where on which we will
61 // execute file I/O operations. 64 // execute file I/O operations.
62 // All non-const methods, ctor and dtor must be called on the same thread. 65 // All non-const methods, ctor and dtor must be called on the same thread.
63 ImportantFileWriter(const FilePath& path, 66 ImportantFileWriter(const FilePath& path,
64 scoped_refptr<SequencedTaskRunner> task_runner); 67 scoped_refptr<SequencedTaskRunner> task_runner,
68 const char* histogram_suffix = nullptr);
65 69
66 // Same as above, but with a custom commit interval. 70 // Same as above, but with a custom commit interval.
67 ImportantFileWriter(const FilePath& path, 71 ImportantFileWriter(const FilePath& path,
68 scoped_refptr<SequencedTaskRunner> task_runner, 72 scoped_refptr<SequencedTaskRunner> task_runner,
69 TimeDelta interval); 73 TimeDelta interval,
74 const char* histogram_suffix = nullptr);
70 75
71 // You have to ensure that there are no pending writes at the moment 76 // You have to ensure that there are no pending writes at the moment
72 // of destruction. 77 // of destruction.
73 ~ImportantFileWriter(); 78 ~ImportantFileWriter();
74 79
75 const FilePath& path() const { return path_; } 80 const FilePath& path() const { return path_; }
76 81
77 // Returns true if there is a scheduled write pending which has not yet 82 // Returns true if there is a scheduled write pending which has not yet
78 // been started. 83 // been started.
79 bool HasPendingWrite() const; 84 bool HasPendingWrite() const;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 141
137 // An override for |timer_| used for testing. 142 // An override for |timer_| used for testing.
138 Timer* timer_override_ = nullptr; 143 Timer* timer_override_ = nullptr;
139 144
140 // Serializer which will provide the data to be saved. 145 // Serializer which will provide the data to be saved.
141 DataSerializer* serializer_; 146 DataSerializer* serializer_;
142 147
143 // Time delta after which scheduled data will be written to disk. 148 // Time delta after which scheduled data will be written to disk.
144 const TimeDelta commit_interval_; 149 const TimeDelta commit_interval_;
145 150
151 // Custom histogram suffix.
152 const std::string histogram_suffix_;
153
146 SEQUENCE_CHECKER(sequence_checker_); 154 SEQUENCE_CHECKER(sequence_checker_);
147 155
148 WeakPtrFactory<ImportantFileWriter> weak_factory_; 156 WeakPtrFactory<ImportantFileWriter> weak_factory_;
149 157
150 DISALLOW_COPY_AND_ASSIGN(ImportantFileWriter); 158 DISALLOW_COPY_AND_ASSIGN(ImportantFileWriter);
151 }; 159 };
152 160
153 } // namespace base 161 } // namespace base
154 162
155 #endif // BASE_FILES_IMPORTANT_FILE_WRITER_H_ 163 #endif // BASE_FILES_IMPORTANT_FILE_WRITER_H_
OLDNEW
« no previous file with comments | « no previous file | base/files/important_file_writer.cc » ('j') | base/files/important_file_writer.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698