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

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: Drop plist, use binary 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 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.
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 //! 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.
43 //!
44 //! This is automatically initialized when the database is created.
45 //!
46 //! \param[out] client_id The unique client identifier.
47 //!
48 //! \return On success, returns `true`, otherwise returns `false` with an
49 //! error logged.
50 bool GetClientID(UUID* client_id);
51
52 //! \brief Retrieves the user’s preference for submitting crash reports to a
53 //! collection server.
54 //!
55 //! The default value is `false`.
56 //!
57 //! \param[out] enabled Whether crash reports should be uploaded.
58 //!
59 //! \return On success, returns `true`, otherwise returns `false` with an
60 //! error logged.
61 bool GetUploadsEnabled(bool* enabled);
62
63 //! \brief Sets the user’s preference for submitting crash reports to a
64 //! collection server.
65 //!
66 //! \param[in] enabled Whether crash reports should be uploaded.
67 //!
68 //! \return On success, returns `true`, otherwise returns `false` with an
69 //! error logged.
70 bool SetUploadsEnabled(bool enabled);
71
72 //! \brief Retrieves the last time at which a report was attempted to be
73 //! uploaded.
74 //!
75 //! The default value is `0` if it has never been set before.
76 //!
77 //! \param[out] time The last time at which a report was uploaded.
78 //!
79 //! \return On success, returns `true`, otherwise returns `false` with an
80 //! error logged.
81 bool GetLastUploadAttemptTime(time_t* time);
82
83 //! \brief Sets the last time at which a report was attempted to be uploaded.
84 //!
85 //! This is only meant to be used internally by the CrashReportDatabase.
86 //!
87 //! \param[in] time The last time at which a report was uploaded.
88 //!
89 //! \return On success, returns `true`, otherwise returns `false` with an
90 //! error logged.
91 bool SetLastUploadAttemptTime(time_t time);
92
93 private:
94 struct Data;
95
96 // Opens the settings file for reading. On error, logs a message and returns
97 // the invalid handle.
98 ScopedFileHandle OpenForReading();
99
100 // Opens the settings file for writing. On error, logs a message and returns
101 // the invalid handle.
102 ScopedFileHandle OpenForWriting();
Mark Mentovai 2015/03/09 19:12:36 OpenForReadingAndWriting(), and adjust the comment
Robert Sesek 2015/03/09 21:16:27 Done.
103
104 // Opens the settings file and reads the data. If that fails, an error will
105 // be logged and the settings will be recovered and re-initialized. If that
106 // 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.
107 bool OpenAndReadSettings(Data* out_data);
108
109 // Reads the settings from |handle|. Logs an error and returns false on
110 // failure. This does not perform recovery.
111 bool ReadSettings(FileHandle handle, Data* out_data);
112
113 // Writes the settings to |handle|. Logs an error and returns false on
114 // failure. This does not perform recovery.
115 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.
116
117 // Recovers the settings file by re-initializing the data. If |handle| is the
118 // invalid handle, this will open the file; if it is not, then it must be the
119 // 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.
120 // Returns true on success and false on failure, with an error logged.
121 bool RecoverSettings(FileHandle handle, Data* out_data);
122
123 // Initializes a settings file and writes the data to |handle|. Returns true
124 // on success and false on failure, with an error logged.
125 bool InitializeSettings(FileHandle handle);
126
127 const char* file_path() { return file_path_.value().c_str(); }
128
129 base::FilePath file_path_;
130
131 DISALLOW_COPY_AND_ASSIGN(Settings);
132 };
133
134 } // namespace crashpad
135
136 #endif // CRASHPAD_CLIENT_SETTINGS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698