| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_ | |
| 6 #define WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/compiler_specific.h" | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "ppapi/shared_impl/ppb_file_io_shared.h" | |
| 14 #include "webkit/plugins/ppapi/plugin_delegate.h" | |
| 15 | |
| 16 namespace webkit { | |
| 17 namespace ppapi { | |
| 18 | |
| 19 class QuotaFileIO; | |
| 20 | |
| 21 class PPB_FileIO_Impl : public ::ppapi::PPB_FileIO_Shared { | |
| 22 public: | |
| 23 explicit PPB_FileIO_Impl(PP_Instance instance); | |
| 24 virtual ~PPB_FileIO_Impl(); | |
| 25 | |
| 26 // PPB_FileIO_API implementation (most of the operations are implemented | |
| 27 // as the "Validated" versions below). | |
| 28 virtual void Close() OVERRIDE; | |
| 29 virtual int32_t GetOSFileDescriptor() OVERRIDE; | |
| 30 virtual int32_t WillWrite( | |
| 31 int64_t offset, | |
| 32 int32_t bytes_to_write, | |
| 33 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; | |
| 34 virtual int32_t WillSetLength( | |
| 35 int64_t length, | |
| 36 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; | |
| 37 | |
| 38 private: | |
| 39 // FileIOImpl overrides. | |
| 40 virtual int32_t OpenValidated( | |
| 41 PP_Resource file_ref_resource, | |
| 42 ::ppapi::thunk::PPB_FileRef_API* file_ref_api, | |
| 43 int32_t open_flags, | |
| 44 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; | |
| 45 virtual int32_t QueryValidated( | |
| 46 PP_FileInfo* info, | |
| 47 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; | |
| 48 virtual int32_t TouchValidated( | |
| 49 PP_Time last_access_time, | |
| 50 PP_Time last_modified_time, | |
| 51 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; | |
| 52 virtual int32_t ReadValidated( | |
| 53 int64_t offset, | |
| 54 const PP_ArrayOutput& output_array_buffer, | |
| 55 int32_t max_read_length, | |
| 56 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; | |
| 57 virtual int32_t WriteValidated( | |
| 58 int64_t offset, | |
| 59 const char* buffer, | |
| 60 int32_t bytes_to_write, | |
| 61 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; | |
| 62 virtual int32_t SetLengthValidated( | |
| 63 int64_t length, | |
| 64 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; | |
| 65 virtual int32_t FlushValidated( | |
| 66 scoped_refptr< ::ppapi::TrackedCallback> callback) OVERRIDE; | |
| 67 | |
| 68 // Returns the plugin delegate for this resource if it exists, or NULL if it | |
| 69 // doesn't. Calling code should always check for NULL. | |
| 70 PluginDelegate* GetPluginDelegate(); | |
| 71 | |
| 72 // Callback handlers. These mostly convert the PlatformFileError to the | |
| 73 // PP_Error code and call the shared (non-"Platform") version. | |
| 74 void ExecutePlatformGeneralCallback(base::PlatformFileError error_code); | |
| 75 void ExecutePlatformOpenFileCallback(base::PlatformFileError error_code, | |
| 76 base::PassPlatformFile file); | |
| 77 void ExecutePlatformOpenFileSystemURLCallback( | |
| 78 base::PlatformFileError error_code, | |
| 79 base::PassPlatformFile file, | |
| 80 const PluginDelegate::NotifyCloseFileCallback& callback); | |
| 81 void ExecutePlatformQueryCallback(base::PlatformFileError error_code, | |
| 82 const base::PlatformFileInfo& file_info); | |
| 83 void ExecutePlatformReadCallback(base::PlatformFileError error_code, | |
| 84 const char* data, int bytes_read); | |
| 85 void ExecutePlatformWriteCallback(base::PlatformFileError error_code, | |
| 86 int bytes_written); | |
| 87 void ExecutePlatformWillWriteCallback(base::PlatformFileError error_code, | |
| 88 int bytes_written); | |
| 89 | |
| 90 base::PlatformFile file_; | |
| 91 | |
| 92 // Valid only for PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY}. | |
| 93 GURL file_system_url_; | |
| 94 | |
| 95 // Callback function for notifying when the file handle is closed. | |
| 96 PluginDelegate::NotifyCloseFileCallback notify_close_file_callback_; | |
| 97 | |
| 98 // Pointer to a QuotaFileIO instance, which is valid only while a file | |
| 99 // of type PP_FILESYSTEMTYPE_LOCAL{PERSISTENT,TEMPORARY} is opened. | |
| 100 scoped_ptr<QuotaFileIO> quota_file_io_; | |
| 101 | |
| 102 base::WeakPtrFactory<PPB_FileIO_Impl> weak_factory_; | |
| 103 | |
| 104 DISALLOW_COPY_AND_ASSIGN(PPB_FileIO_Impl); | |
| 105 }; | |
| 106 | |
| 107 } // namespace ppapi | |
| 108 } // namespace webkit | |
| 109 | |
| 110 #endif // WEBKIT_PLUGINS_PPAPI_PPB_FILE_IO_IMPL_H_ | |
| OLD | NEW |