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

Side by Side 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: Addressed the rest of sievers@ input 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 unified diff | Download patch
OLDNEW
(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(
18 const blink::WebUChar web_string[],
19 const size_t array_size,
20 std::string* log) {
21 base::string16 utf16;
22 utf16.reserve(array_size);
23 for (size_t i = 0; i < array_size && web_string[i]; ++i) {
24 utf16[i] = web_string[i];
25 }
26 log->append(base::UTF16ToUTF8(utf16));
27 }
28
29 }
30
31 namespace IPC {
32
33 void ParamTraits<WebVRDevice>::Write(
34 Message* m,
35 const WebVRDevice& p) {
36 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(WebVRDevice));
37 }
38
39 bool ParamTraits<WebVRDevice>::Read(
40 const Message* m,
41 PickleIterator* iter,
42 WebVRDevice* p) {
43 int length;
44 const char* data;
45 if (!iter->ReadData(&data, &length) || length != sizeof(WebVRDevice))
46 return false;
47 memcpy(p, data, sizeof(WebVRDevice));
48
49 return true;
50 }
51
52 void ParamTraits<WebVRDevice>::Log(
53 const WebVRDevice& p,
54 std::string* l) {
55 l->append("WebVRDevice(");
56 LogParam(p.index, l);
57 LogWebUCharString(p.deviceId, WebVRDevice::deviceIdLengthCap, l);
58 l->append(",");
59 LogWebUCharString(p.deviceName, WebVRDevice::deviceNameLengthCap, l);
60 LogParam(p.flags, l);
61 // TODO(bajones): Log the WebVRHMDInfo struct
62 l->append(")");
63 }
64
65 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698