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

Side by Side Diff: webkit/plugins/ppapi/ppb_file_io_impl.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 | « webkit/plugins/ppapi/ppb_file_io_impl.h ('k') | webkit/plugins/ppapi/ppb_file_ref_impl.h » ('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 "webkit/plugins/ppapi/ppb_file_io_impl.h" 5 #include "webkit/plugins/ppapi/ppb_file_io_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/file_util_proxy.h" 10 #include "base/file_util_proxy.h"
11 #include "base/message_loop_proxy.h" 11 #include "base/message_loop_proxy.h"
(...skipping 10 matching lines...) Expand all
22 #include "ppapi/thunk/ppb_file_ref_api.h" 22 #include "ppapi/thunk/ppb_file_ref_api.h"
23 #include "webkit/plugins/ppapi/common.h" 23 #include "webkit/plugins/ppapi/common.h"
24 #include "webkit/plugins/ppapi/plugin_module.h" 24 #include "webkit/plugins/ppapi/plugin_module.h"
25 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 25 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
26 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" 26 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
27 #include "webkit/plugins/ppapi/quota_file_io.h" 27 #include "webkit/plugins/ppapi/quota_file_io.h"
28 #include "webkit/plugins/ppapi/resource_helper.h" 28 #include "webkit/plugins/ppapi/resource_helper.h"
29 29
30 using ppapi::PPTimeToTime; 30 using ppapi::PPTimeToTime;
31 using ppapi::TimeToPPTime; 31 using ppapi::TimeToPPTime;
32 using ppapi::TrackedCallback;
32 using ppapi::thunk::PPB_FileRef_API; 33 using ppapi::thunk::PPB_FileRef_API;
33 34
34 namespace webkit { 35 namespace webkit {
35 namespace ppapi { 36 namespace ppapi {
36 37
37 PPB_FileIO_Impl::PPB_FileIO_Impl(PP_Instance instance) 38 PPB_FileIO_Impl::PPB_FileIO_Impl(PP_Instance instance)
38 : ::ppapi::PPB_FileIO_Shared(instance), 39 : ::ppapi::PPB_FileIO_Shared(instance),
39 file_(base::kInvalidPlatformFileValue), 40 file_(base::kInvalidPlatformFileValue),
40 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { 41 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
41 } 42 }
42 43
43 PPB_FileIO_Impl::~PPB_FileIO_Impl() { 44 PPB_FileIO_Impl::~PPB_FileIO_Impl() {
44 Close(); 45 Close();
45 } 46 }
46 47
47 int32_t PPB_FileIO_Impl::OpenValidated(PP_Resource file_ref_resource, 48 int32_t PPB_FileIO_Impl::OpenValidated(
48 PPB_FileRef_API* file_ref_api, 49 PP_Resource file_ref_resource,
49 int32_t open_flags, 50 PPB_FileRef_API* file_ref_api,
50 PP_CompletionCallback callback) { 51 int32_t open_flags,
52 scoped_refptr<TrackedCallback> callback) {
51 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api); 53 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api);
52 54
53 int flags = 0; 55 int flags = 0;
54 if (!::ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags, &flags)) 56 if (!::ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags, &flags))
55 return PP_ERROR_BADARGUMENT; 57 return PP_ERROR_BADARGUMENT;
56 58
57 PluginDelegate* plugin_delegate = GetPluginDelegate(); 59 PluginDelegate* plugin_delegate = GetPluginDelegate();
58 if (!plugin_delegate) 60 if (!plugin_delegate)
59 return PP_ERROR_BADARGUMENT; 61 return PP_ERROR_BADARGUMENT;
60 62
(...skipping 11 matching lines...) Expand all
72 file_ref->GetSystemPath(), flags, 74 file_ref->GetSystemPath(), flags,
73 base::Bind(&PPB_FileIO_Impl::ExecutePlatformOpenFileCallback, 75 base::Bind(&PPB_FileIO_Impl::ExecutePlatformOpenFileCallback,
74 weak_factory_.GetWeakPtr()))) 76 weak_factory_.GetWeakPtr())))
75 return PP_ERROR_FAILED; 77 return PP_ERROR_FAILED;
76 } 78 }
77 79
78 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); 80 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL);
79 return PP_OK_COMPLETIONPENDING; 81 return PP_OK_COMPLETIONPENDING;
80 } 82 }
81 83
82 int32_t PPB_FileIO_Impl::QueryValidated(PP_FileInfo* info, 84 int32_t PPB_FileIO_Impl::QueryValidated(
83 PP_CompletionCallback callback) { 85 PP_FileInfo* info,
86 scoped_refptr<TrackedCallback> callback) {
84 PluginDelegate* plugin_delegate = GetPluginDelegate(); 87 PluginDelegate* plugin_delegate = GetPluginDelegate();
85 if (!plugin_delegate) 88 if (!plugin_delegate)
86 return PP_ERROR_FAILED; 89 return PP_ERROR_FAILED;
87 90
88 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( 91 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile(
89 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, 92 plugin_delegate->GetFileThreadMessageLoopProxy(), file_,
90 base::Bind(&PPB_FileIO_Impl::ExecutePlatformQueryCallback, 93 base::Bind(&PPB_FileIO_Impl::ExecutePlatformQueryCallback,
91 weak_factory_.GetWeakPtr()))) 94 weak_factory_.GetWeakPtr())))
92 return PP_ERROR_FAILED; 95 return PP_ERROR_FAILED;
93 96
94 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, info); 97 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, info);
95 return PP_OK_COMPLETIONPENDING; 98 return PP_OK_COMPLETIONPENDING;
96 } 99 }
97 100
98 int32_t PPB_FileIO_Impl::TouchValidated(PP_Time last_access_time, 101 int32_t PPB_FileIO_Impl::TouchValidated(
99 PP_Time last_modified_time, 102 PP_Time last_access_time,
100 PP_CompletionCallback callback) { 103 PP_Time last_modified_time,
104 scoped_refptr<TrackedCallback> callback) {
101 PluginDelegate* plugin_delegate = GetPluginDelegate(); 105 PluginDelegate* plugin_delegate = GetPluginDelegate();
102 if (!plugin_delegate) 106 if (!plugin_delegate)
103 return PP_ERROR_FAILED; 107 return PP_ERROR_FAILED;
104 108
105 if (!base::FileUtilProxy::Touch( 109 if (!base::FileUtilProxy::Touch(
106 plugin_delegate->GetFileThreadMessageLoopProxy(), 110 plugin_delegate->GetFileThreadMessageLoopProxy(),
107 file_, PPTimeToTime(last_access_time), 111 file_, PPTimeToTime(last_access_time),
108 PPTimeToTime(last_modified_time), 112 PPTimeToTime(last_modified_time),
109 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback, 113 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback,
110 weak_factory_.GetWeakPtr()))) 114 weak_factory_.GetWeakPtr())))
111 return PP_ERROR_FAILED; 115 return PP_ERROR_FAILED;
112 116
113 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); 117 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL);
114 return PP_OK_COMPLETIONPENDING; 118 return PP_OK_COMPLETIONPENDING;
115 } 119 }
116 120
117 int32_t PPB_FileIO_Impl::ReadValidated(int64_t offset, 121 int32_t PPB_FileIO_Impl::ReadValidated(
118 char* buffer, 122 int64_t offset,
119 int32_t bytes_to_read, 123 char* buffer,
120 PP_CompletionCallback callback) { 124 int32_t bytes_to_read,
125 scoped_refptr<TrackedCallback> callback) {
121 PluginDelegate* plugin_delegate = GetPluginDelegate(); 126 PluginDelegate* plugin_delegate = GetPluginDelegate();
122 if (!plugin_delegate) 127 if (!plugin_delegate)
123 return PP_ERROR_FAILED; 128 return PP_ERROR_FAILED;
124 129
125 if (!base::FileUtilProxy::Read( 130 if (!base::FileUtilProxy::Read(
126 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, offset, 131 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, offset,
127 bytes_to_read, 132 bytes_to_read,
128 base::Bind(&PPB_FileIO_Impl::ExecutePlatformReadCallback, 133 base::Bind(&PPB_FileIO_Impl::ExecutePlatformReadCallback,
129 weak_factory_.GetWeakPtr()))) 134 weak_factory_.GetWeakPtr())))
130 return PP_ERROR_FAILED; 135 return PP_ERROR_FAILED;
131 136
132 RegisterCallback(OPERATION_READ, callback, buffer, NULL); 137 RegisterCallback(OPERATION_READ, callback, buffer, NULL);
133 return PP_OK_COMPLETIONPENDING; 138 return PP_OK_COMPLETIONPENDING;
134 } 139 }
135 140
136 int32_t PPB_FileIO_Impl::WriteValidated(int64_t offset, 141 int32_t PPB_FileIO_Impl::WriteValidated(
137 const char* buffer, 142 int64_t offset,
138 int32_t bytes_to_write, 143 const char* buffer,
139 PP_CompletionCallback callback) { 144 int32_t bytes_to_write,
145 scoped_refptr<TrackedCallback> callback) {
140 PluginDelegate* plugin_delegate = GetPluginDelegate(); 146 PluginDelegate* plugin_delegate = GetPluginDelegate();
141 if (!plugin_delegate) 147 if (!plugin_delegate)
142 return PP_ERROR_FAILED; 148 return PP_ERROR_FAILED;
143 149
144 if (quota_file_io_.get()) { 150 if (quota_file_io_.get()) {
145 if (!quota_file_io_->Write( 151 if (!quota_file_io_->Write(
146 offset, buffer, bytes_to_write, 152 offset, buffer, bytes_to_write,
147 base::Bind(&PPB_FileIO_Impl::ExecutePlatformWriteCallback, 153 base::Bind(&PPB_FileIO_Impl::ExecutePlatformWriteCallback,
148 weak_factory_.GetWeakPtr()))) 154 weak_factory_.GetWeakPtr())))
149 return PP_ERROR_FAILED; 155 return PP_ERROR_FAILED;
150 } else { 156 } else {
151 if (!base::FileUtilProxy::Write( 157 if (!base::FileUtilProxy::Write(
152 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, offset, 158 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, offset,
153 buffer, bytes_to_write, 159 buffer, bytes_to_write,
154 base::Bind(&PPB_FileIO_Impl::ExecutePlatformWriteCallback, 160 base::Bind(&PPB_FileIO_Impl::ExecutePlatformWriteCallback,
155 weak_factory_.GetWeakPtr()))) 161 weak_factory_.GetWeakPtr())))
156 return PP_ERROR_FAILED; 162 return PP_ERROR_FAILED;
157 } 163 }
158 164
159 RegisterCallback(OPERATION_WRITE, callback, NULL, NULL); 165 RegisterCallback(OPERATION_WRITE, callback, NULL, NULL);
160 return PP_OK_COMPLETIONPENDING; 166 return PP_OK_COMPLETIONPENDING;
161 } 167 }
162 168
163 int32_t PPB_FileIO_Impl::SetLengthValidated(int64_t length, 169 int32_t PPB_FileIO_Impl::SetLengthValidated(
164 PP_CompletionCallback callback) { 170 int64_t length,
171 scoped_refptr<TrackedCallback> callback) {
165 PluginDelegate* plugin_delegate = GetPluginDelegate(); 172 PluginDelegate* plugin_delegate = GetPluginDelegate();
166 if (!plugin_delegate) 173 if (!plugin_delegate)
167 return PP_ERROR_FAILED; 174 return PP_ERROR_FAILED;
168 175
169 if (quota_file_io_.get()) { 176 if (quota_file_io_.get()) {
170 if (!quota_file_io_->SetLength( 177 if (!quota_file_io_->SetLength(
171 length, 178 length,
172 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback, 179 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback,
173 weak_factory_.GetWeakPtr()))) 180 weak_factory_.GetWeakPtr())))
174 return PP_ERROR_FAILED; 181 return PP_ERROR_FAILED;
175 } else { 182 } else {
176 if (!base::FileUtilProxy::Truncate( 183 if (!base::FileUtilProxy::Truncate(
177 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, length, 184 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, length,
178 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback, 185 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback,
179 weak_factory_.GetWeakPtr()))) 186 weak_factory_.GetWeakPtr())))
180 return PP_ERROR_FAILED; 187 return PP_ERROR_FAILED;
181 } 188 }
182 189
183 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); 190 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL);
184 return PP_OK_COMPLETIONPENDING; 191 return PP_OK_COMPLETIONPENDING;
185 } 192 }
186 193
187 int32_t PPB_FileIO_Impl::FlushValidated(PP_CompletionCallback callback) { 194 int32_t PPB_FileIO_Impl::FlushValidated(
195 scoped_refptr<TrackedCallback> callback) {
188 PluginDelegate* plugin_delegate = GetPluginDelegate(); 196 PluginDelegate* plugin_delegate = GetPluginDelegate();
189 if (!plugin_delegate) 197 if (!plugin_delegate)
190 return PP_ERROR_FAILED; 198 return PP_ERROR_FAILED;
191 199
192 if (!base::FileUtilProxy::Flush( 200 if (!base::FileUtilProxy::Flush(
193 plugin_delegate->GetFileThreadMessageLoopProxy(), file_, 201 plugin_delegate->GetFileThreadMessageLoopProxy(), file_,
194 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback, 202 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback,
195 weak_factory_.GetWeakPtr()))) 203 weak_factory_.GetWeakPtr())))
196 return PP_ERROR_FAILED; 204 return PP_ERROR_FAILED;
197 205
(...skipping 17 matching lines...) Expand all
215 return file_; 223 return file_;
216 #elif defined(OS_WIN) 224 #elif defined(OS_WIN)
217 return reinterpret_cast<uintptr_t>(file_); 225 return reinterpret_cast<uintptr_t>(file_);
218 #else 226 #else
219 #error "Platform not supported." 227 #error "Platform not supported."
220 #endif 228 #endif
221 } 229 }
222 230
223 int32_t PPB_FileIO_Impl::WillWrite(int64_t offset, 231 int32_t PPB_FileIO_Impl::WillWrite(int64_t offset,
224 int32_t bytes_to_write, 232 int32_t bytes_to_write,
225 PP_CompletionCallback callback) { 233 scoped_refptr<TrackedCallback> callback) {
226 int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE, callback); 234 int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE);
227 if (rv != PP_OK) 235 if (rv != PP_OK)
228 return rv; 236 return rv;
229 237
230 if (!quota_file_io_.get()) 238 if (!quota_file_io_.get())
231 return PP_OK; 239 return PP_OK;
232 240
233 if (!quota_file_io_->WillWrite( 241 if (!quota_file_io_->WillWrite(
234 offset, bytes_to_write, 242 offset, bytes_to_write,
235 base::Bind(&PPB_FileIO_Impl::ExecutePlatformWillWriteCallback, 243 base::Bind(&PPB_FileIO_Impl::ExecutePlatformWillWriteCallback,
236 weak_factory_.GetWeakPtr()))) 244 weak_factory_.GetWeakPtr())))
237 return PP_ERROR_FAILED; 245 return PP_ERROR_FAILED;
238 246
239 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL); 247 RegisterCallback(OPERATION_EXCLUSIVE, callback, NULL, NULL);
240 return PP_OK_COMPLETIONPENDING; 248 return PP_OK_COMPLETIONPENDING;
241 } 249 }
242 250
243 int32_t PPB_FileIO_Impl::WillSetLength(int64_t length, 251 int32_t PPB_FileIO_Impl::WillSetLength(
244 PP_CompletionCallback callback) { 252 int64_t length,
245 int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE, callback); 253 scoped_refptr<TrackedCallback> callback) {
254 int32_t rv = CommonCallValidation(true, OPERATION_EXCLUSIVE);
246 if (rv != PP_OK) 255 if (rv != PP_OK)
247 return rv; 256 return rv;
248 257
249 if (!quota_file_io_.get()) 258 if (!quota_file_io_.get())
250 return PP_OK; 259 return PP_OK;
251 260
252 if (!quota_file_io_->WillSetLength( 261 if (!quota_file_io_->WillSetLength(
253 length, 262 length,
254 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback, 263 base::Bind(&PPB_FileIO_Impl::ExecutePlatformGeneralCallback,
255 weak_factory_.GetWeakPtr()))) 264 weak_factory_.GetWeakPtr())))
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 if (error_code != base::PLATFORM_FILE_OK) { 339 if (error_code != base::PLATFORM_FILE_OK) {
331 RunAndRemoveFirstPendingCallback( 340 RunAndRemoveFirstPendingCallback(
332 ::ppapi::PlatformFileErrorToPepperError(error_code)); 341 ::ppapi::PlatformFileErrorToPepperError(error_code));
333 } else { 342 } else {
334 RunAndRemoveFirstPendingCallback(bytes_written); 343 RunAndRemoveFirstPendingCallback(bytes_written);
335 } 344 }
336 } 345 }
337 346
338 } // namespace ppapi 347 } // namespace ppapi
339 } // namespace webkit 348 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_file_io_impl.h ('k') | webkit/plugins/ppapi/ppb_file_ref_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698