| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_COMMON_COMMON_TYPE_CONVERTERS_H_ | 5 #ifndef MOJO_COMMON_COMMON_TYPE_CONVERTERS_H_ |
| 6 #define MOJO_COMMON_COMMON_TYPE_CONVERTERS_H_ | 6 #define MOJO_COMMON_COMMON_TYPE_CONVERTERS_H_ |
| 7 | 7 |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
| 10 #include "mojo/common/mojo_common_export.h" | 10 #include "mojo/common/mojo_common_export.h" |
| 11 #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h" | 11 #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h" |
| 12 #include "third_party/mojo/src/mojo/public/cpp/bindings/string.h" | 12 #include "third_party/mojo/src/mojo/public/cpp/bindings/string.h" |
| 13 #include "third_party/mojo/src/mojo/public/cpp/bindings/type_converter.h" | 13 #include "third_party/mojo/src/mojo/public/cpp/bindings/type_converter.h" |
| 14 | 14 |
| 15 class GURL; | |
| 16 | |
| 17 namespace mojo { | 15 namespace mojo { |
| 18 | 16 |
| 19 template <> | 17 template <> |
| 20 struct MOJO_COMMON_EXPORT TypeConverter<String, base::StringPiece> { | 18 struct MOJO_COMMON_EXPORT TypeConverter<String, base::StringPiece> { |
| 21 static String Convert(const base::StringPiece& input); | 19 static String Convert(const base::StringPiece& input); |
| 22 }; | 20 }; |
| 23 | 21 |
| 24 template <> | 22 template <> |
| 25 struct MOJO_COMMON_EXPORT TypeConverter<base::StringPiece, String> { | 23 struct MOJO_COMMON_EXPORT TypeConverter<base::StringPiece, String> { |
| 26 static base::StringPiece Convert(const String& input); | 24 static base::StringPiece Convert(const String& input); |
| 27 }; | 25 }; |
| 28 | 26 |
| 29 template <> | 27 template <> |
| 30 struct MOJO_COMMON_EXPORT TypeConverter<String, base::string16> { | 28 struct MOJO_COMMON_EXPORT TypeConverter<String, base::string16> { |
| 31 static String Convert(const base::string16& input); | 29 static String Convert(const base::string16& input); |
| 32 }; | 30 }; |
| 33 | 31 |
| 34 template <> | 32 template <> |
| 35 struct MOJO_COMMON_EXPORT TypeConverter<base::string16, String> { | 33 struct MOJO_COMMON_EXPORT TypeConverter<base::string16, String> { |
| 36 static base::string16 Convert(const String& input); | 34 static base::string16 Convert(const String& input); |
| 37 }; | 35 }; |
| 38 | 36 |
| 39 template <> | |
| 40 struct MOJO_COMMON_EXPORT TypeConverter<String, GURL> { | |
| 41 static String Convert(const GURL& input); | |
| 42 }; | |
| 43 | |
| 44 template <> | |
| 45 struct MOJO_COMMON_EXPORT TypeConverter<GURL, String> { | |
| 46 static GURL Convert(const String& input); | |
| 47 }; | |
| 48 | |
| 49 // TODO(erg): In the very long term, we will want to remove conversion between | 37 // TODO(erg): In the very long term, we will want to remove conversion between |
| 50 // std::strings and arrays of unsigned bytes. However, there is too much code | 38 // std::strings and arrays of unsigned bytes. However, there is too much code |
| 51 // across chrome which uses std::string as a bag of bytes that we probably | 39 // across chrome which uses std::string as a bag of bytes that we probably |
| 52 // don't want to roll this function at each callsite. | 40 // don't want to roll this function at each callsite. |
| 53 template <> | 41 template <> |
| 54 struct MOJO_COMMON_EXPORT TypeConverter<std::string, Array<uint8_t> > { | 42 struct MOJO_COMMON_EXPORT TypeConverter<std::string, Array<uint8_t> > { |
| 55 static std::string Convert(const Array<uint8_t>& input); | 43 static std::string Convert(const Array<uint8_t>& input); |
| 56 }; | 44 }; |
| 57 | 45 |
| 58 template <> | 46 template <> |
| 59 struct MOJO_COMMON_EXPORT TypeConverter<Array<uint8_t>, std::string> { | 47 struct MOJO_COMMON_EXPORT TypeConverter<Array<uint8_t>, std::string> { |
| 60 static Array<uint8_t> Convert(const std::string& input); | 48 static Array<uint8_t> Convert(const std::string& input); |
| 61 }; | 49 }; |
| 62 | 50 |
| 63 } // namespace mojo | 51 } // namespace mojo |
| 64 | 52 |
| 65 #endif // MOJO_COMMON_COMMON_TYPE_CONVERTERS_H_ | 53 #endif // MOJO_COMMON_COMMON_TYPE_CONVERTERS_H_ |
| OLD | NEW |