| OLD | NEW |
| 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 "ppapi/proxy/ppb_file_io_proxy.h" | 5 #include "ppapi/proxy/ppb_file_io_proxy.h" |
| 6 | 6 |
| 7 #include "ppapi/c/pp_errors.h" | 7 #include "ppapi/c/pp_errors.h" |
| 8 #include "ppapi/proxy/enter_proxy.h" | 8 #include "ppapi/proxy/enter_proxy.h" |
| 9 #include "ppapi/proxy/ppapi_messages.h" | 9 #include "ppapi/proxy/ppapi_messages.h" |
| 10 #include "ppapi/proxy/ppb_file_ref_proxy.h" | 10 #include "ppapi/proxy/ppb_file_ref_proxy.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 class FileIO : public PPB_FileIO_Shared { | 34 class FileIO : public PPB_FileIO_Shared { |
| 35 public: | 35 public: |
| 36 explicit FileIO(const HostResource& host_resource); | 36 explicit FileIO(const HostResource& host_resource); |
| 37 virtual ~FileIO(); | 37 virtual ~FileIO(); |
| 38 | 38 |
| 39 // PPB_FileIO_API implementation (not provided by FileIOImpl). | 39 // PPB_FileIO_API implementation (not provided by FileIOImpl). |
| 40 virtual void Close() OVERRIDE; | 40 virtual void Close() OVERRIDE; |
| 41 virtual int32_t GetOSFileDescriptor() OVERRIDE; | 41 virtual int32_t GetOSFileDescriptor() OVERRIDE; |
| 42 virtual int32_t WillWrite(int64_t offset, | 42 virtual int32_t WillWrite(int64_t offset, |
| 43 int32_t bytes_to_write, | 43 int32_t bytes_to_write, |
| 44 PP_CompletionCallback callback) OVERRIDE; | 44 ApiCallbackType callback) OVERRIDE; |
| 45 virtual int32_t WillSetLength(int64_t length, | 45 virtual int32_t WillSetLength(int64_t length, |
| 46 PP_CompletionCallback callback) OVERRIDE; | 46 ApiCallbackType callback) OVERRIDE; |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 // FileIOImpl overrides. | 49 // FileIOImpl overrides. |
| 50 virtual int32_t OpenValidated(PP_Resource file_ref_resource, | 50 virtual int32_t OpenValidated(PP_Resource file_ref_resource, |
| 51 PPB_FileRef_API* file_ref_api, | 51 PPB_FileRef_API* file_ref_api, |
| 52 int32_t open_flags, | 52 int32_t open_flags, |
| 53 PP_CompletionCallback callback) OVERRIDE; | 53 ApiCallbackType callback) OVERRIDE; |
| 54 virtual int32_t QueryValidated(PP_FileInfo* info, | 54 virtual int32_t QueryValidated(PP_FileInfo* info, |
| 55 PP_CompletionCallback callback) OVERRIDE; | 55 ApiCallbackType callback) OVERRIDE; |
| 56 virtual int32_t TouchValidated(PP_Time last_access_time, | 56 virtual int32_t TouchValidated(PP_Time last_access_time, |
| 57 PP_Time last_modified_time, | 57 PP_Time last_modified_time, |
| 58 PP_CompletionCallback callback) OVERRIDE; | 58 ApiCallbackType callback) OVERRIDE; |
| 59 virtual int32_t ReadValidated(int64_t offset, | 59 virtual int32_t ReadValidated(int64_t offset, |
| 60 char* buffer, | 60 char* buffer, |
| 61 int32_t bytes_to_read, | 61 int32_t bytes_to_read, |
| 62 PP_CompletionCallback callback) OVERRIDE; | 62 ApiCallbackType callback) OVERRIDE; |
| 63 virtual int32_t WriteValidated(int64_t offset, | 63 virtual int32_t WriteValidated(int64_t offset, |
| 64 const char* buffer, | 64 const char* buffer, |
| 65 int32_t bytes_to_write, | 65 int32_t bytes_to_write, |
| 66 PP_CompletionCallback callback) OVERRIDE; | 66 ApiCallbackType callback) OVERRIDE; |
| 67 virtual int32_t SetLengthValidated(int64_t length, | 67 virtual int32_t SetLengthValidated(int64_t length, |
| 68 PP_CompletionCallback callback) OVERRIDE; | 68 ApiCallbackType callback) OVERRIDE; |
| 69 virtual int32_t FlushValidated(PP_CompletionCallback callback) OVERRIDE; | 69 virtual int32_t FlushValidated(ApiCallbackType callback) OVERRIDE; |
| 70 | 70 |
| 71 PluginDispatcher* GetDispatcher() const { | 71 PluginDispatcher* GetDispatcher() const { |
| 72 return PluginDispatcher::GetForResource(this); | 72 return PluginDispatcher::GetForResource(this); |
| 73 } | 73 } |
| 74 | 74 |
| 75 static const ApiID kApiID = API_ID_PPB_FILE_IO; | 75 static const ApiID kApiID = API_ID_PPB_FILE_IO; |
| 76 | 76 |
| 77 DISALLOW_IMPLICIT_CONSTRUCTORS(FileIO); | 77 DISALLOW_IMPLICIT_CONSTRUCTORS(FileIO); |
| 78 }; | 78 }; |
| 79 | 79 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 91 host_resource())); | 91 host_resource())); |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 int32_t FileIO::GetOSFileDescriptor() { | 95 int32_t FileIO::GetOSFileDescriptor() { |
| 96 return -1; | 96 return -1; |
| 97 } | 97 } |
| 98 | 98 |
| 99 int32_t FileIO::WillWrite(int64_t offset, | 99 int32_t FileIO::WillWrite(int64_t offset, |
| 100 int32_t bytes_to_write, | 100 int32_t bytes_to_write, |
| 101 PP_CompletionCallback callback) { | 101 ApiCallbackType callback) { |
| 102 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_WillWrite( | 102 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_WillWrite( |
| 103 kApiID, host_resource(), offset, bytes_to_write)); | 103 kApiID, host_resource(), offset, bytes_to_write)); |
| 104 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); | 104 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); |
| 105 return PP_OK_COMPLETIONPENDING; | 105 return PP_OK_COMPLETIONPENDING; |
| 106 } | 106 } |
| 107 | 107 |
| 108 int32_t FileIO::WillSetLength(int64_t length, | 108 int32_t FileIO::WillSetLength(int64_t length, |
| 109 PP_CompletionCallback callback) { | 109 ApiCallbackType callback) { |
| 110 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_WillSetLength( | 110 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_WillSetLength( |
| 111 kApiID, host_resource(), length)); | 111 kApiID, host_resource(), length)); |
| 112 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); | 112 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); |
| 113 return PP_OK_COMPLETIONPENDING; | 113 return PP_OK_COMPLETIONPENDING; |
| 114 } | 114 } |
| 115 | 115 |
| 116 int32_t FileIO::OpenValidated(PP_Resource file_ref_resource, | 116 int32_t FileIO::OpenValidated(PP_Resource file_ref_resource, |
| 117 PPB_FileRef_API* file_ref_api, | 117 PPB_FileRef_API* file_ref_api, |
| 118 int32_t open_flags, | 118 int32_t open_flags, |
| 119 PP_CompletionCallback callback) { | 119 ApiCallbackType callback) { |
| 120 Resource* file_ref_object = | 120 Resource* file_ref_object = |
| 121 PpapiGlobals::Get()->GetResourceTracker()->GetResource(file_ref_resource); | 121 PpapiGlobals::Get()->GetResourceTracker()->GetResource(file_ref_resource); |
| 122 | 122 |
| 123 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Open( | 123 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Open( |
| 124 kApiID, host_resource(), file_ref_object->host_resource(), open_flags)); | 124 kApiID, host_resource(), file_ref_object->host_resource(), open_flags)); |
| 125 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); | 125 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); |
| 126 return PP_OK_COMPLETIONPENDING; | 126 return PP_OK_COMPLETIONPENDING; |
| 127 } | 127 } |
| 128 | 128 |
| 129 int32_t FileIO::QueryValidated(PP_FileInfo* info, | 129 int32_t FileIO::QueryValidated(PP_FileInfo* info, |
| 130 PP_CompletionCallback callback) { | 130 ApiCallbackType callback) { |
| 131 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Query( | 131 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Query( |
| 132 kApiID, host_resource())); | 132 kApiID, host_resource())); |
| 133 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, info); | 133 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, info); |
| 134 return PP_OK_COMPLETIONPENDING; | 134 return PP_OK_COMPLETIONPENDING; |
| 135 } | 135 } |
| 136 | 136 |
| 137 int32_t FileIO::TouchValidated(PP_Time last_access_time, | 137 int32_t FileIO::TouchValidated(PP_Time last_access_time, |
| 138 PP_Time last_modified_time, | 138 PP_Time last_modified_time, |
| 139 PP_CompletionCallback callback) { | 139 ApiCallbackType callback) { |
| 140 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Touch( | 140 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Touch( |
| 141 kApiID, host_resource(), last_access_time, last_modified_time)); | 141 kApiID, host_resource(), last_access_time, last_modified_time)); |
| 142 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); | 142 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); |
| 143 return PP_OK_COMPLETIONPENDING; | 143 return PP_OK_COMPLETIONPENDING; |
| 144 } | 144 } |
| 145 | 145 |
| 146 int32_t FileIO::ReadValidated(int64_t offset, | 146 int32_t FileIO::ReadValidated(int64_t offset, |
| 147 char* buffer, | 147 char* buffer, |
| 148 int32_t bytes_to_read, | 148 int32_t bytes_to_read, |
| 149 PP_CompletionCallback callback) { | 149 ApiCallbackType callback) { |
| 150 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Read( | 150 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Read( |
| 151 kApiID, host_resource(), offset, bytes_to_read)); | 151 kApiID, host_resource(), offset, bytes_to_read)); |
| 152 RegisterCallback(OPERATION_READ, callback, buffer, NULL); | 152 RegisterCallback(OPERATION_READ, callback, buffer, NULL); |
| 153 return PP_OK_COMPLETIONPENDING; | 153 return PP_OK_COMPLETIONPENDING; |
| 154 } | 154 } |
| 155 | 155 |
| 156 int32_t FileIO::WriteValidated(int64_t offset, | 156 int32_t FileIO::WriteValidated(int64_t offset, |
| 157 const char* buffer, | 157 const char* buffer, |
| 158 int32_t bytes_to_write, | 158 int32_t bytes_to_write, |
| 159 PP_CompletionCallback callback) { | 159 ApiCallbackType callback) { |
| 160 // TODO(brettw) it would be nice to use a shared memory buffer for large | 160 // TODO(brettw) it would be nice to use a shared memory buffer for large |
| 161 // writes rather than having to copy to a string (which will involve a number | 161 // writes rather than having to copy to a string (which will involve a number |
| 162 // of extra copies to serialize over IPC). | 162 // of extra copies to serialize over IPC). |
| 163 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Write( | 163 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Write( |
| 164 kApiID, host_resource(), offset, std::string(buffer, bytes_to_write))); | 164 kApiID, host_resource(), offset, std::string(buffer, bytes_to_write))); |
| 165 RegisterCallback(OPERATION_WRITE, callback, NULL, NULL); | 165 RegisterCallback(OPERATION_WRITE, callback, NULL, NULL); |
| 166 return PP_OK_COMPLETIONPENDING; | 166 return PP_OK_COMPLETIONPENDING; |
| 167 } | 167 } |
| 168 | 168 |
| 169 int32_t FileIO::SetLengthValidated(int64_t length, | 169 int32_t FileIO::SetLengthValidated(int64_t length, |
| 170 PP_CompletionCallback callback) { | 170 ApiCallbackType callback) { |
| 171 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_SetLength( | 171 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_SetLength( |
| 172 kApiID, host_resource(), length)); | 172 kApiID, host_resource(), length)); |
| 173 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); | 173 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); |
| 174 return PP_OK_COMPLETIONPENDING; | 174 return PP_OK_COMPLETIONPENDING; |
| 175 } | 175 } |
| 176 | 176 |
| 177 int32_t FileIO::FlushValidated(PP_CompletionCallback callback) { | 177 int32_t FileIO::FlushValidated(ApiCallbackType callback) { |
| 178 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Flush( | 178 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Flush( |
| 179 kApiID, host_resource())); | 179 kApiID, host_resource())); |
| 180 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); | 180 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); |
| 181 return PP_OK_COMPLETIONPENDING; | 181 return PP_OK_COMPLETIONPENDING; |
| 182 } | 182 } |
| 183 | 183 |
| 184 } // namespace | 184 } // namespace |
| 185 | 185 |
| 186 // ----------------------------------------------------------------------------- | 186 // ----------------------------------------------------------------------------- |
| 187 | 187 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 DCHECK(pp_error <= static_cast<int32_t>(data->size())); | 433 DCHECK(pp_error <= static_cast<int32_t>(data->size())); |
| 434 data->resize(pp_error); | 434 data->resize(pp_error); |
| 435 } | 435 } |
| 436 Send(new PpapiMsg_PPBFileIO_ReadComplete(kApiID, host_resource, pp_error, | 436 Send(new PpapiMsg_PPBFileIO_ReadComplete(kApiID, host_resource, pp_error, |
| 437 *data)); | 437 *data)); |
| 438 delete data; | 438 delete data; |
| 439 } | 439 } |
| 440 | 440 |
| 441 } // namespace proxy | 441 } // namespace proxy |
| 442 } // namespace ppapi | 442 } // namespace ppapi |
| OLD | NEW |