Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / mojo / common / common_type_converters.cc
blob2439432c8ba262b11529ea8c760027107f6ba7a3
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
3 // found in the LICENSE file.
5 #include "mojo/common/common_type_converters.h"
7 #include <string>
9 #include "base/strings/utf_string_conversions.h"
10 #include "url/gurl.h"
12 namespace mojo {
14 // static
15 String TypeConverter<String, base::StringPiece>::ConvertFrom(
16 const base::StringPiece& input) {
17 if (input.empty()) {
18 char c = 0;
19 return String(&c, 0);
21 return String(input.data(), input.size());
23 // static
24 base::StringPiece TypeConverter<String, base::StringPiece>::ConvertTo(
25 const String& input) {
26 return input.get();
29 // static
30 String TypeConverter<String, base::string16>::ConvertFrom(
31 const base::string16& input) {
32 return TypeConverter<String, base::StringPiece>::ConvertFrom(
33 base::UTF16ToUTF8(input));
35 // static
36 base::string16 TypeConverter<String, base::string16>::ConvertTo(
37 const String& input) {
38 return base::UTF8ToUTF16(TypeConverter<String, base::StringPiece>::ConvertTo(
39 input));
42 String TypeConverter<String, GURL>::ConvertFrom(const GURL& input) {
43 return String(input.spec());
46 GURL TypeConverter<String, GURL>::ConvertTo(const String& input) {
47 return GURL(input.get());
50 } // namespace mojo