| Index: base/json/json_string_value_serializer.h
|
| diff --git a/base/json/json_string_value_serializer.h b/base/json/json_string_value_serializer.h
|
| index 6435051aa19b5235df4355065f7170d4854809bb..7f99bc9add79e449ca3ea83bc6475aea47be1454 100644
|
| --- a/base/json/json_string_value_serializer.h
|
| +++ b/base/json/json_string_value_serializer.h
|
| @@ -10,28 +10,20 @@
|
| #include "base/base_export.h"
|
| #include "base/basictypes.h"
|
| #include "base/files/file_path.h"
|
| +#include "base/strings/string_piece.h"
|
| #include "base/values.h"
|
|
|
| class BASE_EXPORT JSONStringValueSerializer : public base::ValueSerializer {
|
| public:
|
| - // json_string is the string that will be source of the deserialization
|
| + // |json_string| is the string that will be source of the deserialization
|
| // or the destination of the serialization. The caller of the constructor
|
| - // retains ownership of the string.
|
| - explicit JSONStringValueSerializer(std::string* json_string)
|
| - : json_string_(json_string),
|
| - initialized_with_const_string_(false),
|
| - pretty_print_(false),
|
| - allow_trailing_comma_(false) {
|
| - }
|
| + // retains ownership of the string. |json_string| must not be null.
|
| + explicit JSONStringValueSerializer(std::string* json_string);
|
|
|
| - // This version allows initialization with a const string reference for
|
| - // deserialization only.
|
| - explicit JSONStringValueSerializer(const std::string& json_string)
|
| - : json_string_(&const_cast<std::string&>(json_string)),
|
| - initialized_with_const_string_(true),
|
| - pretty_print_(false),
|
| - allow_trailing_comma_(false) {
|
| - }
|
| + // This version allows initialization with a StringPiece for deserialization
|
| + // only. Retains a reference to the contents of |json_string|, so the data
|
| + // must outlive the JSONStringValueSerializer.
|
| + explicit JSONStringValueSerializer(const base::StringPiece& json_string);
|
|
|
| ~JSONStringValueSerializer() override;
|
|
|
| @@ -46,7 +38,7 @@ class BASE_EXPORT JSONStringValueSerializer : public base::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 if |error_code| is non-null, |error_code| will
|
| + // value is null, and if |error_code| is non-null, |error_code| will
|
| // contain an integer error code (a JsonParseError in this case).
|
| // If |error_message| is non-null, it will be filled in with a formatted
|
| // error message including the location of the error if appropriate.
|
| @@ -64,8 +56,12 @@ class BASE_EXPORT JSONStringValueSerializer : public base::ValueSerializer {
|
| private:
|
| bool SerializeInternal(const base::Value& root, bool omit_binary_values);
|
|
|
| + // String for writing. Owned by the caller of the constructor. Will be null if
|
| + // the serializer was initialized with a const string.
|
| std::string* json_string_;
|
| - bool initialized_with_const_string_;
|
| + // String for reading. Data is owned by the caller of the constructor. If
|
| + // |json_string_| is non-null, this is a view onto |json_string_|.
|
| + base::StringPiece json_string_readonly_;
|
| bool pretty_print_; // If true, serialization will span multiple lines.
|
| // If true, deserialization will allow trailing commas.
|
| bool allow_trailing_comma_;
|
|
|