| Index: client/settings.h
|
| diff --git a/client/settings.h b/client/settings.h
|
| index bab5186a5351374f5c0449a54c6cd61605b56d95..f528bc1c6659dd959c0ec60eb0f17749fb26ad98 100644
|
| --- a/client/settings.h
|
| +++ b/client/settings.h
|
| @@ -21,6 +21,7 @@
|
|
|
| #include "base/basictypes.h"
|
| #include "base/files/file_path.h"
|
| +#include "base/move.h"
|
| #include "util/file/file_io.h"
|
| #include "util/misc/initialization_state_dcheck.h"
|
| #include "util/misc/uuid.h"
|
| @@ -95,13 +96,37 @@ class Settings {
|
| private:
|
| struct Data;
|
|
|
| + class ScopedLockedFileHandle {
|
| + MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(ScopedLockedFileHandle)
|
| +
|
| + public:
|
| + ScopedLockedFileHandle();
|
| + ScopedLockedFileHandle(FileHandle file, FileLocking locking);
|
| + ScopedLockedFileHandle(ScopedLockedFileHandle&& rvalue)
|
| + : handle_(rvalue.handle_.release()) {}
|
| + ScopedLockedFileHandle& operator=(ScopedLockedFileHandle&& rvalue) {
|
| + handle_.reset(rvalue.handle_.release());
|
| + return *this;
|
| + }
|
| + ~ScopedLockedFileHandle();
|
| +
|
| + FileHandle get() { return handle_.get(); }
|
| + bool is_valid() const { return handle_.is_valid(); }
|
| + void reset();
|
| +
|
| + private:
|
| + void FreeIfNecessary();
|
| +
|
| + ScopedFileHandle handle_;
|
| + };
|
| +
|
| // 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 +136,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.
|
|
|