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

Unified Diff: base/json/json_string_value_serializer.h

Issue 903273002: Update from https://crrev.com/315085 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/files/file_path_watcher_win.cc ('k') | base/json/json_string_value_serializer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_;
« no previous file with comments | « base/files/file_path_watcher_win.cc ('k') | base/json/json_string_value_serializer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698