diff options
author | erikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-06 15:42:39 +0000 |
---|---|---|
committer | erikkay@chromium.org <erikkay@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-06 15:42:39 +0000 |
commit | ba3996771f6d19298ee655992b2f6291a314ea76 (patch) | |
tree | e5d88f89e7e98aa6ee60af431dc5dfa426d727b2 /chrome/common/json_value_serializer.h | |
parent | 44a91f51ec8dd8d1373e28ef6f3f0ab410db942f (diff) | |
download | chromium_src-ba3996771f6d19298ee655992b2f6291a314ea76.zip chromium_src-ba3996771f6d19298ee655992b2f6291a314ea76.tar.gz chromium_src-ba3996771f6d19298ee655992b2f6291a314ea76.tar.bz2 |
detect preferences errors
BUG=38352
TEST=none
Review URL: http://codereview.chromium.org/1120006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43715 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/json_value_serializer.h')
-rw-r--r-- | chrome/common/json_value_serializer.h | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/chrome/common/json_value_serializer.h b/chrome/common/json_value_serializer.h index 1f1e556..7919cfe 100644 --- a/chrome/common/json_value_serializer.h +++ b/chrome/common/json_value_serializer.h @@ -41,9 +41,12 @@ class JSONStringValueSerializer : public ValueSerializer { // Attempt to deserialize the data structure encoded in the string passed // in to the constructor into a structure of Value objects. If the return - // value is NULL and |error_message| is non-null, |error_message| will contain - // a string describing the error. - Value* Deserialize(std::string* error_message); + // value is NULL, and if |error_code| is non-null, |error_code| will + // contain an integer error code (either JsonFileError or JsonParseError). + // If |error_message| is non-null, it will be filled in with a formatted + // error message including the location of the error if appropriate. + // The caller takes ownership of the returned value. + Value* Deserialize(int* error_code, std::string* error_message); void set_pretty_print(bool new_value) { pretty_print_ = new_value; } bool pretty_print() { return pretty_print_; } @@ -85,14 +88,39 @@ class JSONFileValueSerializer : public ValueSerializer { // Attempt to deserialize the data structure encoded in the file passed // in to the constructor into a structure of Value objects. If the return - // value is NULL, and if |error_message| is non-null, |error_message| will - // contain a string describing the error. The caller takes ownership of the - // returned value. - Value* Deserialize(std::string* error_message); + // value is NULL, and if |error_code| is non-null, |error_code| will + // contain an integer error code (either JsonFileError or JsonParseError). + // If |error_message| is non-null, it will be filled in with a formatted + // error message including the location of the error if appropriate. + // The caller takes ownership of the returned value. + Value* Deserialize(int* error_code, std::string* error_message); + + // This enum is designed to safely overlap with JSONReader::JsonParseError. + enum JsonFileError { + JSON_NO_ERROR = 0, + JSON_ACCESS_DENIED = 1000, + JSON_CANNOT_READ_FILE, + JSON_FILE_LOCKED, + JSON_NO_SUCH_FILE + }; + + // File-specific error messages that can be returned. + static const char* kAccessDenied; + static const char* kCannotReadFile; + static const char* kFileLocked; + static const char* kNoSuchFile; + + // Convert an error code into an error message. |error_code| is assumed to + // be a JsonFileError. + static const char* GetErrorMessageForCode(int error_code); private: FilePath json_file_path_; + // A wrapper for file_util::ReadFileToString which returns a non-zero + // JsonFileError if there were file errors. + int ReadFileToString(std::string* json_string); + DISALLOW_IMPLICIT_CONSTRUCTORS(JSONFileValueSerializer); }; |