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

Side by Side Diff: webkit/plugins/ppapi/ppb_file_chooser_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_chooser_impl.h ('k') | webkit/plugins/ppapi/ppb_file_io_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) 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 #include "webkit/plugins/ppapi/ppb_file_chooser_impl.h" 5 #include "webkit/plugins/ppapi/ppb_file_chooser_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 158
159 int32_t result_code = (chosen_files.size() > 0) ? PP_OK : PP_ERROR_USERCANCEL; 159 int32_t result_code = (chosen_files.size() > 0) ? PP_OK : PP_ERROR_USERCANCEL;
160 if (output_.is_valid()) 160 if (output_.is_valid())
161 output_.StoreResourceVector(chosen_files); 161 output_.StoreResourceVector(chosen_files);
162 else // v0.5 API. 162 else // v0.5 API.
163 chosen_files_.swap(chosen_files); 163 chosen_files_.swap(chosen_files);
164 RunCallback(result_code); 164 RunCallback(result_code);
165 } 165 }
166 166
167 int32_t PPB_FileChooser_Impl::ValidateCallback( 167 int32_t PPB_FileChooser_Impl::ValidateCallback(
168 const PP_CompletionCallback& callback) { 168 scoped_refptr<TrackedCallback> callback) {
169 // We only support non-blocking calls.
170 if (!callback.func)
171 return PP_ERROR_BLOCKS_MAIN_THREAD;
172
173 if (TrackedCallback::IsPending(callback_)) 169 if (TrackedCallback::IsPending(callback_))
174 return PP_ERROR_INPROGRESS; 170 return PP_ERROR_INPROGRESS;
175 171
176 return PP_OK; 172 return PP_OK;
177 } 173 }
178 174
179 void PPB_FileChooser_Impl::RegisterCallback( 175 void PPB_FileChooser_Impl::RegisterCallback(
180 const PP_CompletionCallback& callback) { 176 scoped_refptr<TrackedCallback> callback) {
181 DCHECK(callback.func);
182 DCHECK(!TrackedCallback::IsPending(callback_)); 177 DCHECK(!TrackedCallback::IsPending(callback_));
183 178
184 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); 179 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this);
185 if (!plugin_module) 180 if (!plugin_module)
186 return; 181 return;
187 182
188 callback_ = new TrackedCallback(this, callback); 183 callback_ = callback;
189 } 184 }
190 185
191 void PPB_FileChooser_Impl::RunCallback(int32_t result) { 186 void PPB_FileChooser_Impl::RunCallback(int32_t result) {
192 TrackedCallback::ClearAndRun(&callback_, result); 187 TrackedCallback::ClearAndRun(&callback_, result);
193 } 188 }
194 189
195 int32_t PPB_FileChooser_Impl::Show(const PP_ArrayOutput& output, 190 int32_t PPB_FileChooser_Impl::Show(const PP_ArrayOutput& output,
196 const PP_CompletionCallback& callback) { 191 scoped_refptr<TrackedCallback> callback) {
197 int32_t result = Show0_5(callback); 192 int32_t result = Show0_5(callback);
198 if (result == PP_OK_COMPLETIONPENDING) 193 if (result == PP_OK_COMPLETIONPENDING)
199 output_.set_pp_array_output(output); 194 output_.set_pp_array_output(output);
200 return result; 195 return result;
201 } 196 }
202 197
203 int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture( 198 int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture(
204 PP_Bool save_as, 199 PP_Bool save_as,
205 PP_Var suggested_file_name, 200 PP_Var suggested_file_name,
206 const PP_ArrayOutput& output, 201 const PP_ArrayOutput& output,
207 const PP_CompletionCallback& callback) { 202 scoped_refptr<TrackedCallback> callback) {
208 int32_t result = ShowWithoutUserGesture0_5(save_as, suggested_file_name, 203 int32_t result = ShowWithoutUserGesture0_5(save_as, suggested_file_name,
209 callback); 204 callback);
210 if (result == PP_OK_COMPLETIONPENDING) 205 if (result == PP_OK_COMPLETIONPENDING)
211 output_.set_pp_array_output(output); 206 output_.set_pp_array_output(output);
212 return result; 207 return result;
213 } 208 }
214 209
215 int32_t PPB_FileChooser_Impl::Show0_5(const PP_CompletionCallback& callback) { 210 int32_t PPB_FileChooser_Impl::Show0_5(scoped_refptr<TrackedCallback> callback) {
216 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); 211 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this);
217 if (!plugin_instance) 212 if (!plugin_instance)
218 return PP_ERROR_FAILED; 213 return PP_ERROR_FAILED;
219 if (!plugin_instance->IsProcessingUserGesture()) 214 if (!plugin_instance->IsProcessingUserGesture())
220 return PP_ERROR_NO_USER_GESTURE; 215 return PP_ERROR_NO_USER_GESTURE;
221 return ShowWithoutUserGesture0_5(PP_FALSE, PP_MakeUndefined(), callback); 216 return ShowWithoutUserGesture0_5(PP_FALSE, PP_MakeUndefined(), callback);
222 } 217 }
223 218
224 int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture0_5( 219 int32_t PPB_FileChooser_Impl::ShowWithoutUserGesture0_5(
225 PP_Bool save_as, 220 PP_Bool save_as,
226 PP_Var suggested_file_name, 221 PP_Var suggested_file_name,
227 const PP_CompletionCallback& callback) { 222 scoped_refptr<TrackedCallback> callback) {
228 int32_t rv = ValidateCallback(callback); 223 int32_t rv = ValidateCallback(callback);
229 if (rv != PP_OK) 224 if (rv != PP_OK)
230 return rv; 225 return rv;
231 226
232 DCHECK((mode_ == PP_FILECHOOSERMODE_OPEN) || 227 DCHECK((mode_ == PP_FILECHOOSERMODE_OPEN) ||
233 (mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE)); 228 (mode_ == PP_FILECHOOSERMODE_OPENMULTIPLE));
234 229
235 WebFileChooserParams params; 230 WebFileChooserParams params;
236 if (save_as) { 231 if (save_as) {
237 params.saveAs = true; 232 params.saveAs = true;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 continue; 279 continue;
285 StringToLowerASCII(&type); 280 StringToLowerASCII(&type);
286 normalized_type_list.push_back(WebString::fromUTF8(type.data(), 281 normalized_type_list.push_back(WebString::fromUTF8(type.data(),
287 type.size())); 282 type.size()));
288 } 283 }
289 return normalized_type_list; 284 return normalized_type_list;
290 } 285 }
291 286
292 } // namespace ppapi 287 } // namespace ppapi
293 } // namespace webkit 288 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_file_chooser_impl.h ('k') | webkit/plugins/ppapi/ppb_file_io_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698