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

Unified Diff: mojo/common/common_type_converters.cc

Issue 1814003002: Implement the renderer side of the mojo based local storage implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 9 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/common/common_type_converters.h ('k') | mojo/common/common_type_converters_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/common/common_type_converters.cc
diff --git a/mojo/common/common_type_converters.cc b/mojo/common/common_type_converters.cc
index 2740853c3d0836c8d33a7ebd23354b472c33ab7c..78418f8e41a1b7c73bcded5b824e8774528736fa 100644
--- a/mojo/common/common_type_converters.cc
+++ b/mojo/common/common_type_converters.cc
@@ -39,9 +39,9 @@ base::string16 TypeConverter<base::string16, String>::Convert(
return base::UTF8ToUTF16(input.To<base::StringPiece>());
}
-std::string TypeConverter<std::string, Array<uint8_t> >::Convert(
+std::string TypeConverter<std::string, Array<uint8_t>>::Convert(
const Array<uint8_t>& input) {
- if (input.is_null() || input.size() == 0u)
+ if (input.is_null() || input.empty())
return std::string();
return std::string(reinterpret_cast<const char*>(&input.front()),
@@ -51,9 +51,26 @@ std::string TypeConverter<std::string, Array<uint8_t> >::Convert(
Array<uint8_t> TypeConverter<Array<uint8_t>, std::string>::Convert(
const std::string& input) {
Array<uint8_t> result(input.size());
- if (input.size() > 0)
+ if (!input.empty())
memcpy(&result.front(), input.c_str(), input.size());
return result;
}
+base::string16 TypeConverter<base::string16, Array<uint8_t>>::Convert(
+ const Array<uint8_t>& input) {
+ if (input.is_null() || input.empty())
+ return base::string16();
+
+ return base::string16(reinterpret_cast<const base::char16*>(&input.front()),
+ input.size() / sizeof(base::char16));
+}
+
+Array<uint8_t> TypeConverter<Array<uint8_t>, base::string16>::Convert(
+ const base::string16& input) {
+ Array<uint8_t> result(input.size() * sizeof(base::char16));
+ if (!input.empty())
+ memcpy(&result.front(), input.c_str(), input.size() * sizeof(base::char16));
+ return result;
+}
+
} // namespace mojo
« no previous file with comments | « mojo/common/common_type_converters.h ('k') | mojo/common/common_type_converters_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698