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

Side by Side Diff: client/settings.h

Issue 999953002: Use LockFile/UnlockFile for Settings to port to Windows (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@lock-fileio-2
Patch Set: update c_r_d_w Created 5 years, 8 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 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/move.h"
Robert Sesek 2015/04/17 21:33:36 Needed?
scottmg 2015/04/20 18:20:41 Done.
25 #include "base/scoped_generic.h"
24 #include "util/file/file_io.h" 26 #include "util/file/file_io.h"
25 #include "util/misc/initialization_state_dcheck.h" 27 #include "util/misc/initialization_state_dcheck.h"
26 #include "util/misc/uuid.h" 28 #include "util/misc/uuid.h"
27 29
28 namespace crashpad { 30 namespace crashpad {
29 31
32 namespace internal {
33
34 struct ScopedLockedFileHandleTraits {
35 static FileHandle InvalidValue();
36 static void Free(FileHandle handle);
37 };
38
39 } // namespace internal
40
30 //! \brief An interface for accessing and modifying the settings of a 41 //! \brief An interface for accessing and modifying the settings of a
31 //! CrashReportDatabase. 42 //! CrashReportDatabase.
32 //! 43 //!
33 //! This class must not be instantiated directly, but rather an instance of it 44 //! This class must not be instantiated directly, but rather an instance of it
34 //! should be retrieved via CrashReportDatabase::GetSettings(). 45 //! should be retrieved via CrashReportDatabase::GetSettings().
35 class Settings { 46 class Settings {
36 public: 47 public:
37 explicit Settings(const base::FilePath& file_path); 48 explicit Settings(const base::FilePath& file_path);
38 ~Settings(); 49 ~Settings();
39 50
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 //! 99 //!
89 //! \param[in] time The last time at which a report was uploaded. 100 //! \param[in] time The last time at which a report was uploaded.
90 //! 101 //!
91 //! \return On success, returns `true`, otherwise returns `false` with an 102 //! \return On success, returns `true`, otherwise returns `false` with an
92 //! error logged. 103 //! error logged.
93 bool SetLastUploadAttemptTime(time_t time); 104 bool SetLastUploadAttemptTime(time_t time);
94 105
95 private: 106 private:
96 struct Data; 107 struct Data;
97 108
109 // This must be constructed with MakeScopedLockedFileHandle(). It both unlocks
110 // and closes the file on destruction.
111 using ScopedLockedFileHandle =
112 base::ScopedGeneric<FileHandle,
113 internal::ScopedLockedFileHandleTraits>;
114 static ScopedLockedFileHandle MakeScopedLockedFileHandle(FileHandle file,
115 FileLocking locking);
116
98 // Opens the settings file for reading. On error, logs a message and returns 117 // Opens the settings file for reading. On error, logs a message and returns
99 // the invalid handle. 118 // the invalid handle.
100 ScopedFileHandle OpenForReading(); 119 ScopedLockedFileHandle OpenForReading();
101 120
102 // Opens the settings file for reading and writing. On error, logs a message 121 // Opens the settings file for reading and writing. On error, logs a message
103 // and returns the invalid handle. 122 // and returns the invalid handle.
104 ScopedFileHandle OpenForReadingAndWriting(); 123 ScopedLockedFileHandle OpenForReadingAndWriting();
105 124
106 // Opens the settings file and reads the data. If that fails, an error will 125 // Opens the settings file and reads the data. If that fails, an error will
107 // be logged and the settings will be recovered and re-initialized. If that 126 // be logged and the settings will be recovered and re-initialized. If that
108 // also fails, returns false with additional log data from recovery. 127 // also fails, returns false with additional log data from recovery.
109 bool OpenAndReadSettings(Data* out_data); 128 bool OpenAndReadSettings(Data* out_data);
110 129
111 // Opens the settings file for writing and reads the data. If reading fails, 130 // Opens the settings file for writing and reads the data. If reading fails,
112 // recovery is attempted. Returns the opened file handle on success, or the 131 // recovery is attempted. Returns the opened file handle on success, or the
113 // invalid file handle on failure, with an error logged. 132 // invalid file handle on failure, with an error logged.
114 ScopedFileHandle OpenForWritingAndReadSettings(Data* out_data); 133 ScopedLockedFileHandle OpenForWritingAndReadSettings(Data* out_data);
115 134
116 // Reads the settings from |handle|. Logs an error and returns false on 135 // Reads the settings from |handle|. Logs an error and returns false on
117 // failure. This does not perform recovery. 136 // failure. This does not perform recovery.
118 bool ReadSettings(FileHandle handle, Data* out_data); 137 bool ReadSettings(FileHandle handle, Data* out_data);
119 138
120 // Writes the settings to |handle|. Logs an error and returns false on 139 // Writes the settings to |handle|. Logs an error and returns false on
121 // failure. This does not perform recovery. 140 // failure. This does not perform recovery.
122 bool WriteSettings(FileHandle handle, const Data& data); 141 bool WriteSettings(FileHandle handle, const Data& data);
123 142
124 // Recovers the settings file by re-initializing the data. If |handle| is the 143 // Recovers the settings file by re-initializing the data. If |handle| is the
(...skipping 13 matching lines...) Expand all
138 base::FilePath file_path_; 157 base::FilePath file_path_;
139 158
140 InitializationStateDcheck initialized_; 159 InitializationStateDcheck initialized_;
141 160
142 DISALLOW_COPY_AND_ASSIGN(Settings); 161 DISALLOW_COPY_AND_ASSIGN(Settings);
143 }; 162 };
144 163
145 } // namespace crashpad 164 } // namespace crashpad
146 165
147 #endif // CRASHPAD_CLIENT_SETTINGS_H_ 166 #endif // CRASHPAD_CLIENT_SETTINGS_H_
OLDNEW
« no previous file with comments | « client/crash_report_database_win.cc ('k') | client/settings.cc » ('j') | client/settings.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698