Chromium Code Reviews| Index: content/common/vr_param_traits.cc |
| diff --git a/content/common/vr_param_traits.cc b/content/common/vr_param_traits.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2cbc41890576dfa2f6497873ca87ebeba58965c9 |
| --- /dev/null |
| +++ b/content/common/vr_param_traits.cc |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/common/vr_param_traits.h" |
| + |
| +#include "base/pickle.h" |
| +#include "base/strings/string16.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "ipc/ipc_message_utils.h" |
| +#include "third_party/WebKit/public/platform/WebVR.h" |
| + |
| +using blink::WebVRDevice; |
| + |
| +namespace { |
| + |
| +void LogWebUCharString( |
|
mdempsky
2015/05/11 19:25:01
(I'm surprised this functionality doesn't already
|
| + const blink::WebUChar web_string[], |
| + const size_t array_size, |
| + std::string* log) { |
| + base::string16 utf16; |
| + utf16.reserve(array_size); |
| + for (size_t i = 0; i < array_size && web_string[i]; ++i) { |
| + utf16[i] = web_string[i]; |
| + } |
| + log->append(base::UTF16ToUTF8(utf16)); |
| +} |
| + |
| +} |
|
mdempsky
2015/05/11 19:25:01
Nit: "// namespace".
|
| + |
| +namespace IPC { |
| + |
| +void ParamTraits<WebVRDevice>::Write( |
| + Message* m, |
| + const WebVRDevice& p) { |
| + m->WriteData(reinterpret_cast<const char*>(&p), sizeof(WebVRDevice)); |
| +} |
| + |
| +bool ParamTraits<WebVRDevice>::Read( |
| + const Message* m, |
| + PickleIterator* iter, |
| + WebVRDevice* p) { |
| + int length; |
| + const char* data; |
| + if (!iter->ReadData(&data, &length) || length != sizeof(WebVRDevice)) |
| + return false; |
| + memcpy(p, data, sizeof(WebVRDevice)); |
| + |
| + return true; |
| +} |
| + |
| +void ParamTraits<WebVRDevice>::Log( |
| + const WebVRDevice& p, |
| + std::string* l) { |
| + l->append("WebVRDevice("); |
| + LogParam(p.index, l); |
| + LogWebUCharString(p.deviceName, WebVRDevice::deviceNameLengthCap, l); |
|
mdempsky
2015/05/11 19:25:01
Should there be delimiters between the logged fiel
|
| + LogParam(p.flags, l); |
| + // TODO(bajones): Log the WebVRHMDInfo struct |
| + l->append(")"); |
| +} |
| + |
| +} // namespace IPC |