OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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. |
| 4 |
| 5 #include "content/common/vr_param_traits.h" |
| 6 |
| 7 #include "base/pickle.h" |
| 8 #include "base/strings/string16.h" |
| 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "ipc/ipc_message_utils.h" |
| 11 #include "third_party/WebKit/public/platform/WebVR.h" |
| 12 |
| 13 using blink::WebVRDevice; |
| 14 |
| 15 namespace { |
| 16 |
| 17 void LogWebUCharString(const blink::WebUChar web_string[], |
| 18 const size_t array_size, |
| 19 std::string* log) { |
| 20 base::string16 utf16; |
| 21 utf16.reserve(array_size); |
| 22 for (size_t i = 0; i < array_size && web_string[i]; ++i) { |
| 23 utf16[i] = web_string[i]; |
| 24 } |
| 25 log->append(base::UTF16ToUTF8(utf16)); |
| 26 } |
| 27 |
| 28 } // namespace |
| 29 |
| 30 namespace IPC { |
| 31 |
| 32 void ParamTraits<WebVRDevice>::Write(Message* m, const WebVRDevice& p) { |
| 33 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(WebVRDevice)); |
| 34 } |
| 35 |
| 36 bool ParamTraits<WebVRDevice>::Read(const Message* m, |
| 37 PickleIterator* iter, |
| 38 WebVRDevice* p) { |
| 39 int length; |
| 40 const char* data; |
| 41 if (!iter->ReadData(&data, &length) || length != sizeof(WebVRDevice)) |
| 42 return false; |
| 43 memcpy(p, data, sizeof(WebVRDevice)); |
| 44 |
| 45 return true; |
| 46 } |
| 47 |
| 48 void ParamTraits<WebVRDevice>::Log(const WebVRDevice& p, std::string* l) { |
| 49 l->append("WebVRDevice("); |
| 50 LogParam(p.index, l); |
| 51 l->append(","); |
| 52 LogWebUCharString(p.deviceName, WebVRDevice::deviceNameLengthCap, l); |
| 53 l->append(","); |
| 54 LogParam(p.flags, l); |
| 55 // TODO(bajones): Log the WebVRHMDInfo struct |
| 56 l->append(")"); |
| 57 } |
| 58 |
| 59 } // namespace IPC |
OLD | NEW |