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

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

Issue 11359097: Refactored the PPB_Flash_File_ModuleLocal/FileRef to the new ppapi resource model (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month 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) 2012 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 "base/pickle.h"
8 #include "base/platform_file.h" 8 #include "base/platform_file.h"
9 #include "base/shared_memory.h" 9 #include "base/shared_memory.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 SerializedHandle::SerializedHandle( 100 SerializedHandle::SerializedHandle(
101 Type type, 101 Type type,
102 const IPC::PlatformFileForTransit& socket_descriptor) 102 const IPC::PlatformFileForTransit& socket_descriptor)
103 : type_(type), 103 : type_(type),
104 shm_handle_(base::SharedMemory::NULLHandle()), 104 shm_handle_(base::SharedMemory::NULLHandle()),
105 size_(0), 105 size_(0),
106 descriptor_(socket_descriptor) { 106 descriptor_(socket_descriptor) {
107 } 107 }
108 108
109 bool SerializedHandle::IsHandleValid() const { 109 bool SerializedHandle::IsHandleValid() const {
110 if (type_ == SHARED_MEMORY) 110 switch (type_) {
111 return base::SharedMemory::IsHandleValid(shm_handle_); 111 case SHARED_MEMORY:
112 else if (type_ == SOCKET || type_ == CHANNEL_HANDLE) 112 return base::SharedMemory::IsHandleValid(shm_handle_);
113 return !(IPC::InvalidPlatformFileForTransit() == descriptor_); 113 case SOCKET:
114 case CHANNEL_HANDLE:
115 case FILE:
116 return !(IPC::InvalidPlatformFileForTransit() == descriptor_);
117 case INVALID:
118 return false;
119 // No default so the compiler will warn us if a new type is added.
120 }
114 return false; 121 return false;
115 } 122 }
116 123
117 void SerializedHandle::Close() { 124 void SerializedHandle::Close() {
118 if (IsHandleValid()) { 125 if (IsHandleValid()) {
119 switch (type_) { 126 switch (type_) {
120 case INVALID: 127 case INVALID:
121 NOTREACHED(); 128 NOTREACHED();
122 break; 129 break;
123 case SHARED_MEMORY: 130 case SHARED_MEMORY:
124 base::SharedMemory::CloseHandle(shm_handle_); 131 base::SharedMemory::CloseHandle(shm_handle_);
125 break; 132 break;
126 case SOCKET: 133 case SOCKET:
127 case CHANNEL_HANDLE: 134 case CHANNEL_HANDLE:
135 case FILE:
128 base::PlatformFile file = 136 base::PlatformFile file =
129 IPC::PlatformFileForTransitToPlatformFile(descriptor_); 137 IPC::PlatformFileForTransitToPlatformFile(descriptor_);
130 #if !defined(OS_NACL) 138 #if !defined(OS_NACL)
131 base::ClosePlatformFile(file); 139 base::ClosePlatformFile(file);
132 #else 140 #else
133 close(file); 141 close(file);
134 #endif 142 #endif
135 break; 143 break;
136 // No default so the compiler will warn us if a new type is added. 144 // No default so the compiler will warn us if a new type is added.
137 } 145 }
(...skipping 23 matching lines...) Expand all
161 case SHARED_MEMORY: { 169 case SHARED_MEMORY: {
162 uint32_t size = 0; 170 uint32_t size = 0;
163 if (!iter->ReadUInt32(&size)) 171 if (!iter->ReadUInt32(&size))
164 return false; 172 return false;
165 hdr->size = size; 173 hdr->size = size;
166 valid_type = true; 174 valid_type = true;
167 break; 175 break;
168 } 176 }
169 case SOCKET: 177 case SOCKET:
170 case CHANNEL_HANDLE: 178 case CHANNEL_HANDLE:
179 case FILE:
171 case INVALID: 180 case INVALID:
172 valid_type = true; 181 valid_type = true;
173 break; 182 break;
174 // No default so the compiler will warn us if a new type is added. 183 // No default so the compiler will warn us if a new type is added.
175 } 184 }
176 if (valid_type) 185 if (valid_type)
177 hdr->type = Type(type); 186 hdr->type = Type(type);
178 return valid_type; 187 return valid_type;
179 } 188 }
180 189
181 } // namespace proxy 190 } // namespace proxy
182 } // namespace ppapi 191 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698