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

Side by Side Diff: client/settings.h

Issue 1392953002: Don’t log an error when creating a new crash report database (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Add missing be Created 5 years, 2 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 | client/settings.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 // Copyright 2015 The Crashpad Authors. All rights reserved. 1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #ifndef CRASHPAD_CLIENT_SETTINGS_H_ 15 #ifndef CRASHPAD_CLIENT_SETTINGS_H_
16 #define CRASHPAD_CLIENT_SETTINGS_H_ 16 #define CRASHPAD_CLIENT_SETTINGS_H_
17 17
18 #include <time.h> 18 #include <time.h>
19 19
20 #include <string> 20 #include <string>
21 21
22 #include "base/basictypes.h" 22 #include "base/basictypes.h"
23 #include "base/files/file_path.h" 23 #include "base/files/file_path.h"
24 #include "base/scoped_generic.h" 24 #include "base/scoped_generic.h"
25 #include "util/file/file_io.h" 25 #include "util/file/file_io.h"
26 #include "util/misc/initialization_state_dcheck.h" 26 #include "util/misc/initialization_state.h"
27 #include "util/misc/uuid.h" 27 #include "util/misc/uuid.h"
28 28
29 namespace crashpad { 29 namespace crashpad {
30 30
31 namespace internal { 31 namespace internal {
32 32
33 struct ScopedLockedFileHandleTraits { 33 struct ScopedLockedFileHandleTraits {
34 static FileHandle InvalidValue(); 34 static FileHandle InvalidValue();
35 static void Free(FileHandle handle); 35 static void Free(FileHandle handle);
36 }; 36 };
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 //! \return On success, returns `true`, otherwise returns `false` with an 101 //! \return On success, returns `true`, otherwise returns `false` with an
102 //! error logged. 102 //! error logged.
103 bool SetLastUploadAttemptTime(time_t time); 103 bool SetLastUploadAttemptTime(time_t time);
104 104
105 private: 105 private:
106 struct Data; 106 struct Data;
107 107
108 // This must be constructed with MakeScopedLockedFileHandle(). It both unlocks 108 // This must be constructed with MakeScopedLockedFileHandle(). It both unlocks
109 // and closes the file on destruction. 109 // and closes the file on destruction.
110 using ScopedLockedFileHandle = 110 using ScopedLockedFileHandle =
111 base::ScopedGeneric<FileHandle, 111 base::ScopedGeneric<FileHandle, internal::ScopedLockedFileHandleTraits>;
112 internal::ScopedLockedFileHandleTraits>;
113 static ScopedLockedFileHandle MakeScopedLockedFileHandle(FileHandle file, 112 static ScopedLockedFileHandle MakeScopedLockedFileHandle(FileHandle file,
114 FileLocking locking); 113 FileLocking locking);
115 114
116 // Opens the settings file for reading. On error, logs a message and returns 115 // Opens the settings file for reading. On error, logs a message and returns
117 // the invalid handle. 116 // the invalid handle.
118 ScopedLockedFileHandle OpenForReading(); 117 ScopedLockedFileHandle OpenForReading();
119 118
120 // Opens the settings file for reading and writing. On error, logs a message 119 // Opens the settings file for reading and writing. On error, logs a message
121 // and returns the invalid handle. 120 // and returns the invalid handle. |mode| determines how the file will be
122 ScopedLockedFileHandle OpenForReadingAndWriting(); 121 // opened. |mode| must not be FileWriteMode::kTruncateOrCreate.
122 //
123 // If |log_open_error| is false, nothing will be logged for an error
124 // encountered when attempting to open the file, but this method will still
125 // return false. This is intended to be used to suppress error messages when
126 // attempting to create a new settings file when multiple attempts are made.
127 ScopedLockedFileHandle OpenForReadingAndWriting(FileWriteMode mode,
128 bool log_open_error);
123 129
124 // Opens the settings file and reads the data. If that fails, an error will 130 // Opens the settings file and reads the data. If that fails, an error will
125 // be logged and the settings will be recovered and re-initialized. If that 131 // be logged and the settings will be recovered and re-initialized. If that
126 // also fails, returns false with additional log data from recovery. 132 // also fails, returns false with additional log data from recovery.
127 bool OpenAndReadSettings(Data* out_data); 133 bool OpenAndReadSettings(Data* out_data);
128 134
129 // Opens the settings file for writing and reads the data. If reading fails, 135 // Opens the settings file for writing and reads the data. If reading fails,
130 // recovery is attempted. Returns the opened file handle on success, or the 136 // recovery is attempted. Returns the opened file handle on success, or the
131 // invalid file handle on failure, with an error logged. 137 // invalid file handle on failure, with an error logged.
132 ScopedLockedFileHandle OpenForWritingAndReadSettings(Data* out_data); 138 ScopedLockedFileHandle OpenForWritingAndReadSettings(Data* out_data);
133 139
134 // Reads the settings from |handle|. Logs an error and returns false on 140 // Reads the settings from |handle|. Logs an error and returns false on
135 // failure. This does not perform recovery. 141 // failure. This does not perform recovery.
136 bool ReadSettings(FileHandle handle, Data* out_data); 142 //
143 // |handle| must be the result of OpenForReading() or
144 // OpenForReadingAndWriting().
145 //
146 // If |log_read_error| is false, nothing will be logged for a read error, but
147 // this method will still return false. This is intended to be used to
148 // suppress error messages when attempting to read a newly created settings
149 // file.
150 bool ReadSettings(FileHandle handle, Data* out_data, bool log_read_error);
137 151
138 // Writes the settings to |handle|. Logs an error and returns false on 152 // Writes the settings to |handle|. Logs an error and returns false on
139 // failure. This does not perform recovery. 153 // failure. This does not perform recovery.
154 //
155 // |handle| must be the result of OpenForReadingAndWriting().
140 bool WriteSettings(FileHandle handle, const Data& data); 156 bool WriteSettings(FileHandle handle, const Data& data);
141 157
142 // Recovers the settings file by re-initializing the data. If |handle| is the 158 // Recovers the settings file by re-initializing the data. If |handle| is the
143 // invalid handle, this will open the file; if it is not, then it must be the 159 // invalid handle, this will open the file; if it is not, then it must be the
144 // result of OpenForReadingAndWriting(). If the invalid handle is passed, the 160 // result of OpenForReadingAndWriting(). If the invalid handle is passed, the
145 // caller must not be holding the handle. The new settings data are stored in 161 // caller must not be holding the handle. The new settings data are stored in
146 // |out_data|. Returns true on success and false on failure, with an error 162 // |out_data|. Returns true on success and false on failure, with an error
147 // logged. 163 // logged.
148 bool RecoverSettings(FileHandle handle, Data* out_data); 164 bool RecoverSettings(FileHandle handle, Data* out_data);
149 165
150 // Initializes a settings file and writes the data to |handle|. Returns true 166 // Initializes a settings file and writes the data to |handle|. Returns true
151 // on success and false on failure, with an error logged. 167 // on success and false on failure, with an error logged.
168 //
169 // |handle| must be the result of OpenForReadingAndWriting().
152 bool InitializeSettings(FileHandle handle); 170 bool InitializeSettings(FileHandle handle);
153 171
154 const base::FilePath& file_path() const { return file_path_; } 172 const base::FilePath& file_path() const { return file_path_; }
155 173
156 base::FilePath file_path_; 174 base::FilePath file_path_;
157 175
158 InitializationStateDcheck initialized_; 176 InitializationState initialized_;
159 177
160 DISALLOW_COPY_AND_ASSIGN(Settings); 178 DISALLOW_COPY_AND_ASSIGN(Settings);
161 }; 179 };
162 180
163 } // namespace crashpad 181 } // namespace crashpad
164 182
165 #endif // CRASHPAD_CLIENT_SETTINGS_H_ 183 #endif // CRASHPAD_CLIENT_SETTINGS_H_
OLDNEW
« no previous file with comments | « no previous file | client/settings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698