Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | |
| 24 #include "util/file/file_io.h" | 25 #include "util/file/file_io.h" |
| 25 #include "util/misc/initialization_state_dcheck.h" | 26 #include "util/misc/initialization_state_dcheck.h" |
| 26 #include "util/misc/uuid.h" | 27 #include "util/misc/uuid.h" |
| 27 | 28 |
| 28 namespace crashpad { | 29 namespace crashpad { |
| 29 | 30 |
| 30 //! \brief An interface for accessing and modifying the settings of a | 31 //! \brief An interface for accessing and modifying the settings of a |
| 31 //! CrashReportDatabase. | 32 //! CrashReportDatabase. |
| 32 //! | 33 //! |
| 33 //! This class must not be instantiated directly, but rather an instance of it | 34 //! This class must not be instantiated directly, but rather an instance of it |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 //! | 89 //! |
| 89 //! \param[in] time The last time at which a report was uploaded. | 90 //! \param[in] time The last time at which a report was uploaded. |
| 90 //! | 91 //! |
| 91 //! \return On success, returns `true`, otherwise returns `false` with an | 92 //! \return On success, returns `true`, otherwise returns `false` with an |
| 92 //! error logged. | 93 //! error logged. |
| 93 bool SetLastUploadAttemptTime(time_t time); | 94 bool SetLastUploadAttemptTime(time_t time); |
| 94 | 95 |
| 95 private: | 96 private: |
| 96 struct Data; | 97 struct Data; |
| 97 | 98 |
| 99 class ScopedLockedFileHandle { | |
|
Robert Sesek
2015/04/01 15:08:26
Can you use ScopedGeneric for this? It should hand
scottmg
2015/04/01 19:32:10
Done.
| |
| 100 MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(ScopedLockedFileHandle) | |
| 101 | |
| 102 public: | |
| 103 ScopedLockedFileHandle(); | |
| 104 ScopedLockedFileHandle(FileHandle file, FileLocking locking); | |
| 105 ScopedLockedFileHandle(ScopedLockedFileHandle&& rvalue) | |
| 106 : handle_(rvalue.handle_.release()) {} | |
| 107 ScopedLockedFileHandle& operator=(ScopedLockedFileHandle&& rvalue) { | |
| 108 handle_.reset(rvalue.handle_.release()); | |
| 109 return *this; | |
| 110 } | |
| 111 ~ScopedLockedFileHandle(); | |
| 112 | |
| 113 FileHandle get() { return handle_.get(); } | |
| 114 bool is_valid() const { return handle_.is_valid(); } | |
| 115 void reset(); | |
| 116 | |
| 117 private: | |
| 118 void FreeIfNecessary(); | |
| 119 | |
| 120 ScopedFileHandle handle_; | |
| 121 }; | |
| 122 | |
| 98 // Opens the settings file for reading. On error, logs a message and returns | 123 // Opens the settings file for reading. On error, logs a message and returns |
| 99 // the invalid handle. | 124 // the invalid handle. |
| 100 ScopedFileHandle OpenForReading(); | 125 ScopedLockedFileHandle OpenForReading(); |
| 101 | 126 |
| 102 // Opens the settings file for reading and writing. On error, logs a message | 127 // Opens the settings file for reading and writing. On error, logs a message |
| 103 // and returns the invalid handle. | 128 // and returns the invalid handle. |
| 104 ScopedFileHandle OpenForReadingAndWriting(); | 129 ScopedLockedFileHandle OpenForReadingAndWriting(); |
| 105 | 130 |
| 106 // Opens the settings file and reads the data. If that fails, an error will | 131 // 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 | 132 // be logged and the settings will be recovered and re-initialized. If that |
| 108 // also fails, returns false with additional log data from recovery. | 133 // also fails, returns false with additional log data from recovery. |
| 109 bool OpenAndReadSettings(Data* out_data); | 134 bool OpenAndReadSettings(Data* out_data); |
| 110 | 135 |
| 111 // Opens the settings file for writing and reads the data. If reading fails, | 136 // 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 | 137 // recovery is attempted. Returns the opened file handle on success, or the |
| 113 // invalid file handle on failure, with an error logged. | 138 // invalid file handle on failure, with an error logged. |
| 114 ScopedFileHandle OpenForWritingAndReadSettings(Data* out_data); | 139 ScopedLockedFileHandle OpenForWritingAndReadSettings(Data* out_data); |
| 115 | 140 |
| 116 // Reads the settings from |handle|. Logs an error and returns false on | 141 // Reads the settings from |handle|. Logs an error and returns false on |
| 117 // failure. This does not perform recovery. | 142 // failure. This does not perform recovery. |
| 118 bool ReadSettings(FileHandle handle, Data* out_data); | 143 bool ReadSettings(FileHandle handle, Data* out_data); |
| 119 | 144 |
| 120 // Writes the settings to |handle|. Logs an error and returns false on | 145 // Writes the settings to |handle|. Logs an error and returns false on |
| 121 // failure. This does not perform recovery. | 146 // failure. This does not perform recovery. |
| 122 bool WriteSettings(FileHandle handle, const Data& data); | 147 bool WriteSettings(FileHandle handle, const Data& data); |
| 123 | 148 |
| 124 // Recovers the settings file by re-initializing the data. If |handle| is the | 149 // Recovers the settings file by re-initializing the data. If |handle| is the |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 138 base::FilePath file_path_; | 163 base::FilePath file_path_; |
| 139 | 164 |
| 140 InitializationStateDcheck initialized_; | 165 InitializationStateDcheck initialized_; |
| 141 | 166 |
| 142 DISALLOW_COPY_AND_ASSIGN(Settings); | 167 DISALLOW_COPY_AND_ASSIGN(Settings); |
| 143 }; | 168 }; |
| 144 | 169 |
| 145 } // namespace crashpad | 170 } // namespace crashpad |
| 146 | 171 |
| 147 #endif // CRASHPAD_CLIENT_SETTINGS_H_ | 172 #endif // CRASHPAD_CLIENT_SETTINGS_H_ |
| OLD | NEW |