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

Unified 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: Tag inside, no info spam 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « client/crash_report_database_win.cc ('k') | client/settings.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/settings.h
diff --git a/client/settings.h b/client/settings.h
index bab5186a5351374f5c0449a54c6cd61605b56d95..61e18c4339e69628ffb76363eb2205dceb783c0e 100644
--- a/client/settings.h
+++ b/client/settings.h
@@ -21,12 +21,22 @@
#include "base/basictypes.h"
#include "base/files/file_path.h"
+#include "base/scoped_generic.h"
#include "util/file/file_io.h"
#include "util/misc/initialization_state_dcheck.h"
#include "util/misc/uuid.h"
namespace crashpad {
+namespace internal {
+
+struct ScopedLockedFileHandleTraits {
+ static FileHandle InvalidValue();
+ static void Free(FileHandle handle);
+};
+
+} // namespace internal
+
//! \brief An interface for accessing and modifying the settings of a
//! CrashReportDatabase.
//!
@@ -95,13 +105,21 @@ class Settings {
private:
struct Data;
+ // This must be constructed with MakeScopedLockedFileHandle(). It both unlocks
+ // and closes the file on destruction.
+ using ScopedLockedFileHandle =
+ base::ScopedGeneric<FileHandle,
+ internal::ScopedLockedFileHandleTraits>;
+ static ScopedLockedFileHandle MakeScopedLockedFileHandle(FileHandle file,
+ FileLocking locking);
+
// Opens the settings file for reading. On error, logs a message and returns
// the invalid handle.
- ScopedFileHandle OpenForReading();
+ ScopedLockedFileHandle OpenForReading();
// Opens the settings file for reading and writing. On error, logs a message
// and returns the invalid handle.
- ScopedFileHandle OpenForReadingAndWriting();
+ ScopedLockedFileHandle OpenForReadingAndWriting();
// Opens the settings file and reads the data. If that fails, an error will
// be logged and the settings will be recovered and re-initialized. If that
@@ -111,7 +129,7 @@ class Settings {
// Opens the settings file for writing and reads the data. If reading fails,
// recovery is attempted. Returns the opened file handle on success, or the
// invalid file handle on failure, with an error logged.
- ScopedFileHandle OpenForWritingAndReadSettings(Data* out_data);
+ ScopedLockedFileHandle OpenForWritingAndReadSettings(Data* out_data);
// Reads the settings from |handle|. Logs an error and returns false on
// failure. This does not perform recovery.
« no previous file with comments | « client/crash_report_database_win.cc ('k') | client/settings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698