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

Unified Diff: content/common/vr_param_traits.cc

Issue 829803003: Adding Chrome-side WebVR interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updates/cleanups before pulling in reviewers. Created 5 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
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..e92a3afc690cf5457870f068b5585f47785c41d5
--- /dev/null
+++ b/content/common/vr_param_traits.cc
@@ -0,0 +1,65 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
no sievers 2015/03/19 01:24:52 nit: 2015
+// 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 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.deviceId, WebVRDevice::deviceIdLengthCap, l);
+ l->append(",");
+ LogWebUCharString(p.deviceName, WebVRDevice::deviceNameLengthCap, l);
+ LogParam(p.flags, l);
+ // TODO(bajones): Log the WebVRHMDInfo struct
+ l->append(")");
+}
+
+} // namespace IPC

Powered by Google App Engine
This is Rietveld 408576698