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

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

Issue 10081020: PPAPI: Make blocking completion callbacks work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated TestURLLoader to test blocking callbacks. Created 8 years, 8 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
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 "ppapi/proxy/ppb_file_chooser_proxy.h" 5 #include "ppapi/proxy/ppb_file_chooser_proxy.h"
6 6
7 #include <queue> 7 #include <queue>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "ppapi/c/dev/ppb_file_chooser_dev.h" 10 #include "ppapi/c/dev/ppb_file_chooser_dev.h"
(...skipping 28 matching lines...) Expand all
39 public PPB_FileChooser_API { 39 public PPB_FileChooser_API {
40 public: 40 public:
41 FileChooser(const HostResource& resource); 41 FileChooser(const HostResource& resource);
42 virtual ~FileChooser(); 42 virtual ~FileChooser();
43 43
44 // Resource overrides. 44 // Resource overrides.
45 virtual PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE; 45 virtual PPB_FileChooser_API* AsPPB_FileChooser_API() OVERRIDE;
46 46
47 // PPB_FileChooser_API implementation. 47 // PPB_FileChooser_API implementation.
48 virtual int32_t Show(const PP_ArrayOutput& output, 48 virtual int32_t Show(const PP_ArrayOutput& output,
49 const PP_CompletionCallback& callback) OVERRIDE; 49 ApiCallbackType callback) OVERRIDE;
50 virtual int32_t ShowWithoutUserGesture( 50 virtual int32_t ShowWithoutUserGesture(PP_Bool save_as,
51 PP_Bool save_as, 51 PP_Var suggested_file_name,
52 PP_Var suggested_file_name, 52 const PP_ArrayOutput& output,
53 const PP_ArrayOutput& output, 53 ApiCallbackType callback);
54 const PP_CompletionCallback& callback); 54 virtual int32_t Show0_5(ApiCallbackType callback) OVERRIDE;
55 virtual int32_t Show0_5(const PP_CompletionCallback& callback) OVERRIDE;
56 virtual PP_Resource GetNextChosenFile() OVERRIDE; 55 virtual PP_Resource GetNextChosenFile() OVERRIDE;
57 virtual int32_t ShowWithoutUserGesture0_5( 56 virtual int32_t ShowWithoutUserGesture0_5(PP_Bool save_as,
58 PP_Bool save_as, 57 PP_Var suggested_file_name,
59 PP_Var suggested_file_name, 58 ApiCallbackType callback) OVERRIDE;
60 const PP_CompletionCallback& callback) OVERRIDE;
61 59
62 // Handles the choose complete notification from the host. 60 // Handles the choose complete notification from the host.
63 void ChooseComplete( 61 void ChooseComplete(
64 int32_t result_code, 62 int32_t result_code,
65 const std::vector<PPB_FileRef_CreateInfo>& chosen_files); 63 const std::vector<PPB_FileRef_CreateInfo>& chosen_files);
66 64
67 private: 65 private:
68 int32_t Show(bool require_user_gesture, 66 int32_t Show(bool require_user_gesture,
69 PP_Bool save_as, 67 PP_Bool save_as,
70 PP_Var suggested_file_name, 68 PP_Var suggested_file_name,
71 const PP_CompletionCallback& callback); 69 ApiCallbackType callback);
72 70
73 // When using v0.6 of the API, contains the array output info. 71 // When using v0.6 of the API, contains the array output info.
74 ArrayWriter output_; 72 ArrayWriter output_;
75 73
76 scoped_refptr<TrackedCallback> current_show_callback_; 74 scoped_refptr<TrackedCallback> current_show_callback_;
77 75
78 // When using v0.5 of the API, contains all files returned by the current 76 // When using v0.5 of the API, contains all files returned by the current
79 // show callback that haven't yet been given to the plugin. The plugin will 77 // show callback that haven't yet been given to the plugin. The plugin will
80 // repeatedly call us to get the next file, and we'll vend those out of this 78 // repeatedly call us to get the next file, and we'll vend those out of this
81 // queue, removing them when ownership has transferred to the plugin. 79 // queue, removing them when ownership has transferred to the plugin.
(...skipping 14 matching lines...) Expand all
96 tracker->ReleaseResource(file_queue_.front()); 94 tracker->ReleaseResource(file_queue_.front());
97 file_queue_.pop(); 95 file_queue_.pop();
98 } 96 }
99 } 97 }
100 98
101 PPB_FileChooser_API* FileChooser::AsPPB_FileChooser_API() { 99 PPB_FileChooser_API* FileChooser::AsPPB_FileChooser_API() {
102 return this; 100 return this;
103 } 101 }
104 102
105 int32_t FileChooser::Show(const PP_ArrayOutput& output, 103 int32_t FileChooser::Show(const PP_ArrayOutput& output,
106 const PP_CompletionCallback& callback) { 104 ApiCallbackType callback) {
107 int32_t result = Show(true, PP_FALSE, PP_MakeUndefined(), callback); 105 int32_t result = Show(true, PP_FALSE, PP_MakeUndefined(), callback);
108 if (result == PP_OK_COMPLETIONPENDING) 106 if (result == PP_OK_COMPLETIONPENDING)
109 output_.set_pp_array_output(output); 107 output_.set_pp_array_output(output);
110 return result; 108 return result;
111 } 109 }
112 110
113 int32_t FileChooser::ShowWithoutUserGesture( 111 int32_t FileChooser::ShowWithoutUserGesture(PP_Bool save_as,
114 PP_Bool save_as, 112 PP_Var suggested_file_name,
115 PP_Var suggested_file_name, 113 const PP_ArrayOutput& output,
116 const PP_ArrayOutput& output, 114 ApiCallbackType callback) {
117 const PP_CompletionCallback& callback) {
118 int32_t result = Show(false, save_as, PP_MakeUndefined(), callback); 115 int32_t result = Show(false, save_as, PP_MakeUndefined(), callback);
119 if (result == PP_OK_COMPLETIONPENDING) 116 if (result == PP_OK_COMPLETIONPENDING)
120 output_.set_pp_array_output(output); 117 output_.set_pp_array_output(output);
121 return result; 118 return result;
122 } 119 }
123 120
124 int32_t FileChooser::Show0_5(const PP_CompletionCallback& callback) { 121 int32_t FileChooser::Show0_5(ApiCallbackType callback) {
125 return Show(true, PP_FALSE, PP_MakeUndefined(), callback); 122 return Show(true, PP_FALSE, PP_MakeUndefined(), callback);
126 } 123 }
127 124
128 int32_t FileChooser::ShowWithoutUserGesture0_5( 125 int32_t FileChooser::ShowWithoutUserGesture0_5(PP_Bool save_as,
129 PP_Bool save_as, 126 PP_Var suggested_file_name,
130 PP_Var suggested_file_name, 127 ApiCallbackType callback) {
131 const PP_CompletionCallback& callback) {
132 return Show(false, save_as, suggested_file_name, callback); 128 return Show(false, save_as, suggested_file_name, callback);
133 } 129 }
134 130
135 int32_t FileChooser::Show(bool require_user_gesture, 131 int32_t FileChooser::Show(bool require_user_gesture,
136 PP_Bool save_as, 132 PP_Bool save_as,
137 PP_Var suggested_file_name, 133 PP_Var suggested_file_name,
138 const PP_CompletionCallback& callback) { 134 ApiCallbackType callback) {
139 if (!callback.func)
140 return PP_ERROR_BLOCKS_MAIN_THREAD;
141
142 if (TrackedCallback::IsPending(current_show_callback_)) 135 if (TrackedCallback::IsPending(current_show_callback_))
143 return PP_ERROR_INPROGRESS; // Can't show more than once. 136 return PP_ERROR_INPROGRESS; // Can't show more than once.
144 137
145 current_show_callback_ = new TrackedCallback(this, callback); 138 current_show_callback_ = callback;
146 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this); 139 PluginDispatcher* dispatcher = PluginDispatcher::GetForResource(this);
147 dispatcher->Send( 140 dispatcher->Send(
148 new PpapiHostMsg_PPBFileChooser_Show( 141 new PpapiHostMsg_PPBFileChooser_Show(
149 API_ID_PPB_FILE_CHOOSER, 142 API_ID_PPB_FILE_CHOOSER,
150 host_resource(), 143 host_resource(),
151 save_as, 144 save_as,
152 SerializedVarSendInput(dispatcher, suggested_file_name), 145 SerializedVarSendInput(dispatcher, suggested_file_name),
153 require_user_gesture)); 146 require_user_gesture));
154 return PP_OK_COMPLETIONPENDING; 147 return PP_OK_COMPLETIONPENDING;
155 } 148 }
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 files.push_back(cur_create_info); 298 files.push_back(cur_create_info);
306 } 299 }
307 } 300 }
308 301
309 dispatcher()->Send(new PpapiMsg_PPBFileChooser_ChooseComplete( 302 dispatcher()->Send(new PpapiMsg_PPBFileChooser_ChooseComplete(
310 API_ID_PPB_FILE_CHOOSER, chooser, result, files)); 303 API_ID_PPB_FILE_CHOOSER, chooser, result, files));
311 } 304 }
312 305
313 } // namespace proxy 306 } // namespace proxy
314 } // namespace ppapi 307 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698