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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STRING_PIECE_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STRING_PIECE_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STRING_PIECE_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STRING_PIECE_H_
7 7
8 #include "base/strings/string_piece.h" 8 #include "base/strings/string_piece.h"
9 #include "mojo/public/cpp/bindings/string_traits.h" 9 #include "mojo/public/cpp/bindings/string_traits.h"
10 10
11 namespace mojo { 11 namespace mojo {
12 12
13 template <> 13 template <>
14 struct StringTraits<base::StringPiece> { 14 struct StringTraits<base::StringPiece> {
15 // No IsNull() function, which means that base::StringPiece is always 15 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
16 // considered as non-null mojom string. We could have let StringPiece 16 // base::StringPiece is always converted to non-null mojom string. We could
17 // containing a null data pointer map to null mojom string, but 17 // have let StringPiece containing a null data pointer map to null mojom
18 // StringPiece::empty() returns true in this case. It seems confusing to mix 18 // string, but StringPiece::empty() returns true in this case. It seems
19 // the concept of empty and null strings, especially because they mean 19 // confusing to mix the concept of empty and null strings, especially
20 // different things in mojom. 20 // because they mean different things in mojom.
21 return false;
22 }
23
24 static void SetToNull(base::StringPiece* output) {
25 // Convert null to an "empty" base::StringPiece.
26 output->set(nullptr, 0);
27 }
21 28
22 static size_t GetSize(const base::StringPiece& input) { return input.size(); } 29 static size_t GetSize(const base::StringPiece& input) { return input.size(); }
23 30
24 static const char* GetData(const base::StringPiece& input) { 31 static const char* GetData(const base::StringPiece& input) {
25 return input.data(); 32 return input.data();
26 } 33 }
27 34
28 static bool Read(StringDataView input, base::StringPiece* output) { 35 static bool Read(StringDataView input, base::StringPiece* output) {
29 if (!input.is_null()) 36 output->set(input.storage(), input.size());
30 output->set(input.storage(), input.size());
31 else
32 output->set(nullptr, 0);
33 return true; 37 return true;
34 } 38 }
35 }; 39 };
36 40
37 } // namespace mojo 41 } // namespace mojo
38 42
39 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STRING_PIECE_H_ 43 #endif // MOJO_PUBLIC_CPP_BINDINGS_STRING_TRAITS_STRING_PIECE_H_
OLDNEW
« 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