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

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

Issue 14784002: Move DirectoryReader::ReadEntries to FileRef::ReadDirectoryEntries (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: address dmichael's comments Created 7 years, 7 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
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_ref_proxy.h" 5 #include "ppapi/proxy/ppb_file_ref_proxy.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/c/ppb_file_ref.h" 11 #include "ppapi/c/ppb_file_ref.h"
12 #include "ppapi/c/private/ppb_file_ref_private.h" 12 #include "ppapi/c/private/ppb_file_ref_private.h"
13 #include "ppapi/c/private/ppb_proxy_private.h" 13 #include "ppapi/c/private/ppb_proxy_private.h"
14 #include "ppapi/proxy/enter_proxy.h" 14 #include "ppapi/proxy/enter_proxy.h"
15 #include "ppapi/proxy/host_dispatcher.h" 15 #include "ppapi/proxy/host_dispatcher.h"
16 #include "ppapi/proxy/plugin_dispatcher.h" 16 #include "ppapi/proxy/plugin_dispatcher.h"
17 #include "ppapi/proxy/ppapi_messages.h" 17 #include "ppapi/proxy/ppapi_messages.h"
18 #include "ppapi/proxy/serialized_var.h" 18 #include "ppapi/proxy/serialized_var.h"
19 #include "ppapi/shared_impl/array_writer.h"
19 #include "ppapi/shared_impl/ppb_file_ref_shared.h" 20 #include "ppapi/shared_impl/ppb_file_ref_shared.h"
20 #include "ppapi/shared_impl/scoped_pp_resource.h" 21 #include "ppapi/shared_impl/scoped_pp_resource.h"
21 #include "ppapi/shared_impl/tracked_callback.h" 22 #include "ppapi/shared_impl/tracked_callback.h"
22 #include "ppapi/thunk/resource_creation_api.h" 23 #include "ppapi/thunk/resource_creation_api.h"
23 #include "ppapi/thunk/thunk.h" 24 #include "ppapi/thunk/thunk.h"
24 25
25 using ppapi::thunk::EnterResourceNoLock; 26 using ppapi::thunk::EnterResourceNoLock;
26 using ppapi::thunk::PPB_FileRef_API; 27 using ppapi::thunk::PPB_FileRef_API;
27 using ppapi::thunk::ResourceCreationAPI; 28 using ppapi::thunk::ResourceCreationAPI;
28 29
29 namespace ppapi { 30 namespace ppapi {
30 namespace proxy { 31 namespace proxy {
31 32
33 namespace {
34
35 void ReleaseEntries(const std::vector<PP_DirectoryEntry>& entries) {
36 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
37 for (std::vector<PP_DirectoryEntry>::const_iterator it = entries.begin();
38 it != entries.end(); ++it)
39 tracker->ReleaseResource(it->file_ref);
40 }
41
42 } // namespace
43
32 class FileRef : public PPB_FileRef_Shared { 44 class FileRef : public PPB_FileRef_Shared {
33 public: 45 public:
34 explicit FileRef(const PPB_FileRef_CreateInfo& info); 46 explicit FileRef(const PPB_FileRef_CreateInfo& info);
35 virtual ~FileRef(); 47 virtual ~FileRef();
36 48
37 // Resource overrides. 49 // Resource overrides.
38 virtual void LastPluginRefWasDeleted() OVERRIDE; 50 virtual void LastPluginRefWasDeleted() OVERRIDE;
39 51
40 // PPB_FileRef_API implementation (not provided by PPB_FileRef_Shared). 52 // PPB_FileRef_API implementation (not provided by PPB_FileRef_Shared).
41 virtual PP_Resource GetParent() OVERRIDE; 53 virtual PP_Resource GetParent() OVERRIDE;
42 virtual int32_t MakeDirectory( 54 virtual int32_t MakeDirectory(
43 PP_Bool make_ancestors, 55 PP_Bool make_ancestors,
44 scoped_refptr<TrackedCallback> callback) OVERRIDE; 56 scoped_refptr<TrackedCallback> callback) OVERRIDE;
45 virtual int32_t Touch(PP_Time last_access_time, 57 virtual int32_t Touch(PP_Time last_access_time,
46 PP_Time last_modified_time, 58 PP_Time last_modified_time,
47 scoped_refptr<TrackedCallback> callback) OVERRIDE; 59 scoped_refptr<TrackedCallback> callback) OVERRIDE;
48 virtual int32_t Delete(scoped_refptr<TrackedCallback> callback) OVERRIDE; 60 virtual int32_t Delete(scoped_refptr<TrackedCallback> callback) OVERRIDE;
49 virtual int32_t Rename(PP_Resource new_file_ref, 61 virtual int32_t Rename(PP_Resource new_file_ref,
50 scoped_refptr<TrackedCallback> callback) OVERRIDE; 62 scoped_refptr<TrackedCallback> callback) OVERRIDE;
51 virtual int32_t Query(PP_FileInfo* info, 63 virtual int32_t Query(PP_FileInfo* info,
52 scoped_refptr<TrackedCallback> callback) OVERRIDE; 64 scoped_refptr<TrackedCallback> callback) OVERRIDE;
65 virtual int32_t ReadEntries(const PP_ArrayOutput& output,
66 scoped_refptr<TrackedCallback> callback) OVERRIDE;
67 virtual int32_t ReadEntriesInHost(
68 std::vector<ppapi::PPB_FileRef_CreateInfo>* files,
69 std::vector<PP_FileType>* file_types,
70 scoped_refptr<TrackedCallback> callback) OVERRIDE;
53 virtual PP_Var GetAbsolutePath() OVERRIDE; 71 virtual PP_Var GetAbsolutePath() OVERRIDE;
54 72
55 // Executes the pending callback with the given ID. See pending_callbacks_. 73 // Executes the pending callback with the given ID. See pending_callbacks_.
56 void ExecuteCallback(uint32_t callback_id, int32_t result); 74 void ExecuteCallback(uint32_t callback_id, int32_t result);
57 void SetFileInfo(uint32_t callback_id, const PP_FileInfo& info); 75 void SetFileInfo(uint32_t callback_id, const PP_FileInfo& info);
76 int32_t SetReadEntriesOutput(
77 uint32_t callback_id,
78 const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos,
79 const std::vector<PP_FileType>& file_types);
58 80
59 private: 81 private:
60 PluginDispatcher* GetDispatcher() const { 82 PluginDispatcher* GetDispatcher() const {
61 return PluginDispatcher::GetForResource(this); 83 return PluginDispatcher::GetForResource(this);
62 } 84 }
63 85
64 // Adds a callback to the list and returns its ID. 86 // Adds a callback to the list and returns its ID.
65 uint32_t SendCallback(scoped_refptr<TrackedCallback> callback); 87 uint32_t SendCallback(scoped_refptr<TrackedCallback> callback);
66 88
67 // This class can have any number of out-standing requests with completion 89 // This class can have any number of out-standing requests with completion
68 // callbacks, in contrast to most resources which have one possible pending 90 // callbacks, in contrast to most resources which have one possible pending
69 // callback pending (like a Flush callback). 91 // callback pending (like a Flush callback).
70 // 92 //
71 // To keep track of them, assign integer IDs to the callbacks, which is how 93 // To keep track of them, assign integer IDs to the callbacks, which is how
72 // the callback will be identified when it's passed to the host and then 94 // the callback will be identified when it's passed to the host and then
73 // back here. Use unsigned so that overflow is well-defined. 95 // back here. Use unsigned so that overflow is well-defined.
74 uint32_t next_callback_id_; 96 uint32_t next_callback_id_;
75 typedef std::map<uint32_t, 97 typedef std::map<uint32_t,
76 scoped_refptr<TrackedCallback> > PendingCallbackMap; 98 scoped_refptr<TrackedCallback> > PendingCallbackMap;
77 PendingCallbackMap pending_callbacks_; 99 PendingCallbackMap pending_callbacks_;
78 100
79 // Used to keep pointers to PP_FileInfo instances that are written before 101 // Used to keep pointers to PP_FileInfo instances that are written before
80 // callbacks are invoked. The id of a pending file info will match that of 102 // callbacks are invoked. The id of a pending file info will match that of
81 // the corresponding callback. 103 // the corresponding callback.
82 typedef std::map<uint32_t, PP_FileInfo*> PendingFileInfoMap; 104 typedef std::map<uint32_t, PP_FileInfo*> PendingFileInfoMap;
83 PendingFileInfoMap pending_file_infos_; 105 PendingFileInfoMap pending_file_infos_;
84 106
107 // Used to keep PP_ArrayOutput instances that are written before callbacks
108 // are invoked. The id of a pending array output will match that of the
109 // corresponding callback.
110 typedef std::map<uint32_t, PP_ArrayOutput> PendingReadEntriesOutputMap;
palmer 2013/05/03 00:07:24 So, these are the uint32_ts that you elsewhere cal
hamaji 2013/05/03 01:10:34 They are actually opaque reference to callbacks. T
dmichael (off chromium) 2013/05/03 02:54:57 +1, map is more appropriate here.
111 PendingReadEntriesOutputMap pending_read_entries_outputs_;
112
85 // Holds a reference on plugin side when running out of process, so that 113 // Holds a reference on plugin side when running out of process, so that
86 // FileSystem won't die before FileRef. See PPB_FileRef_Impl for 114 // FileSystem won't die before FileRef. See PPB_FileRef_Impl for
87 // corresponding code for in-process mode. Note that this workaround will 115 // corresponding code for in-process mode. Note that this workaround will
88 // be no longer needed after FileRef refactoring. 116 // be no longer needed after FileRef refactoring.
89 ScopedPPResource file_system_; 117 ScopedPPResource file_system_;
90 118
91 DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef); 119 DISALLOW_IMPLICIT_CONSTRUCTORS(FileRef);
92 }; 120 };
93 121
94 FileRef::FileRef(const PPB_FileRef_CreateInfo& info) 122 FileRef::FileRef(const PPB_FileRef_CreateInfo& info)
95 : PPB_FileRef_Shared(OBJECT_IS_PROXY, info), 123 : PPB_FileRef_Shared(OBJECT_IS_PROXY, info),
96 next_callback_id_(0u), 124 next_callback_id_(0u),
97 file_system_(info.file_system_plugin_resource) { 125 file_system_(info.file_system_plugin_resource) {
98 } 126 }
99 127
100 FileRef::~FileRef() { 128 FileRef::~FileRef() {
101 // The callbacks map should have been cleared by LastPluginRefWasDeleted. 129 // The callbacks map should have been cleared by LastPluginRefWasDeleted.
102 DCHECK(pending_callbacks_.empty()); 130 DCHECK(pending_callbacks_.empty());
103 DCHECK(pending_file_infos_.empty()); 131 DCHECK(pending_file_infos_.empty());
132 DCHECK(pending_read_entries_outputs_.empty());
104 } 133 }
105 134
106 void FileRef::LastPluginRefWasDeleted() { 135 void FileRef::LastPluginRefWasDeleted() {
107 // The callback tracker will abort our callbacks for us. 136 // The callback tracker will abort our callbacks for us.
108 pending_callbacks_.clear(); 137 pending_callbacks_.clear();
109 pending_file_infos_.clear(); 138 pending_file_infos_.clear();
139 pending_read_entries_outputs_.clear();
110 } 140 }
111 141
112 PP_Resource FileRef::GetParent() { 142 PP_Resource FileRef::GetParent() {
113 PPB_FileRef_CreateInfo create_info; 143 PPB_FileRef_CreateInfo create_info;
114 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetParent( 144 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetParent(
115 API_ID_PPB_FILE_REF, host_resource(), &create_info)); 145 API_ID_PPB_FILE_REF, host_resource(), &create_info));
116 return PPB_FileRef_Proxy::DeserializeFileRef(create_info); 146 return PPB_FileRef_Proxy::DeserializeFileRef(create_info);
117 } 147 }
118 148
119 int32_t FileRef::MakeDirectory(PP_Bool make_ancestors, 149 int32_t FileRef::MakeDirectory(PP_Bool make_ancestors,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 int32_t FileRef::Query(PP_FileInfo* info, 186 int32_t FileRef::Query(PP_FileInfo* info,
157 scoped_refptr<TrackedCallback> callback) { 187 scoped_refptr<TrackedCallback> callback) {
158 // Store the pending file info id. 188 // Store the pending file info id.
159 int id = SendCallback(callback); 189 int id = SendCallback(callback);
160 pending_file_infos_[id] = info; 190 pending_file_infos_[id] = info;
161 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Query( 191 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_Query(
162 API_ID_PPB_FILE_REF, host_resource(), id)); 192 API_ID_PPB_FILE_REF, host_resource(), id));
163 return PP_OK_COMPLETIONPENDING; 193 return PP_OK_COMPLETIONPENDING;
164 } 194 }
165 195
196 int32_t FileRef::ReadEntries(const PP_ArrayOutput& output,
197 scoped_refptr<TrackedCallback> callback) {
198 // Store the pending read entries output id.
199 int id = SendCallback(callback);
palmer 2013/05/03 00:07:24 Should be uint32_t; or in ay case, this type and t
hamaji 2013/05/03 01:10:34 Done.
200 pending_read_entries_outputs_[id] = output;
201 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_ReadEntries(
202 API_ID_PPB_FILE_REF, host_resource(), id));
203 return PP_OK_COMPLETIONPENDING;
204 }
205
206 int32_t FileRef::ReadEntriesInHost(
207 std::vector<ppapi::PPB_FileRef_CreateInfo>* files,
208 std::vector<PP_FileType>* file_types,
209 scoped_refptr<TrackedCallback> callback) {
210 NOTREACHED();
211 return PP_ERROR_FAILED;
212 }
213
166 PP_Var FileRef::GetAbsolutePath() { 214 PP_Var FileRef::GetAbsolutePath() {
167 ReceiveSerializedVarReturnValue result; 215 ReceiveSerializedVarReturnValue result;
168 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetAbsolutePath( 216 GetDispatcher()->Send(new PpapiHostMsg_PPBFileRef_GetAbsolutePath(
169 API_ID_PPB_FILE_REF, host_resource(), &result)); 217 API_ID_PPB_FILE_REF, host_resource(), &result));
170 return result.Return(GetDispatcher()); 218 return result.Return(GetDispatcher());
171 } 219 }
172 220
173 void FileRef::ExecuteCallback(uint32_t callback_id, int32_t result) { 221 void FileRef::ExecuteCallback(uint32_t callback_id, int32_t result) {
174 PendingCallbackMap::iterator found = pending_callbacks_.find(callback_id); 222 PendingCallbackMap::iterator found = pending_callbacks_.find(callback_id);
175 if (found == pending_callbacks_.end()) { 223 if (found == pending_callbacks_.end()) {
(...skipping 11 matching lines...) Expand all
187 235
188 void FileRef::SetFileInfo(uint32_t callback_id, const PP_FileInfo& info) { 236 void FileRef::SetFileInfo(uint32_t callback_id, const PP_FileInfo& info) {
189 PendingFileInfoMap::iterator found = pending_file_infos_.find(callback_id); 237 PendingFileInfoMap::iterator found = pending_file_infos_.find(callback_id);
190 if (found == pending_file_infos_.end()) 238 if (found == pending_file_infos_.end())
191 return; 239 return;
192 PP_FileInfo* target_info = found->second; 240 PP_FileInfo* target_info = found->second;
193 *target_info = info; 241 *target_info = info;
194 pending_file_infos_.erase(found); 242 pending_file_infos_.erase(found);
195 } 243 }
196 244
245 int32_t FileRef::SetReadEntriesOutput(
246 uint32_t callback_id,
247 const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos,
248 const std::vector<PP_FileType>& file_types) {
249 PendingReadEntriesOutputMap::iterator found =
250 pending_read_entries_outputs_.find(callback_id);
251 if (found == pending_read_entries_outputs_.end())
252 return PP_OK;
raymes 2013/05/02 21:45:21 should this return PP_OK or a failure code? I thin
hamaji 2013/05/02 22:45:14 Oops, I think I tried to follow the logic of Query
253
254 PP_ArrayOutput output = found->second;
255 pending_read_entries_outputs_.erase(found);
256
257 std::vector<PP_DirectoryEntry> entries;
258 for (std::vector<ppapi::PPB_FileRef_CreateInfo>::size_type i = 0;
palmer 2013/05/03 00:07:24 Style guide says to just use size_t instead of the
hamaji 2013/05/03 01:10:34 Done.
259 i < infos.size(); ++i) {
260 PP_DirectoryEntry entry;
261 entry.file_ref = PPB_FileRef_Proxy::DeserializeFileRef(infos[i]);
262 entry.file_type = file_types[i];
263 entries.push_back(entry);
264 }
265
266 ArrayWriter writer(output);
267 if (!writer.is_valid()) {
268 ReleaseEntries(entries);
269 entries.clear();
270 return PP_ERROR_BADARGUMENT;
271 }
272
273 writer.StoreVector(entries);
274 entries.clear();
raymes 2013/05/02 21:45:21 nit: I don't think this (or the above entries.clea
hamaji 2013/05/02 22:45:14 Done.
275 return PP_OK;
276 }
277
197 uint32_t FileRef::SendCallback(scoped_refptr<TrackedCallback> callback) { 278 uint32_t FileRef::SendCallback(scoped_refptr<TrackedCallback> callback) {
198 // In extreme cases the IDs may wrap around, so avoid duplicates. 279 // In extreme cases the IDs may wrap around, so avoid duplicates.
199 while (pending_callbacks_.count(next_callback_id_)) 280 while (pending_callbacks_.count(next_callback_id_))
200 ++next_callback_id_; 281 ++next_callback_id_;
201 282
202 pending_callbacks_[next_callback_id_] = callback; 283 pending_callbacks_[next_callback_id_] = callback;
203 return next_callback_id_++; 284 return next_callback_id_++;
204 } 285 }
205 286
206 PPB_FileRef_Proxy::PPB_FileRef_Proxy(Dispatcher* dispatcher) 287 PPB_FileRef_Proxy::PPB_FileRef_Proxy(Dispatcher* dispatcher)
(...skipping 20 matching lines...) Expand all
227 IPC_BEGIN_MESSAGE_MAP(PPB_FileRef_Proxy, msg) 308 IPC_BEGIN_MESSAGE_MAP(PPB_FileRef_Proxy, msg)
228 #if !defined(OS_NACL) 309 #if !defined(OS_NACL)
229 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Create, OnMsgCreate) 310 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Create, OnMsgCreate)
230 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetParent, OnMsgGetParent) 311 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetParent, OnMsgGetParent)
231 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_MakeDirectory, 312 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_MakeDirectory,
232 OnMsgMakeDirectory) 313 OnMsgMakeDirectory)
233 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Touch, OnMsgTouch) 314 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Touch, OnMsgTouch)
234 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Delete, OnMsgDelete) 315 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Delete, OnMsgDelete)
235 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Rename, OnMsgRename) 316 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Rename, OnMsgRename)
236 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Query, OnMsgQuery) 317 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_Query, OnMsgQuery)
318 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_ReadEntries, OnMsgReadEntries)
237 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetAbsolutePath, 319 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFileRef_GetAbsolutePath,
238 OnMsgGetAbsolutePath) 320 OnMsgGetAbsolutePath)
239 #endif // !defined(OS_NACL) 321 #endif // !defined(OS_NACL)
240 322
241 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_CallbackComplete, 323 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_CallbackComplete,
242 OnMsgCallbackComplete) 324 OnMsgCallbackComplete)
243 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_QueryCallbackComplete, 325 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_QueryCallbackComplete,
244 OnMsgQueryCallbackComplete) 326 OnMsgQueryCallbackComplete)
327 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFileRef_ReadEntriesCallbackComplete,
328 OnMsgReadEntriesCallbackComplete)
245 IPC_MESSAGE_UNHANDLED(handled = false) 329 IPC_MESSAGE_UNHANDLED(handled = false)
246 IPC_END_MESSAGE_MAP() 330 IPC_END_MESSAGE_MAP()
247 return handled; 331 return handled;
248 } 332 }
249 333
250 // static 334 // static
251 void PPB_FileRef_Proxy::SerializeFileRef(PP_Resource file_ref, 335 void PPB_FileRef_Proxy::SerializeFileRef(PP_Resource file_ref,
252 PPB_FileRef_CreateInfo* result) { 336 PPB_FileRef_CreateInfo* result) {
253 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, false); 337 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref, false);
254 if (enter.succeeded()) 338 if (enter.succeeded())
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 file_ref, callback_factory_, 411 file_ref, callback_factory_,
328 &PPB_FileRef_Proxy::OnCallbackCompleteInHost, file_ref, callback_id); 412 &PPB_FileRef_Proxy::OnCallbackCompleteInHost, file_ref, callback_id);
329 if (enter.succeeded()) { 413 if (enter.succeeded()) {
330 enter.SetResult(enter.object()->Rename(new_file_ref.host_resource(), 414 enter.SetResult(enter.object()->Rename(new_file_ref.host_resource(),
331 enter.callback())); 415 enter.callback()));
332 } 416 }
333 } 417 }
334 418
335 void PPB_FileRef_Proxy::OnMsgQuery(const HostResource& file_ref, 419 void PPB_FileRef_Proxy::OnMsgQuery(const HostResource& file_ref,
336 uint32_t callback_id) { 420 uint32_t callback_id) {
337 PP_FileInfo* info = new PP_FileInfo(); 421 linked_ptr<PP_FileInfo> info(new PP_FileInfo());
338 EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter( 422 EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter(
339 file_ref, callback_factory_, 423 file_ref, callback_factory_,
340 &PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost, file_ref, 424 &PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost, file_ref,
341 base::Owned(info), callback_id); 425 info, callback_id);
342 if (enter.succeeded()) 426 if (enter.succeeded())
343 enter.SetResult(enter.object()->Query(info, enter.callback())); 427 enter.SetResult(enter.object()->Query(info.get(), enter.callback()));
344 } 428 }
345 429
346 void PPB_FileRef_Proxy::OnMsgGetAbsolutePath(const HostResource& host_resource, 430 void PPB_FileRef_Proxy::OnMsgGetAbsolutePath(const HostResource& host_resource,
347 SerializedVarReturnValue result) { 431 SerializedVarReturnValue result) {
348 EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource); 432 EnterHostFromHostResource<PPB_FileRef_API> enter(host_resource);
349 if (enter.succeeded()) 433 if (enter.succeeded())
350 result.Return(dispatcher(), enter.object()->GetAbsolutePath()); 434 result.Return(dispatcher(), enter.object()->GetAbsolutePath());
351 } 435 }
436
437 void PPB_FileRef_Proxy::OnMsgReadEntries(const HostResource& file_ref,
438 uint32_t callback_id) {
439 linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files(
440 new std::vector<ppapi::PPB_FileRef_CreateInfo>());
441 linked_ptr<std::vector<PP_FileType> > file_types(
442 new std::vector<PP_FileType>());
443 HostCallbackParams params(file_ref, callback_id);
444 EnterHostFromHostResourceForceCallback<PPB_FileRef_API> enter(
445 file_ref, callback_factory_,
446 &PPB_FileRef_Proxy::OnReadEntriesCallbackCompleteInHost,
447 params, files, file_types);
448 if (enter.succeeded()) {
449 enter.SetResult(enter.object()->ReadEntriesInHost(files.get(),
450 file_types.get(),
451 enter.callback()));
dmichael (off chromium) 2013/05/02 20:39:13 Hmm, it looks like if enter fails, the completion
hamaji 2013/05/02 22:45:14 Done. See the comment in file_callbacks.h for deta
452 }
453 }
454
352 #endif // !defined(OS_NACL) 455 #endif // !defined(OS_NACL)
353 456
354 void PPB_FileRef_Proxy::OnMsgCallbackComplete( 457 void PPB_FileRef_Proxy::OnMsgCallbackComplete(
355 const HostResource& host_resource, 458 const HostResource& host_resource,
356 uint32_t callback_id, 459 uint32_t callback_id,
357 int32_t result) { 460 int32_t result) {
358 // Forward the callback info to the plugin resource. 461 // Forward the callback info to the plugin resource.
359 EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); 462 EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource);
360 if (enter.succeeded()) 463 if (enter.succeeded())
361 static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); 464 static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result);
362 } 465 }
363 466
364 void PPB_FileRef_Proxy::OnMsgQueryCallbackComplete( 467 void PPB_FileRef_Proxy::OnMsgQueryCallbackComplete(
365 const HostResource& host_resource, 468 const HostResource& host_resource,
366 const PP_FileInfo& info, 469 const PP_FileInfo& info,
367 uint32_t callback_id, 470 uint32_t callback_id,
368 int32_t result) { 471 int32_t result) {
369 EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource); 472 EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource);
370 if (enter.succeeded()) { 473 if (enter.succeeded()) {
371 // Set the FileInfo output parameter. 474 // Set the FileInfo output parameter.
372 static_cast<FileRef*>(enter.object())->SetFileInfo(callback_id, info); 475 static_cast<FileRef*>(enter.object())->SetFileInfo(callback_id, info);
373 static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result); 476 static_cast<FileRef*>(enter.object())->ExecuteCallback(callback_id, result);
374 } 477 }
375 } 478 }
376 479
480 void PPB_FileRef_Proxy::OnMsgReadEntriesCallbackComplete(
481 const HostResource& host_resource,
482 const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos,
483 const std::vector<PP_FileType>& file_types,
484 uint32_t callback_id,
485 int32_t result) {
486 CHECK_EQ(infos.size(), file_types.size());
487
488 EnterPluginFromHostResource<PPB_FileRef_API> enter(host_resource);
489 if (enter.succeeded()) {
palmer 2013/05/03 00:07:24 Style nit: You could save a level of indentation b
hamaji 2013/05/03 01:10:34 Done.
490 if (result == PP_OK)
491 result = static_cast<FileRef*>(enter.object())->SetReadEntriesOutput(
492 callback_id, infos, file_types);
dmichael (off chromium) 2013/05/02 20:39:13 nit: please use curly braces for >1 line (even whe
hamaji 2013/05/02 22:45:14 Done.
493 static_cast<FileRef*>(enter.object())->ExecuteCallback(
494 callback_id, result);
495 }
496 }
497
377 #if !defined(OS_NACL) 498 #if !defined(OS_NACL)
378 void PPB_FileRef_Proxy::OnCallbackCompleteInHost( 499 void PPB_FileRef_Proxy::OnCallbackCompleteInHost(
379 int32_t result, 500 int32_t result,
380 const HostResource& host_resource, 501 const HostResource& host_resource,
381 uint32_t callback_id) { 502 uint32_t callback_id) {
382 // Execute OnMsgCallbackComplete in the plugin process. 503 // Execute OnMsgCallbackComplete in the plugin process.
383 Send(new PpapiMsg_PPBFileRef_CallbackComplete( 504 Send(new PpapiMsg_PPBFileRef_CallbackComplete(
384 API_ID_PPB_FILE_REF, host_resource, callback_id, result)); 505 API_ID_PPB_FILE_REF, host_resource, callback_id, result));
385 } 506 }
386 507
387 void PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost( 508 void PPB_FileRef_Proxy::OnQueryCallbackCompleteInHost(
388 int32_t result, 509 int32_t result,
389 const HostResource& host_resource, 510 const HostResource& host_resource,
390 base::internal::OwnedWrapper<PP_FileInfo> info, 511 linked_ptr<PP_FileInfo> info,
391 uint32_t callback_id) { 512 uint32_t callback_id) {
392 Send(new PpapiMsg_PPBFileRef_QueryCallbackComplete( 513 Send(new PpapiMsg_PPBFileRef_QueryCallbackComplete(
393 API_ID_PPB_FILE_REF, host_resource, *info.get(), callback_id, result)); 514 API_ID_PPB_FILE_REF, host_resource, *info.get(), callback_id, result));
394 } 515 }
516
517 void PPB_FileRef_Proxy::OnReadEntriesCallbackCompleteInHost(
518 int32_t result,
519 HostCallbackParams params,
520 linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files,
521 linked_ptr<std::vector<PP_FileType> > file_types) {
522 Send(new PpapiMsg_PPBFileRef_ReadEntriesCallbackComplete(
523 API_ID_PPB_FILE_REF, params.host_resource,
524 *files, *file_types, params.callback_id, result));
525 }
526
395 #endif // !defined(OS_NACL) 527 #endif // !defined(OS_NACL)
396 528
397 } // namespace proxy 529 } // namespace proxy
398 } // namespace ppapi 530 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698