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

Side by Side Diff: webkit/plugins/ppapi/ppb_file_io_impl.cc

Issue 7038032: Fix PP_FileOpenFlags_Dev handling: (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: . Created 9 years, 7 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) 2011 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 "webkit/plugins/ppapi/ppb_file_io_impl.h" 5 #include "webkit/plugins/ppapi/ppb_file_io_impl.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/file_util_proxy.h" 9 #include "base/file_util_proxy.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
11 #include "base/platform_file.h" 11 #include "base/platform_file.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "ppapi/c/dev/ppb_file_io_dev.h" 14 #include "ppapi/c/dev/ppb_file_io_dev.h"
15 #include "ppapi/c/dev/ppb_file_io_trusted_dev.h" 15 #include "ppapi/c/dev/ppb_file_io_trusted_dev.h"
16 #include "ppapi/c/pp_completion_callback.h" 16 #include "ppapi/c/pp_completion_callback.h"
17 #include "ppapi/c/pp_errors.h" 17 #include "ppapi/c/pp_errors.h"
18 #include "webkit/plugins/ppapi/common.h" 18 #include "webkit/plugins/ppapi/common.h"
19 #include "webkit/plugins/ppapi/file_type_conversions.h"
19 #include "webkit/plugins/ppapi/plugin_module.h" 20 #include "webkit/plugins/ppapi/plugin_module.h"
20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 21 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
21 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" 22 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
22 #include "webkit/plugins/ppapi/resource_tracker.h" 23 #include "webkit/plugins/ppapi/resource_tracker.h"
23 24
24 namespace webkit { 25 namespace webkit {
25 namespace ppapi { 26 namespace ppapi {
26 27
27 namespace { 28 namespace {
28 29
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 return PP_ERROR_BADRESOURCE; 170 return PP_ERROR_BADRESOURCE;
170 return file_io->WillSetLength(length, callback); 171 return file_io->WillSetLength(length, callback);
171 } 172 }
172 173
173 const PPB_FileIOTrusted_Dev ppb_fileiotrusted = { 174 const PPB_FileIOTrusted_Dev ppb_fileiotrusted = {
174 &GetOSFileDescriptor, 175 &GetOSFileDescriptor,
175 &WillWrite, 176 &WillWrite,
176 &WillSetLength 177 &WillSetLength
177 }; 178 };
178 179
179 int PlatformFileErrorToPepperError(base::PlatformFileError error_code) {
180 switch (error_code) {
181 case base::PLATFORM_FILE_OK:
182 return PP_OK;
183 case base::PLATFORM_FILE_ERROR_EXISTS:
184 return PP_ERROR_FILEEXISTS;
185 case base::PLATFORM_FILE_ERROR_NOT_FOUND:
186 return PP_ERROR_FILENOTFOUND;
187 case base::PLATFORM_FILE_ERROR_ACCESS_DENIED:
188 return PP_ERROR_NOACCESS;
189 case base::PLATFORM_FILE_ERROR_NO_MEMORY:
190 return PP_ERROR_NOMEMORY;
191 case base::PLATFORM_FILE_ERROR_NO_SPACE:
192 return PP_ERROR_NOSPACE;
193 case base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY:
194 NOTREACHED();
195 return PP_ERROR_FAILED;
196 default:
197 return PP_ERROR_FAILED;
198 }
199 }
200
201 } // namespace 180 } // namespace
202 181
203 PPB_FileIO_Impl::PPB_FileIO_Impl(PluginInstance* instance) 182 PPB_FileIO_Impl::PPB_FileIO_Impl(PluginInstance* instance)
204 : Resource(instance), 183 : Resource(instance),
205 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)), 184 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)),
206 file_(base::kInvalidPlatformFileValue), 185 file_(base::kInvalidPlatformFileValue),
207 callback_(), 186 callback_(),
208 info_(NULL), 187 info_(NULL),
209 read_buffer_(NULL) { 188 read_buffer_(NULL) {
210 } 189 }
(...skipping 17 matching lines...) Expand all
228 } 207 }
229 208
230 int32_t PPB_FileIO_Impl::Open(PPB_FileRef_Impl* file_ref, 209 int32_t PPB_FileIO_Impl::Open(PPB_FileRef_Impl* file_ref,
231 int32_t open_flags, 210 int32_t open_flags,
232 PP_CompletionCallback callback) { 211 PP_CompletionCallback callback) {
233 int32_t rv = CommonCallValidation(false, callback); 212 int32_t rv = CommonCallValidation(false, callback);
234 if (rv != PP_OK) 213 if (rv != PP_OK)
235 return rv; 214 return rv;
236 215
237 int flags = 0; 216 int flags = 0;
238 if (open_flags & PP_FILEOPENFLAG_READ) 217 if (!PepperFileOpenFlagsToPlatformFileFlags(open_flags, &flags))
239 flags |= base::PLATFORM_FILE_READ; 218 return PP_ERROR_BADARGUMENT;
240 if (open_flags & PP_FILEOPENFLAG_WRITE) {
241 flags |= base::PLATFORM_FILE_WRITE;
242 flags |= base::PLATFORM_FILE_WRITE_ATTRIBUTES;
243 }
244 219
245 if (open_flags & PP_FILEOPENFLAG_TRUNCATE) {
246 DCHECK(open_flags & PP_FILEOPENFLAG_WRITE);
247 flags |= base::PLATFORM_FILE_TRUNCATE;
248 } else if (open_flags & PP_FILEOPENFLAG_CREATE) {
249 if (open_flags & PP_FILEOPENFLAG_EXCLUSIVE)
250 flags |= base::PLATFORM_FILE_CREATE;
251 else
252 flags |= base::PLATFORM_FILE_OPEN_ALWAYS;
253 } else {
254 flags |= base::PLATFORM_FILE_OPEN;
255 }
256 file_system_type_ = file_ref->GetFileSystemType(); 220 file_system_type_ = file_ref->GetFileSystemType();
257 switch (file_system_type_) { 221 switch (file_system_type_) {
258 case PP_FILESYSTEMTYPE_EXTERNAL: 222 case PP_FILESYSTEMTYPE_EXTERNAL:
259 if (!instance()->delegate()->AsyncOpenFile( 223 if (!instance()->delegate()->AsyncOpenFile(
260 file_ref->GetSystemPath(), flags, 224 file_ref->GetSystemPath(), flags,
261 callback_factory_.NewCallback( 225 callback_factory_.NewCallback(
262 &PPB_FileIO_Impl::AsyncOpenFileCallback))) 226 &PPB_FileIO_Impl::AsyncOpenFileCallback)))
263 return PP_ERROR_FAILED; 227 return PP_ERROR_FAILED;
264 break; 228 break;
265 case PP_FILESYSTEMTYPE_LOCALPERSISTENT: 229 case PP_FILESYSTEMTYPE_LOCALPERSISTENT:
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 void PPB_FileIO_Impl::WriteCallback(base::PlatformFileError error_code, 471 void PPB_FileIO_Impl::WriteCallback(base::PlatformFileError error_code,
508 int bytes_written) { 472 int bytes_written) {
509 if (error_code != base::PLATFORM_FILE_OK) 473 if (error_code != base::PLATFORM_FILE_OK)
510 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); 474 RunPendingCallback(PlatformFileErrorToPepperError(error_code));
511 else 475 else
512 RunPendingCallback(bytes_written); 476 RunPendingCallback(bytes_written);
513 } 477 }
514 478
515 } // namespace ppapi 479 } // namespace ppapi
516 } // namespace webkit 480 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/file_type_conversions.cc ('k') | webkit/plugins/ppapi/ppb_flash_file_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698