| 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..268d4715d01f0996b8a6b7f035c96a3b4082927f
|
| --- /dev/null
|
| +++ b/content/common/vr_param_traits.cc
|
| @@ -0,0 +1,59 @@
|
| +// 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(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));
|
| +}
|
| +
|
| +} // 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);
|
| + l->append(",");
|
| + LogWebUCharString(p.deviceName, WebVRDevice::deviceNameLengthCap, l);
|
| + l->append(",");
|
| + LogParam(p.flags, l);
|
| + // TODO(bajones): Log the WebVRHMDInfo struct
|
| + l->append(")");
|
| +}
|
| +
|
| +} // namespace IPC
|
|
|