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

Unified Diff: base/json/json_string_value_serializer.h

Issue 895913004: JSONStringValueSerializer takes a StringPiece instead of std::string&. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@json-nullstring
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 | « no previous file | 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 3e0cb00d2fa1739b092f3ad0db2cf1732280ccf2..7f99bc9add79e449ca3ea83bc6475aea47be1454 100644
--- a/base/json/json_string_value_serializer.h
+++ b/base/json/json_string_value_serializer.h
@@ -10,6 +10,7 @@
#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 {
@@ -19,10 +20,10 @@ class BASE_EXPORT JSONStringValueSerializer : public base::ValueSerializer {
// 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. Retains a reference to |json_string|, so the string
- // argument must outlive the JSONStringValueSerializer.
- explicit JSONStringValueSerializer(const std::string& json_string);
+ // 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;
@@ -55,8 +56,12 @@ class BASE_EXPORT JSONStringValueSerializer : public base::ValueSerializer {
private:
bool SerializeInternal(const base::Value& root, bool omit_binary_values);
- std::string* json_string_; // Not null.
- bool initialized_with_const_string_;
+ // 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_;
+ // 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 | « no previous file | base/json/json_string_value_serializer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698