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

Side by Side Diff: ppapi/proxy/serialized_structs.cc

Issue 10828023: PPAPI/NaCl: Make NaClIPCAdapter transfer handles more generally (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed some proxy changes that aren't necessary now Created 8 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/proxy/serialized_structs.h" 5 #include "ppapi/proxy/serialized_structs.h"
6 6
7 #include "base/pickle.h"
7 #include "ppapi/c/dev/ppb_font_dev.h" 8 #include "ppapi/c/dev/ppb_font_dev.h"
8 #include "ppapi/c/pp_file_info.h" 9 #include "ppapi/c/pp_file_info.h"
9 #include "ppapi/c/pp_rect.h" 10 #include "ppapi/c/pp_rect.h"
10 11
11 namespace ppapi { 12 namespace ppapi {
12 namespace proxy { 13 namespace proxy {
13 14
14 SerializedFontDescription::SerializedFontDescription() 15 SerializedFontDescription::SerializedFontDescription()
15 : face(), 16 : face(),
16 family(0), 17 family(0),
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 clip.point.y = 0; 72 clip.point.y = 0;
72 clip.size.height = 0; 73 clip.size.height = 0;
73 clip.size.width = 0; 74 clip.size.width = 0;
74 position.x = 0; 75 position.x = 0;
75 position.y = 0; 76 position.y = 0;
76 allow_subpixel_aa = PP_FALSE; 77 allow_subpixel_aa = PP_FALSE;
77 } 78 }
78 79
79 PPBFlash_DrawGlyphs_Params::~PPBFlash_DrawGlyphs_Params() {} 80 PPBFlash_DrawGlyphs_Params::~PPBFlash_DrawGlyphs_Params() {}
80 81
82 SerializedHandle::SerializedHandle()
83 : type_(INVALID),
84 shm_handle_(base::SharedMemory::NULLHandle()),
85 size_(0),
86 descriptor_(IPC::InvalidPlatformFileForTransit()) {
87 }
88
89 SerializedHandle::SerializedHandle(Type type_param)
90 : type_(type_param),
91 shm_handle_(base::SharedMemory::NULLHandle()),
92 size_(0),
93 descriptor_(IPC::InvalidPlatformFileForTransit()) {
94 }
95
96 SerializedHandle::SerializedHandle(const base::SharedMemoryHandle& handle,
97 uint32_t size)
98 : type_(SHARED_MEMORY),
99 shm_handle_(handle),
100 size_(size),
101 descriptor_(IPC::InvalidPlatformFileForTransit()) {
102 }
103
104 SerializedHandle::SerializedHandle(
105 const IPC::PlatformFileForTransit& socket_descriptor)
106 : type_(SOCKET),
107 shm_handle_(base::SharedMemory::NULLHandle()),
108 size_(0),
109 descriptor_(socket_descriptor) {
110 }
111
112 bool SerializedHandle::IsHandleValid() const {
113 if (type_ == SHARED_MEMORY)
114 return base::SharedMemory::IsHandleValid(shm_handle_);
115 else if (type_ == SOCKET)
116 return (IPC::InvalidPlatformFileForTransit() == descriptor_);
117 return false;
118 }
119
120 // static
121 bool SerializedHandle::WriteHeader(const Header& hdr, Pickle* pickle) {
122 if (!pickle->WriteInt(hdr.type))
123 return false;
124 if (hdr.type == SHARED_MEMORY) {
125 if (!pickle->WriteUInt32(hdr.size))
126 return false;
127 }
128 return true;
129 }
130
131 // static
132 bool SerializedHandle::ReadHeader(PickleIterator* iter, Header* hdr) {
133 if (!hdr)
brettw 2012/08/22 23:27:06 I probably wouldn't null check the output param. A
dmichael (off chromium) 2012/08/23 22:55:14 Done.
134 return false;
135 *hdr = Header(INVALID, 0);
136 int type = 0;
137 if (!iter->ReadInt(&type))
138 return false;
139 bool valid_type = false;
140 switch (type) {
141 case SHARED_MEMORY: {
142 uint32_t size = 0;
143 if (!iter->ReadUInt32(&size))
144 return false;
145 hdr->size = size;
146 valid_type = true;
147 break;
148 }
149 case SOCKET:
150 valid_type = true;
151 break;
152 case INVALID:
153 valid_type = true;
154 break;
155 // No default so the compiler will warn us if a new type is added.
156 }
157 if (valid_type)
158 hdr->type = Type(type);
159 return valid_type;
160 }
161
81 } // namespace proxy 162 } // namespace proxy
82 } // namespace ppapi 163 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698