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

Side by Side Diff: ppapi/proxy/ppb_file_io_proxy.cc

Issue 10081020: PPAPI: Make blocking completion callbacks work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: export AssertLockHeld Created 8 years, 6 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
« no previous file with comments | « ppapi/proxy/ppb_file_chooser_proxy.cc ('k') | ppapi/proxy/ppb_file_ref_proxy.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #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"
11 #include "ppapi/shared_impl/ppapi_globals.h" 11 #include "ppapi/shared_impl/ppapi_globals.h"
(...skipping 22 matching lines...) Expand all
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 scoped_refptr<TrackedCallback> callback) OVERRIDE;
45 virtual int32_t WillSetLength(int64_t length, 45 virtual int32_t WillSetLength(
46 PP_CompletionCallback callback) OVERRIDE; 46 int64_t length,
47 scoped_refptr<TrackedCallback> callback) OVERRIDE;
47 48
48 private: 49 private:
49 // FileIOImpl overrides. 50 // FileIOImpl overrides.
50 virtual int32_t OpenValidated(PP_Resource file_ref_resource, 51 virtual int32_t OpenValidated(
51 PPB_FileRef_API* file_ref_api, 52 PP_Resource file_ref_resource,
52 int32_t open_flags, 53 PPB_FileRef_API* file_ref_api,
53 PP_CompletionCallback callback) OVERRIDE; 54 int32_t open_flags,
54 virtual int32_t QueryValidated(PP_FileInfo* info, 55 scoped_refptr<TrackedCallback> callback) OVERRIDE;
55 PP_CompletionCallback callback) OVERRIDE; 56 virtual int32_t QueryValidated(
56 virtual int32_t TouchValidated(PP_Time last_access_time, 57 PP_FileInfo* info,
57 PP_Time last_modified_time, 58 scoped_refptr<TrackedCallback> callback) OVERRIDE;
58 PP_CompletionCallback callback) OVERRIDE; 59 virtual int32_t TouchValidated(
59 virtual int32_t ReadValidated(int64_t offset, 60 PP_Time last_access_time,
60 char* buffer, 61 PP_Time last_modified_time,
61 int32_t bytes_to_read, 62 scoped_refptr<TrackedCallback> callback) OVERRIDE;
62 PP_CompletionCallback callback) OVERRIDE; 63 virtual int32_t ReadValidated(
63 virtual int32_t WriteValidated(int64_t offset, 64 int64_t offset,
64 const char* buffer, 65 char* buffer,
65 int32_t bytes_to_write, 66 int32_t bytes_to_read,
66 PP_CompletionCallback callback) OVERRIDE; 67 scoped_refptr<TrackedCallback> callback) OVERRIDE;
67 virtual int32_t SetLengthValidated(int64_t length, 68 virtual int32_t WriteValidated(
68 PP_CompletionCallback callback) OVERRIDE; 69 int64_t offset,
69 virtual int32_t FlushValidated(PP_CompletionCallback callback) OVERRIDE; 70 const char* buffer,
71 int32_t bytes_to_write,
72 scoped_refptr<TrackedCallback> callback) OVERRIDE;
73 virtual int32_t SetLengthValidated(
74 int64_t length,
75 scoped_refptr<TrackedCallback> callback) OVERRIDE;
76 virtual int32_t FlushValidated(
77 scoped_refptr<TrackedCallback> callback) OVERRIDE;
70 78
71 PluginDispatcher* GetDispatcher() const { 79 PluginDispatcher* GetDispatcher() const {
72 return PluginDispatcher::GetForResource(this); 80 return PluginDispatcher::GetForResource(this);
73 } 81 }
74 82
75 static const ApiID kApiID = API_ID_PPB_FILE_IO; 83 static const ApiID kApiID = API_ID_PPB_FILE_IO;
76 84
77 DISALLOW_IMPLICIT_CONSTRUCTORS(FileIO); 85 DISALLOW_IMPLICIT_CONSTRUCTORS(FileIO);
78 }; 86 };
79 87
(...skipping 11 matching lines...) Expand all
91 host_resource())); 99 host_resource()));
92 } 100 }
93 } 101 }
94 102
95 int32_t FileIO::GetOSFileDescriptor() { 103 int32_t FileIO::GetOSFileDescriptor() {
96 return -1; 104 return -1;
97 } 105 }
98 106
99 int32_t FileIO::WillWrite(int64_t offset, 107 int32_t FileIO::WillWrite(int64_t offset,
100 int32_t bytes_to_write, 108 int32_t bytes_to_write,
101 PP_CompletionCallback callback) { 109 scoped_refptr<TrackedCallback> callback) {
102 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_WillWrite( 110 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_WillWrite(
103 kApiID, host_resource(), offset, bytes_to_write)); 111 kApiID, host_resource(), offset, bytes_to_write));
104 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); 112 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL);
105 return PP_OK_COMPLETIONPENDING; 113 return PP_OK_COMPLETIONPENDING;
106 } 114 }
107 115
108 int32_t FileIO::WillSetLength(int64_t length, 116 int32_t FileIO::WillSetLength(int64_t length,
109 PP_CompletionCallback callback) { 117 scoped_refptr<TrackedCallback> callback) {
110 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_WillSetLength( 118 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_WillSetLength(
111 kApiID, host_resource(), length)); 119 kApiID, host_resource(), length));
112 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); 120 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL);
113 return PP_OK_COMPLETIONPENDING; 121 return PP_OK_COMPLETIONPENDING;
114 } 122 }
115 123
116 int32_t FileIO::OpenValidated(PP_Resource file_ref_resource, 124 int32_t FileIO::OpenValidated(PP_Resource file_ref_resource,
117 PPB_FileRef_API* file_ref_api, 125 PPB_FileRef_API* file_ref_api,
118 int32_t open_flags, 126 int32_t open_flags,
119 PP_CompletionCallback callback) { 127 scoped_refptr<TrackedCallback> callback) {
120 Resource* file_ref_object = 128 Resource* file_ref_object =
121 PpapiGlobals::Get()->GetResourceTracker()->GetResource(file_ref_resource); 129 PpapiGlobals::Get()->GetResourceTracker()->GetResource(file_ref_resource);
122 130
123 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Open( 131 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Open(
124 kApiID, host_resource(), file_ref_object->host_resource(), open_flags)); 132 kApiID, host_resource(), file_ref_object->host_resource(), open_flags));
125 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); 133 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL);
126 return PP_OK_COMPLETIONPENDING; 134 return PP_OK_COMPLETIONPENDING;
127 } 135 }
128 136
129 int32_t FileIO::QueryValidated(PP_FileInfo* info, 137 int32_t FileIO::QueryValidated(PP_FileInfo* info,
130 PP_CompletionCallback callback) { 138 scoped_refptr<TrackedCallback> callback) {
131 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Query( 139 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Query(
132 kApiID, host_resource())); 140 kApiID, host_resource()));
133 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, info); 141 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, info);
134 return PP_OK_COMPLETIONPENDING; 142 return PP_OK_COMPLETIONPENDING;
135 } 143 }
136 144
137 int32_t FileIO::TouchValidated(PP_Time last_access_time, 145 int32_t FileIO::TouchValidated(PP_Time last_access_time,
138 PP_Time last_modified_time, 146 PP_Time last_modified_time,
139 PP_CompletionCallback callback) { 147 scoped_refptr<TrackedCallback> callback) {
140 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Touch( 148 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Touch(
141 kApiID, host_resource(), last_access_time, last_modified_time)); 149 kApiID, host_resource(), last_access_time, last_modified_time));
142 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); 150 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL);
143 return PP_OK_COMPLETIONPENDING; 151 return PP_OK_COMPLETIONPENDING;
144 } 152 }
145 153
146 int32_t FileIO::ReadValidated(int64_t offset, 154 int32_t FileIO::ReadValidated(int64_t offset,
147 char* buffer, 155 char* buffer,
148 int32_t bytes_to_read, 156 int32_t bytes_to_read,
149 PP_CompletionCallback callback) { 157 scoped_refptr<TrackedCallback> callback) {
150 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Read( 158 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Read(
151 kApiID, host_resource(), offset, bytes_to_read)); 159 kApiID, host_resource(), offset, bytes_to_read));
152 RegisterCallback(OPERATION_READ, callback, buffer, NULL); 160 RegisterCallback(OPERATION_READ, callback, buffer, NULL);
153 return PP_OK_COMPLETIONPENDING; 161 return PP_OK_COMPLETIONPENDING;
154 } 162 }
155 163
156 int32_t FileIO::WriteValidated(int64_t offset, 164 int32_t FileIO::WriteValidated(int64_t offset,
157 const char* buffer, 165 const char* buffer,
158 int32_t bytes_to_write, 166 int32_t bytes_to_write,
159 PP_CompletionCallback callback) { 167 scoped_refptr<TrackedCallback> callback) {
160 // TODO(brettw) it would be nice to use a shared memory buffer for large 168 // 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 169 // writes rather than having to copy to a string (which will involve a number
162 // of extra copies to serialize over IPC). 170 // of extra copies to serialize over IPC).
163 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Write( 171 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Write(
164 kApiID, host_resource(), offset, std::string(buffer, bytes_to_write))); 172 kApiID, host_resource(), offset, std::string(buffer, bytes_to_write)));
165 RegisterCallback(OPERATION_WRITE, callback, NULL, NULL); 173 RegisterCallback(OPERATION_WRITE, callback, NULL, NULL);
166 return PP_OK_COMPLETIONPENDING; 174 return PP_OK_COMPLETIONPENDING;
167 } 175 }
168 176
169 int32_t FileIO::SetLengthValidated(int64_t length, 177 int32_t FileIO::SetLengthValidated(int64_t length,
170 PP_CompletionCallback callback) { 178 scoped_refptr<TrackedCallback> callback) {
171 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_SetLength( 179 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_SetLength(
172 kApiID, host_resource(), length)); 180 kApiID, host_resource(), length));
173 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); 181 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL);
174 return PP_OK_COMPLETIONPENDING; 182 return PP_OK_COMPLETIONPENDING;
175 } 183 }
176 184
177 int32_t FileIO::FlushValidated(PP_CompletionCallback callback) { 185 int32_t FileIO::FlushValidated(scoped_refptr<TrackedCallback> callback) {
178 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Flush( 186 GetDispatcher()->Send(new PpapiHostMsg_PPBFileIO_Flush(
179 kApiID, host_resource())); 187 kApiID, host_resource()));
180 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); 188 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL);
181 return PP_OK_COMPLETIONPENDING; 189 return PP_OK_COMPLETIONPENDING;
182 } 190 }
183 191
184 } // namespace 192 } // namespace
185 193
186 // ----------------------------------------------------------------------------- 194 // -----------------------------------------------------------------------------
187 195
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 DCHECK(pp_error <= static_cast<int32_t>(data->size())); 441 DCHECK(pp_error <= static_cast<int32_t>(data->size()));
434 data->resize(pp_error); 442 data->resize(pp_error);
435 } 443 }
436 Send(new PpapiMsg_PPBFileIO_ReadComplete(kApiID, host_resource, pp_error, 444 Send(new PpapiMsg_PPBFileIO_ReadComplete(kApiID, host_resource, pp_error,
437 *data)); 445 *data));
438 delete data; 446 delete data;
439 } 447 }
440 448
441 } // namespace proxy 449 } // namespace proxy
442 } // namespace ppapi 450 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_file_chooser_proxy.cc ('k') | ppapi/proxy/ppb_file_ref_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698