| OLD | NEW |
| 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 #ifndef PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_ | 5 #ifndef PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_ |
| 6 #define PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_ | 6 #define PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "ppapi/shared_impl/ppapi_shared_export.h" | 11 #include "ppapi/shared_impl/ppapi_shared_export.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 25 PPB_FileIO_Shared(PP_Instance instance); | 25 PPB_FileIO_Shared(PP_Instance instance); |
| 26 PPB_FileIO_Shared(const HostResource& host_resource); | 26 PPB_FileIO_Shared(const HostResource& host_resource); |
| 27 ~PPB_FileIO_Shared(); | 27 ~PPB_FileIO_Shared(); |
| 28 | 28 |
| 29 // Resource overrides. | 29 // Resource overrides. |
| 30 virtual thunk::PPB_FileIO_API* AsPPB_FileIO_API() OVERRIDE; | 30 virtual thunk::PPB_FileIO_API* AsPPB_FileIO_API() OVERRIDE; |
| 31 | 31 |
| 32 // PPB_FileIO_API implementation. | 32 // PPB_FileIO_API implementation. |
| 33 virtual int32_t Open(PP_Resource file_ref, | 33 virtual int32_t Open(PP_Resource file_ref, |
| 34 int32_t open_flags, | 34 int32_t open_flags, |
| 35 PP_CompletionCallback callback) OVERRIDE; | 35 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 36 virtual int32_t Query(PP_FileInfo* info, | 36 virtual int32_t Query(PP_FileInfo* info, |
| 37 PP_CompletionCallback callback) OVERRIDE; | 37 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 38 virtual int32_t Touch(PP_Time last_access_time, | 38 virtual int32_t Touch(PP_Time last_access_time, |
| 39 PP_Time last_modified_time, | 39 PP_Time last_modified_time, |
| 40 PP_CompletionCallback callback) OVERRIDE; | 40 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 41 virtual int32_t Read(int64_t offset, | 41 virtual int32_t Read(int64_t offset, |
| 42 char* buffer, | 42 char* buffer, |
| 43 int32_t bytes_to_read, | 43 int32_t bytes_to_read, |
| 44 PP_CompletionCallback callback) OVERRIDE; | 44 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 45 virtual int32_t Write(int64_t offset, | 45 virtual int32_t Write(int64_t offset, |
| 46 const char* buffer, | 46 const char* buffer, |
| 47 int32_t bytes_to_write, | 47 int32_t bytes_to_write, |
| 48 PP_CompletionCallback callback) OVERRIDE; | 48 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 49 virtual int32_t SetLength(int64_t length, | 49 virtual int32_t SetLength(int64_t length, |
| 50 PP_CompletionCallback callback) OVERRIDE; | 50 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 51 virtual int32_t Flush(PP_CompletionCallback callback) OVERRIDE; | 51 virtual int32_t Flush(scoped_refptr<TrackedCallback> callback) OVERRIDE; |
| 52 | 52 |
| 53 // Callback handler for different types of operations. | 53 // Callback handler for different types of operations. |
| 54 void ExecuteGeneralCallback(int32_t pp_error); | 54 void ExecuteGeneralCallback(int32_t pp_error); |
| 55 void ExecuteOpenFileCallback(int32_t pp_error); | 55 void ExecuteOpenFileCallback(int32_t pp_error); |
| 56 void ExecuteQueryCallback(int32_t pp_error, const PP_FileInfo& info); | 56 void ExecuteQueryCallback(int32_t pp_error, const PP_FileInfo& info); |
| 57 void ExecuteReadCallback(int32_t pp_error, const char* data); | 57 void ExecuteReadCallback(int32_t pp_error, const char* data); |
| 58 | 58 |
| 59 protected: | 59 protected: |
| 60 struct CallbackEntry { | 60 struct CallbackEntry { |
| 61 CallbackEntry(); | 61 CallbackEntry(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 88 // If there is a pending operation that is neither read nor write, no | 88 // If there is a pending operation that is neither read nor write, no |
| 89 // further async operation is allowed. | 89 // further async operation is allowed. |
| 90 OPERATION_EXCLUSIVE | 90 OPERATION_EXCLUSIVE |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 // Validated versions of the FileIO API. Subclasses in the proxy and impl | 93 // Validated versions of the FileIO API. Subclasses in the proxy and impl |
| 94 // implement these so the common error checking stays here. | 94 // implement these so the common error checking stays here. |
| 95 virtual int32_t OpenValidated(PP_Resource file_ref_resource, | 95 virtual int32_t OpenValidated(PP_Resource file_ref_resource, |
| 96 thunk::PPB_FileRef_API* file_ref_api, | 96 thunk::PPB_FileRef_API* file_ref_api, |
| 97 int32_t open_flags, | 97 int32_t open_flags, |
| 98 PP_CompletionCallback callback) = 0; | 98 scoped_refptr<TrackedCallback> callback) = 0; |
| 99 virtual int32_t QueryValidated(PP_FileInfo* info, | 99 virtual int32_t QueryValidated(PP_FileInfo* info, |
| 100 PP_CompletionCallback callback) = 0; | 100 scoped_refptr<TrackedCallback> callback) = 0; |
| 101 virtual int32_t TouchValidated(PP_Time last_access_time, | 101 virtual int32_t TouchValidated(PP_Time last_access_time, |
| 102 PP_Time last_modified_time, | 102 PP_Time last_modified_time, |
| 103 PP_CompletionCallback callback) = 0; | 103 scoped_refptr<TrackedCallback> callback) = 0; |
| 104 virtual int32_t ReadValidated(int64_t offset, | 104 virtual int32_t ReadValidated(int64_t offset, |
| 105 char* buffer, | 105 char* buffer, |
| 106 int32_t bytes_to_read, | 106 int32_t bytes_to_read, |
| 107 PP_CompletionCallback callback) = 0; | 107 scoped_refptr<TrackedCallback> callback) = 0; |
| 108 virtual int32_t WriteValidated(int64_t offset, | 108 virtual int32_t WriteValidated(int64_t offset, |
| 109 const char* buffer, | 109 const char* buffer, |
| 110 int32_t bytes_to_write, | 110 int32_t bytes_to_write, |
| 111 PP_CompletionCallback callback) = 0; | 111 scoped_refptr<TrackedCallback> callback) = 0; |
| 112 virtual int32_t SetLengthValidated(int64_t length, | 112 virtual int32_t SetLengthValidated( |
| 113 PP_CompletionCallback callback) = 0; | 113 int64_t length, |
| 114 virtual int32_t FlushValidated(PP_CompletionCallback callback) = 0; | 114 scoped_refptr<TrackedCallback> callback) = 0; |
| 115 virtual int32_t FlushValidated(scoped_refptr<TrackedCallback> callback) = 0; |
| 115 | 116 |
| 116 // Called for every "Validated" function. | 117 // Called for every "Validated" function. |
| 117 // | 118 // |
| 118 // This verifies that the callback is valid and that no callback is already | 119 // This verifies that the callback is valid and that no callback is already |
| 119 // pending, or it is a read(write) request and currently the pending | 120 // pending, or it is a read(write) request and currently the pending |
| 120 // operations are reads(writes). | 121 // operations are reads(writes). |
| 121 // | 122 // |
| 122 // Returns |PP_OK| to indicate that everything is valid or |PP_ERROR_...| if | 123 // Returns |PP_OK| to indicate that everything is valid or |PP_ERROR_...| if |
| 123 // the call should be aborted and that code returned to the plugin. | 124 // the call should be aborted and that code returned to the plugin. |
| 124 int32_t CommonCallValidation(bool should_be_open, | 125 int32_t CommonCallValidation(bool should_be_open, OperationType new_op); |
| 125 OperationType new_op, | |
| 126 PP_CompletionCallback callback); | |
| 127 | 126 |
| 128 // Sets up a pending callback. This should only be called once it is certain | 127 // Sets up a pending callback. This should only be called once it is certain |
| 129 // that |PP_OK_COMPLETIONPENDING| will be returned. | 128 // that |PP_OK_COMPLETIONPENDING| will be returned. |
| 130 // | 129 // |
| 131 // |read_buffer| is only used by read operations, |info| is used only by | 130 // |read_buffer| is only used by read operations, |info| is used only by |
| 132 // query operations. | 131 // query operations. |
| 133 void RegisterCallback(OperationType op, | 132 void RegisterCallback(OperationType op, |
| 134 PP_CompletionCallback callback, | 133 scoped_refptr<TrackedCallback> callback, |
| 135 char* read_buffer, | 134 char* read_buffer, |
| 136 PP_FileInfo* info); | 135 PP_FileInfo* info); |
| 137 | 136 |
| 138 // Pops the oldest callback from the queue and runs it. | 137 // Pops the oldest callback from the queue and runs it. |
| 139 void RunAndRemoveFirstPendingCallback(int32_t result); | 138 void RunAndRemoveFirstPendingCallback(int32_t result); |
| 140 | 139 |
| 141 // The file system type specified in the Open() call. This will be | 140 // The file system type specified in the Open() call. This will be |
| 142 // PP_FILESYSTEMTYPE_INVALID before open was called. This value does not | 141 // PP_FILESYSTEMTYPE_INVALID before open was called. This value does not |
| 143 // indicate that the open command actually succeeded. | 142 // indicate that the open command actually succeeded. |
| 144 PP_FileSystemType file_system_type_; | 143 PP_FileSystemType file_system_type_; |
| 145 | 144 |
| 146 // Set to true when the file has been successfully opened. | 145 // Set to true when the file has been successfully opened. |
| 147 bool file_open_; | 146 bool file_open_; |
| 148 | 147 |
| 149 std::deque<CallbackEntry> callbacks_; | 148 std::deque<CallbackEntry> callbacks_; |
| 150 OperationType pending_op_; | 149 OperationType pending_op_; |
| 151 | 150 |
| 152 DISALLOW_COPY_AND_ASSIGN(PPB_FileIO_Shared); | 151 DISALLOW_COPY_AND_ASSIGN(PPB_FileIO_Shared); |
| 153 }; | 152 }; |
| 154 | 153 |
| 155 } // namespace ppapi | 154 } // namespace ppapi |
| 156 | 155 |
| 157 #endif // PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_ | 156 #endif // PPAPI_SHARED_IMPL_PPB_FILE_IO_SHARED_H_ |
| OLD | NEW |