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

Side by Side Diff: client/settings.h

Issue 988063003: Define the Settings interface for a CrashReportDatabase and provide a Mac implementation. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address comments Created 5 years, 9 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
(Empty)
1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #ifndef CRASHPAD_CLIENT_SETTINGS_H_
16 #define CRASHPAD_CLIENT_SETTINGS_H_
17
18 #include <time.h>
19
20 #include <string>
21
22 #include "base/basictypes.h"
23 #include "base/files/file_path.h"
24 #include "util/file/file_io.h"
25 #include "util/misc/uuid.h"
26
27 namespace crashpad {
28
29 //! \brief An interface for accessing and modifying the settings of a
30 //! CrashReportDatabase.
31 //!
32 //! This class must not be instantiated directly, but rather an instance of it
33 //! should be retrieved via CrashReportDatabase::GetSettings().
34 class Settings {
35 public:
36 explicit Settings(const base::FilePath& file_path);
37 ~Settings();
38
39 bool Initialize();
40
41 //! \brief Retrieves the immutable identifier for this client, which is used
42 //! on a server to locate all crash reports from a specific Crashpad
43 //! database.
44 //!
45 //! This is automatically initialized when the database is created.
46 //!
47 //! \param[out] client_id The unique client identifier.
48 //!
49 //! \return On success, returns `true`, otherwise returns `false` with an
50 //! error logged.
51 bool GetClientID(UUID* client_id);
52
53 //! \brief Retrieves the user’s preference for submitting crash reports to a
54 //! collection server.
55 //!
56 //! The default value is `false`.
57 //!
58 //! \param[out] enabled Whether crash reports should be uploaded.
59 //!
60 //! \return On success, returns `true`, otherwise returns `false` with an
61 //! error logged.
62 bool GetUploadsEnabled(bool* enabled);
63
64 //! \brief Sets the user’s preference for submitting crash reports to a
65 //! collection server.
66 //!
67 //! \param[in] enabled Whether crash reports should be uploaded.
68 //!
69 //! \return On success, returns `true`, otherwise returns `false` with an
70 //! error logged.
71 bool SetUploadsEnabled(bool enabled);
72
73 //! \brief Retrieves the last time at which a report was attempted to be
74 //! uploaded.
75 //!
76 //! The default value is `0` if it has never been set before.
77 //!
78 //! \param[out] time The last time at which a report was uploaded.
79 //!
80 //! \return On success, returns `true`, otherwise returns `false` with an
81 //! error logged.
82 bool GetLastUploadAttemptTime(time_t* time);
83
84 //! \brief Sets the last time at which a report was attempted to be uploaded.
85 //!
86 //! This is only meant to be used internally by the CrashReportDatabase.
87 //!
88 //! \param[in] time The last time at which a report was uploaded.
89 //!
90 //! \return On success, returns `true`, otherwise returns `false` with an
91 //! error logged.
92 bool SetLastUploadAttemptTime(time_t time);
93
94 private:
95 struct Data;
96
97 // Opens the settings file for reading. On error, logs a message and returns
98 // the invalid handle.
99 ScopedFileHandle OpenForReading();
100
101 // Opens the settings file for reading and writing. On error, logs a message
102 // and returns the invalid handle.
103 ScopedFileHandle OpenForReadingAndWriting();
104
105 // Opens the settings file and reads the data. If that fails, an error will
106 // be logged and the settings will be recovered and re-initialized. If that
107 // also fails, returns false with additional log data from recovery.
108 bool OpenAndReadSettings(Data* out_data);
109
110 // Opens the settings file for writing and reads the data. If reading fails,
111 // recovery is attempted. Returns the opened file handle on success, or the
112 // invalid file handle on failure, with an error logged.
113 ScopedFileHandle OpenForWritingAndReadSettings(Data* out_data);
114
115 // Reads the settings from |handle|. Logs an error and returns false on
116 // failure. This does not perform recovery.
117 bool ReadSettings(FileHandle handle, Data* out_data);
118
119 // Writes the settings to |handle|. Logs an error and returns false on
120 // failure. This does not perform recovery.
121 bool WriteSettings(FileHandle handle, const Data& data);
122
123 // Recovers the settings file by re-initializing the data. If |handle| is the
124 // invalid handle, this will open the file; if it is not, then it must be the
125 // result of OpenForReadingAndWriting(). If the invalid handle is passed, the
126 // caller must not be holding the handle. The new settings data are stored in
127 // |out_data|. Returns true on success and false on failure, with an error
128 // logged.
129 bool RecoverSettings(FileHandle handle, Data* out_data);
130
131 // Initializes a settings file and writes the data to |handle|. Returns true
132 // on success and false on failure, with an error logged.
133 bool InitializeSettings(FileHandle handle);
134
135 const char* file_path() { return file_path_.value().c_str(); }
Mark Mentovai 2015/03/09 22:00:58 This method can be const.
136
137 base::FilePath file_path_;
138
139 DISALLOW_COPY_AND_ASSIGN(Settings);
140 };
141
142 } // namespace crashpad
143
144 #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