Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_MAC_H_ | |
| 16 #define CRASHPAD_CLIENT_SETTINGS_MAC_H_ | |
| 17 | |
| 18 #import <Foundation/Foundation.h> | |
| 19 | |
| 20 #include "base/files/file_path.h" | |
| 21 #include "client/settings.h" | |
| 22 #include "util/file/file_io.h" | |
| 23 | |
| 24 namespace crashpad { | |
| 25 namespace internal { | |
| 26 | |
| 27 //! \brief An implementation of the Settings interface, which stores the values | |
| 28 //! in a property list (plist) file. | |
| 29 class SettingsMac : public Settings { | |
| 30 public: | |
| 31 explicit SettingsMac(const base::FilePath& file_path); | |
| 32 ~SettingsMac() override; | |
| 33 | |
| 34 bool Initialize(); | |
| 35 | |
| 36 // Settings: | |
| 37 bool GetClientID(std::string* client_id) override; | |
| 38 bool GetUploadsEnabled(bool* enabled) override; | |
| 39 bool SetUploadsEnabled(bool enabled) override; | |
| 40 bool GetLastUploadAttemptTime(time_t* time) override; | |
| 41 bool SetLastUploadAttemptTime(time_t time) override; | |
| 42 | |
| 43 private: | |
| 44 // Deserializes the plist from |fd|, which must be opened for reading and | |
| 45 // have at least a shared file lock. Returns nil if an error occurred, with | |
| 46 // an error logged. | |
| 47 NSMutableDictionary* ReadPlist(FileHandle fd); | |
| 48 | |
| 49 // Serializes the |plist| to the |fd|, which must be opened for writing and | |
| 50 // have the exclusive file lock. Returns true on success and false on failure. | |
| 51 bool WritePlist(FileHandle fd, NSDictionary* plist); | |
| 52 | |
| 53 // Reads the settings file and returns the value associated with |key|, or nil | |
| 54 // if it is not set. The value must be of type |value_class| or it is an | |
| 55 // error. If an error occurs, it is logged and this returns nil. | |
| 56 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
| |
| 57 | |
| 58 // Sets the |value| for |key| and writes the plist file. Returns true on | |
| 59 // success and false on failure, with an error logged. | |
| 60 bool SetSetting(NSString* key, NSObject* value); | |
| 61 | |
| 62 // Generates a client ID and writes it as the sole value in a plist to |fd|. | |
| 63 bool GenerateClientID(FileHandle fd); | |
| 64 | |
| 65 // Performs error recovery by reopening the file with an exclusive lock and | |
| 66 // reading it. If the operation fails, the settings plist is recreated with | |
| 67 // a new client ID, and the new plist is returned. | |
| 68 NSMutableDictionary* RecoverPlist(); | |
| 69 | |
| 70 const char* file_path() { return file_path_.value().c_str(); }; | |
| 71 | |
| 72 base::FilePath file_path_; | |
| 73 | |
| 74 DISALLOW_COPY_AND_ASSIGN(SettingsMac); | |
| 75 }; | |
| 76 | |
| 77 } // namespace internal | |
| 78 } // namespace crashpad | |
| 79 | |
| 80 #endif // CRASHPAD_CLIENT_SETTINGS_MAC_H_ | |
| OLD | NEW |