Index: client/settings_mac.h |
diff --git a/client/settings_mac.h b/client/settings_mac.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1df54e52d3c85d09aedc0d3610a4e2111ac4422b |
--- /dev/null |
+++ b/client/settings_mac.h |
@@ -0,0 +1,80 @@ |
+// 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_MAC_H_ |
+#define CRASHPAD_CLIENT_SETTINGS_MAC_H_ |
+ |
+#import <Foundation/Foundation.h> |
+ |
+#include "base/files/file_path.h" |
+#include "client/settings.h" |
+#include "util/file/file_io.h" |
+ |
+namespace crashpad { |
+namespace internal { |
+ |
+//! \brief An implementation of the Settings interface, which stores the values |
+//! in a property list (plist) file. |
+class SettingsMac : public Settings { |
+ public: |
+ explicit SettingsMac(const base::FilePath& file_path); |
+ ~SettingsMac() override; |
+ |
+ bool Initialize(); |
+ |
+ // Settings: |
+ bool GetClientID(std::string* client_id) override; |
+ bool GetUploadsEnabled(bool* enabled) override; |
+ bool SetUploadsEnabled(bool enabled) override; |
+ bool GetLastUploadAttemptTime(time_t* time) override; |
+ bool SetLastUploadAttemptTime(time_t time) override; |
+ |
+ private: |
+ // Deserializes the plist from |fd|, which must be opened for reading and |
+ // have at least a shared file lock. Returns nil if an error occurred, with |
+ // an error logged. |
+ NSMutableDictionary* ReadPlist(FileHandle fd); |
+ |
+ // Serializes the |plist| to the |fd|, which must be opened for writing and |
+ // have the exclusive file lock. Returns true on success and false on failure. |
+ bool WritePlist(FileHandle fd, NSDictionary* plist); |
+ |
+ // Reads the settings file and returns the value associated with |key|, or nil |
+ // if it is not set. The value must be of type |value_class| or it is an |
+ // error. If an error occurs, it is logged and this returns nil. |
+ id GetSetting(NSString* key, Class value_class); |
Mark Mentovai
2015/03/09 14:01:23
This can be templatized so that it returns the cor
|
+ |
+ // Sets the |value| for |key| and writes the plist file. Returns true on |
+ // success and false on failure, with an error logged. |
+ bool SetSetting(NSString* key, NSObject* value); |
+ |
+ // Generates a client ID and writes it as the sole value in a plist to |fd|. |
+ bool GenerateClientID(FileHandle fd); |
+ |
+ // Performs error recovery by reopening the file with an exclusive lock and |
+ // reading it. If the operation fails, the settings plist is recreated with |
+ // a new client ID, and the new plist is returned. |
+ NSMutableDictionary* RecoverPlist(); |
+ |
+ const char* file_path() { return file_path_.value().c_str(); }; |
+ |
+ base::FilePath file_path_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SettingsMac); |
+}; |
+ |
+} // namespace internal |
+} // namespace crashpad |
+ |
+#endif // CRASHPAD_CLIENT_SETTINGS_MAC_H_ |