OLD | NEW |
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 #ifndef PPAPI_PROXY_FILE_IO_RESOURCE_H_ | 5 #ifndef PPAPI_PROXY_FILE_IO_RESOURCE_H_ |
6 #define PPAPI_PROXY_FILE_IO_RESOURCE_H_ | 6 #define PPAPI_PROXY_FILE_IO_RESOURCE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "ppapi/c/private/pp_file_handle.h" | 10 #include "ppapi/c/private/pp_file_handle.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 scoped_refptr<TrackedCallback> callback) OVERRIDE; | 64 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
65 virtual int32_t WillSetLength( | 65 virtual int32_t WillSetLength( |
66 int64_t length, | 66 int64_t length, |
67 scoped_refptr<TrackedCallback> callback) OVERRIDE; | 67 scoped_refptr<TrackedCallback> callback) OVERRIDE; |
68 | 68 |
69 private: | 69 private: |
70 int32_t ReadValidated(int64_t offset, | 70 int32_t ReadValidated(int64_t offset, |
71 int32_t bytes_to_read, | 71 int32_t bytes_to_read, |
72 const PP_ArrayOutput& array_output, | 72 const PP_ArrayOutput& array_output, |
73 scoped_refptr<TrackedCallback> callback); | 73 scoped_refptr<TrackedCallback> callback); |
| 74 void CloseFileHandle(); |
74 | 75 |
75 // Handlers of reply messages. Note that all of them have a callback | 76 // Reply message handlers for operations that are done in the host. |
76 // parameters bound when call to the host. | |
77 void OnPluginMsgGeneralComplete(scoped_refptr<TrackedCallback> callback, | 77 void OnPluginMsgGeneralComplete(scoped_refptr<TrackedCallback> callback, |
78 const ResourceMessageReplyParams& params); | 78 const ResourceMessageReplyParams& params); |
79 void OnPluginMsgOpenFileComplete(scoped_refptr<TrackedCallback> callback, | 79 void OnPluginMsgOpenFileComplete(scoped_refptr<TrackedCallback> callback, |
80 const ResourceMessageReplyParams& params); | 80 const ResourceMessageReplyParams& params); |
81 void OnPluginMsgQueryComplete(scoped_refptr<TrackedCallback> callback, | |
82 PP_FileInfo* output_info_, | |
83 const ResourceMessageReplyParams& params, | |
84 const PP_FileInfo& info); | |
85 void OnPluginMsgReadComplete(scoped_refptr<TrackedCallback> callback, | |
86 PP_ArrayOutput array_output, | |
87 const ResourceMessageReplyParams& params, | |
88 const std::string& data); | |
89 void OnPluginMsgRequestOSFileHandleComplete( | 81 void OnPluginMsgRequestOSFileHandleComplete( |
90 scoped_refptr<TrackedCallback> callback, | 82 scoped_refptr<TrackedCallback> callback, |
91 PP_FileHandle* output_handle, | 83 PP_FileHandle* output_handle, |
92 const ResourceMessageReplyParams& params); | 84 const ResourceMessageReplyParams& params); |
93 | 85 |
| 86 // When we pass a callback to FileUtilProxy code, we must keep the resource |
| 87 // alive until it's called. However, we can't directly pass a reference to the |
| 88 // resource, since that can cause our destructor to run when when the callback |
| 89 // is destroyed, when we don't hold the proxy lock. Instead, pass a scoped_ptr |
| 90 // to a scoped_refptr. This keeps the resource alive and allows us to take the |
| 91 // reference so the destructor only runs while we hold the lock. |
| 92 typedef scoped_ptr<scoped_refptr<FileIOResource> > PassedRef; |
| 93 |
| 94 // These callbacks can be safely passed to FileUtilProxy. They take the lock, |
| 95 // then take the resource reference and run the reply message handler. If |
| 96 // this is the last reference, the destructor will run while we hold the lock. |
| 97 static void QueryCallback(PassedRef file_io_ref, |
| 98 scoped_refptr<TrackedCallback> callback, |
| 99 PP_FileInfo* output_info, |
| 100 base::PlatformFileError error_code, |
| 101 const base::PlatformFileInfo& file_info); |
| 102 |
| 103 static void ReadCallback(PassedRef file_io_ref, |
| 104 scoped_refptr<TrackedCallback> callback, |
| 105 PP_ArrayOutput array_output, |
| 106 base::PlatformFileError error_code, |
| 107 const char* data, int bytes_read); |
| 108 |
| 109 // Reply message handlers for operations that are done in the plugin process. |
| 110 // These should not be called directly. |
| 111 void OnQueryComplete(scoped_refptr<TrackedCallback> callback, |
| 112 PP_FileInfo* output_info, |
| 113 base::PlatformFileError error_code, |
| 114 const base::PlatformFileInfo& file_info); |
| 115 void OnReadComplete(scoped_refptr<TrackedCallback> callback, |
| 116 PP_ArrayOutput array_output, |
| 117 base::PlatformFileError error_code, |
| 118 const char* data, int bytes_read); |
| 119 |
| 120 PP_FileHandle file_handle_; |
| 121 PP_FileSystemType file_system_type_; |
94 FileIOStateManager state_manager_; | 122 FileIOStateManager state_manager_; |
95 | 123 |
96 DISALLOW_COPY_AND_ASSIGN(FileIOResource); | 124 DISALLOW_COPY_AND_ASSIGN(FileIOResource); |
97 }; | 125 }; |
98 | 126 |
99 } // namespace proxy | 127 } // namespace proxy |
100 } // namespace ppapi | 128 } // namespace ppapi |
101 | 129 |
102 #endif // PPAPI_PROXY_FILE_IO_RESOURCE_H_ | 130 #endif // PPAPI_PROXY_FILE_IO_RESOURCE_H_ |
OLD | NEW |