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

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: For landing 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
« no previous file with comments | « client/crash_report_database_win.cc ('k') | client/settings.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/initialization_state_dcheck.h"
26 #include "util/misc/uuid.h"
27
28 namespace crashpad {
29
30 //! \brief An interface for accessing and modifying the settings of a
31 //! CrashReportDatabase.
32 //!
33 //! This class must not be instantiated directly, but rather an instance of it
34 //! should be retrieved via CrashReportDatabase::GetSettings().
35 class Settings {
36 public:
37 explicit Settings(const base::FilePath& file_path);
38 ~Settings();
39
40 bool Initialize();
41
42 //! \brief Retrieves the immutable identifier for this client, which is used
43 //! on a server to locate all crash reports from a specific Crashpad
44 //! database.
45 //!
46 //! This is automatically initialized when the database is created.
47 //!
48 //! \param[out] client_id The unique client identifier.
49 //!
50 //! \return On success, returns `true`, otherwise returns `false` with an
51 //! error logged.
52 bool GetClientID(UUID* client_id);
53
54 //! \brief Retrieves the user’s preference for submitting crash reports to a
55 //! collection server.
56 //!
57 //! The default value is `false`.
58 //!
59 //! \param[out] enabled Whether crash reports should be uploaded.
60 //!
61 //! \return On success, returns `true`, otherwise returns `false` with an
62 //! error logged.
63 bool GetUploadsEnabled(bool* enabled);
64
65 //! \brief Sets the user’s preference for submitting crash reports to a
66 //! collection server.
67 //!
68 //! \param[in] enabled Whether crash reports should be uploaded.
69 //!
70 //! \return On success, returns `true`, otherwise returns `false` with an
71 //! error logged.
72 bool SetUploadsEnabled(bool enabled);
73
74 //! \brief Retrieves the last time at which a report was attempted to be
75 //! uploaded.
76 //!
77 //! The default value is `0` if it has never been set before.
78 //!
79 //! \param[out] time The last time at which a report was uploaded.
80 //!
81 //! \return On success, returns `true`, otherwise returns `false` with an
82 //! error logged.
83 bool GetLastUploadAttemptTime(time_t* time);
84
85 //! \brief Sets the last time at which a report was attempted to be uploaded.
86 //!
87 //! This is only meant to be used internally by the CrashReportDatabase.
88 //!
89 //! \param[in] time The last time at which a report was uploaded.
90 //!
91 //! \return On success, returns `true`, otherwise returns `false` with an
92 //! error logged.
93 bool SetLastUploadAttemptTime(time_t time);
94
95 private:
96 struct Data;
97
98 // Opens the settings file for reading. On error, logs a message and returns
99 // the invalid handle.
100 ScopedFileHandle OpenForReading();
101
102 // Opens the settings file for reading and writing. On error, logs a message
103 // and returns the invalid handle.
104 ScopedFileHandle OpenForReadingAndWriting();
105
106 // 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
108 // also fails, returns false with additional log data from recovery.
109 bool OpenAndReadSettings(Data* out_data);
110
111 // 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
113 // invalid file handle on failure, with an error logged.
114 ScopedFileHandle OpenForWritingAndReadSettings(Data* out_data);
115
116 // Reads the settings from |handle|. Logs an error and returns false on
117 // failure. This does not perform recovery.
118 bool ReadSettings(FileHandle handle, Data* out_data);
119
120 // Writes the settings to |handle|. Logs an error and returns false on
121 // failure. This does not perform recovery.
122 bool WriteSettings(FileHandle handle, const Data& data);
123
124 // Recovers the settings file by re-initializing the data. If |handle| is the
125 // invalid handle, this will open the file; if it is not, then it must be the
126 // result of OpenForReadingAndWriting(). If the invalid handle is passed, the
127 // caller must not be holding the handle. The new settings data are stored in
128 // |out_data|. Returns true on success and false on failure, with an error
129 // logged.
130 bool RecoverSettings(FileHandle handle, Data* out_data);
131
132 // Initializes a settings file and writes the data to |handle|. Returns true
133 // on success and false on failure, with an error logged.
134 bool InitializeSettings(FileHandle handle);
135
136 const char* file_path() { return file_path_.value().c_str(); }
137
138 base::FilePath file_path_;
139
140 InitializationStateDcheck initialized_;
141
142 DISALLOW_COPY_AND_ASSIGN(Settings);
143 };
144
145 } // namespace crashpad
146
147 #endif // CRASHPAD_CLIENT_SETTINGS_H_
OLDNEW
« 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