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

Unified Diff: mojo/public/cpp/bindings/string_traits_string_piece.h

Issue 1966933002: Mojo C++ bindings: switch the existing usage of StructTraits to use the new data view interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@26_reader
Patch Set: typeid() is not allowed :/ Created 4 years, 7 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 | « mojo/public/cpp/bindings/string_traits_standard.h ('k') | mojo/public/cpp/bindings/string_traits_wtf.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/string_traits_string_piece.h
diff --git a/mojo/public/cpp/bindings/string_traits_string_piece.h b/mojo/public/cpp/bindings/string_traits_string_piece.h
index b6018f22fbe8a99d8da775620025aebf84bfb347..af6be893ac006aad361918ad65a0962c6eddd37f 100644
--- a/mojo/public/cpp/bindings/string_traits_string_piece.h
+++ b/mojo/public/cpp/bindings/string_traits_string_piece.h
@@ -12,12 +12,19 @@ namespace mojo {
template <>
struct StringTraits<base::StringPiece> {
- // No IsNull() function, which means that base::StringPiece is always
- // considered as non-null mojom string. We could have let StringPiece
- // containing a null data pointer map to null mojom string, but
- // StringPiece::empty() returns true in this case. It seems confusing to mix
- // the concept of empty and null strings, especially because they mean
- // different things in mojom.
+ static bool IsNull(const base::StringPiece& input) {
dcheng 2016/05/13 04:12:34 Usually, StringPiece should be passed by value. An
yzshen1 2016/05/13 04:35:08 It still works if I change this method's signature
dcheng 2016/05/13 06:05:15 To clarify, my comment was only referring to using
+ // base::StringPiece is always converted to non-null mojom string. We could
+ // have let StringPiece containing a null data pointer map to null mojom
+ // string, but StringPiece::empty() returns true in this case. It seems
+ // confusing to mix the concept of empty and null strings, especially
+ // because they mean different things in mojom.
+ return false;
+ }
+
+ static void SetToNull(base::StringPiece* output) {
+ // Convert null to an "empty" base::StringPiece.
+ output->set(nullptr, 0);
+ }
static size_t GetSize(const base::StringPiece& input) { return input.size(); }
@@ -26,10 +33,7 @@ struct StringTraits<base::StringPiece> {
}
static bool Read(StringDataView input, base::StringPiece* output) {
- if (!input.is_null())
- output->set(input.storage(), input.size());
- else
- output->set(nullptr, 0);
+ output->set(input.storage(), input.size());
return true;
}
};
« no previous file with comments | « mojo/public/cpp/bindings/string_traits_standard.h ('k') | mojo/public/cpp/bindings/string_traits_wtf.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698