Index: client/settings.h |
diff --git a/client/settings.h b/client/settings.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7e6c5501cd05e004fe5f5aa3fcebc1ade89d755f |
--- /dev/null |
+++ b/client/settings.h |
@@ -0,0 +1,136 @@ |
+// Copyright 2015 The Crashpad Authors. All rights reserved. |
+// |
+// Licensed under the Apache License, Version 2.0 (the "License"); |
+// you may not use this file except in compliance with the License. |
+// You may obtain a copy of the License at |
+// |
+// http://www.apache.org/licenses/LICENSE-2.0 |
+// |
+// Unless required by applicable law or agreed to in writing, software |
+// distributed under the License is distributed on an "AS IS" BASIS, |
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+// See the License for the specific language governing permissions and |
+// limitations under the License. |
+ |
+#ifndef CRASHPAD_CLIENT_SETTINGS_H_ |
+#define CRASHPAD_CLIENT_SETTINGS_H_ |
+ |
+#include <time.h> |
+ |
+#include <string> |
+ |
+#include "base/basictypes.h" |
+#include "base/files/file_path.h" |
+#include "util/file/file_io.h" |
+#include "util/misc/uuid.h" |
+ |
+namespace crashpad { |
+ |
+//! \brief An interface for accessing and modifying the settings of a |
+//! CrashReportDatabase. |
+//! |
+//! This class cannot be instantiated directly, but rather an instance of it |
Mark Mentovai
2015/03/09 19:12:36
“cannot” makes it sound like it’s physically impos
Robert Sesek
2015/03/09 21:16:27
Done.
|
+//! should be retrieved via CrashReportDatabase::GetSettings(). |
+class Settings { |
+ public: |
+ explicit Settings(const base::FilePath& file_path); |
+ ~Settings(); |
+ |
+ bool Initialize(); |
+ |
+ //! \brief Retrieves the immutable identifier for this client, which is used |
+ //! to locate all crash reports from a specific Crashpad database. |
Mark Mentovai
2015/03/09 19:12:36
used on a server
Robert Sesek
2015/03/09 21:16:27
Done.
|
+ //! |
+ //! This is automatically initialized when the database is created. |
+ //! |
+ //! \param[out] client_id The unique client identifier. |
+ //! |
+ //! \return On success, returns `true`, otherwise returns `false` with an |
+ //! error logged. |
+ bool GetClientID(UUID* client_id); |
+ |
+ //! \brief Retrieves the user’s preference for submitting crash reports to a |
+ //! collection server. |
+ //! |
+ //! The default value is `false`. |
+ //! |
+ //! \param[out] enabled Whether crash reports should be uploaded. |
+ //! |
+ //! \return On success, returns `true`, otherwise returns `false` with an |
+ //! error logged. |
+ bool GetUploadsEnabled(bool* enabled); |
+ |
+ //! \brief Sets the user’s preference for submitting crash reports to a |
+ //! collection server. |
+ //! |
+ //! \param[in] enabled Whether crash reports should be uploaded. |
+ //! |
+ //! \return On success, returns `true`, otherwise returns `false` with an |
+ //! error logged. |
+ bool SetUploadsEnabled(bool enabled); |
+ |
+ //! \brief Retrieves the last time at which a report was attempted to be |
+ //! uploaded. |
+ //! |
+ //! The default value is `0` if it has never been set before. |
+ //! |
+ //! \param[out] time The last time at which a report was uploaded. |
+ //! |
+ //! \return On success, returns `true`, otherwise returns `false` with an |
+ //! error logged. |
+ bool GetLastUploadAttemptTime(time_t* time); |
+ |
+ //! \brief Sets the last time at which a report was attempted to be uploaded. |
+ //! |
+ //! This is only meant to be used internally by the CrashReportDatabase. |
+ //! |
+ //! \param[in] time The last time at which a report was uploaded. |
+ //! |
+ //! \return On success, returns `true`, otherwise returns `false` with an |
+ //! error logged. |
+ bool SetLastUploadAttemptTime(time_t time); |
+ |
+ private: |
+ struct Data; |
+ |
+ // Opens the settings file for reading. On error, logs a message and returns |
+ // the invalid handle. |
+ ScopedFileHandle OpenForReading(); |
+ |
+ // Opens the settings file for writing. On error, logs a message and returns |
+ // the invalid handle. |
+ ScopedFileHandle OpenForWriting(); |
Mark Mentovai
2015/03/09 19:12:36
OpenForReadingAndWriting(), and adjust the comment
Robert Sesek
2015/03/09 21:16:27
Done.
|
+ |
+ // 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 |
+ // fails, returns false. |
Mark Mentovai
2015/03/09 19:12:36
Add the word “also” before the final “fails.” Also
Robert Sesek
2015/03/09 21:16:27
Done.
|
+ bool OpenAndReadSettings(Data* out_data); |
+ |
+ // Reads the settings from |handle|. Logs an error and returns false on |
+ // failure. This does not perform recovery. |
+ bool ReadSettings(FileHandle handle, Data* out_data); |
+ |
+ // Writes the settings to |handle|. Logs an error and returns false on |
+ // failure. This does not perform recovery. |
+ bool WriteSettings(FileHandle handle, const Data* data); |
Mark Mentovai
2015/03/09 19:12:36
const Data& instead of const Data* for the const i
Robert Sesek
2015/03/09 21:16:27
Done.
|
+ |
+ // Recovers the settings file by re-initializing the data. If |handle| is the |
+ // invalid handle, this will open the file; if it is not, then it must be the |
+ // result of OpenForWriting(). The new settings data are stored in |out_data|. |
Mark Mentovai
2015/03/09 19:12:36
Also say that the caller must not be holding a han
Robert Sesek
2015/03/09 21:16:27
Done.
|
+ // Returns true on success and false on failure, with an error logged. |
+ bool RecoverSettings(FileHandle handle, Data* out_data); |
+ |
+ // Initializes a settings file and writes the data to |handle|. Returns true |
+ // on success and false on failure, with an error logged. |
+ bool InitializeSettings(FileHandle handle); |
+ |
+ const char* file_path() { return file_path_.value().c_str(); } |
+ |
+ base::FilePath file_path_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(Settings); |
+}; |
+ |
+} // namespace crashpad |
+ |
+#endif // CRASHPAD_CLIENT_SETTINGS_H_ |