OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ppapi/proxy/directory_reader_resource.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "ipc/ipc_message.h" | |
9 #include "ppapi/c/pp_errors.h" | |
10 #include "ppapi/proxy/dispatch_reply_message.h" | |
11 #include "ppapi/proxy/ppapi_messages.h" | |
12 #include "ppapi/proxy/ppb_file_ref_proxy.h" | |
13 #include "ppapi/shared_impl/ppapi_globals.h" | |
14 #include "ppapi/shared_impl/resource_tracker.h" | |
15 #include "ppapi/shared_impl/tracked_callback.h" | |
16 #include "ppapi/thunk/enter.h" | |
17 #include "ppapi/thunk/ppb_file_ref_api.h" | |
18 | |
19 using ppapi::proxy::PPB_FileRef_Proxy; | |
20 | |
21 namespace ppapi { | |
22 namespace proxy { | |
23 | |
24 DirectoryReaderResource::DirectoryReaderResource( | |
25 Connection connection, | |
26 PP_Instance instance, | |
27 PP_Resource directory_ref) | |
28 : PluginResource(connection, instance), | |
29 output_(NULL), | |
30 has_more_(true) { | |
31 directory_resource_ = | |
32 PpapiGlobals::Get()->GetResourceTracker()->GetResource(directory_ref); | |
33 } | |
34 | |
35 DirectoryReaderResource::~DirectoryReaderResource() { | |
36 } | |
37 | |
38 thunk::PPB_DirectoryReader_API* | |
39 DirectoryReaderResource::AsPPB_DirectoryReader_API() { | |
40 return this; | |
41 } | |
42 | |
43 int32_t DirectoryReaderResource::GetNextEntry( | |
44 PP_DirectoryEntry_Dev* entry, | |
45 scoped_refptr<TrackedCallback> callback) { | |
46 if (TrackedCallback::IsPending(callback_)) | |
47 return PP_ERROR_INPROGRESS; | |
48 | |
49 output_ = entry; | |
50 callback_ = callback; | |
51 | |
52 if (FillUpEntry()) | |
53 return PP_OK; | |
54 | |
55 if (!sent_create_to_renderer()) | |
56 SendCreate(RENDERER, PpapiHostMsg_DirectoryReader_Create()); | |
57 | |
58 PpapiHostMsg_DirectoryReader_GetEntries msg( | |
59 directory_resource_->host_resource()); | |
60 Call<PpapiPluginMsg_DirectoryReader_GetEntriesReply>( | |
61 RENDERER, msg, | |
62 base::Bind(&DirectoryReaderResource::OnPluginMsgGetEntriesReply, this)); | |
63 return PP_OK_COMPLETIONPENDING; | |
64 } | |
65 | |
66 void DirectoryReaderResource::OnPluginMsgGetEntriesReply( | |
67 const ResourceMessageReplyParams& params, | |
68 const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos, | |
69 const std::vector<PP_FileType>& file_types) { | |
70 CHECK_EQ(infos.size(), file_types.size()); | |
71 | |
72 for (std::vector<ppapi::PPB_FileRef_CreateInfo>::size_type i = 0; | |
73 i < infos.size(); ++i) { | |
74 DirectoryEntry entry; | |
75 entry.file_resource = ScopedPPResource( | |
76 ScopedPPResource::PassRef(), | |
77 PPB_FileRef_Proxy::DeserializeFileRef(infos[i])); | |
78 entry.file_type = file_types[i]; | |
79 entries_.push(entry); | |
80 } | |
81 has_more_ = false; | |
dmichael (off chromium)
2013/02/06 22:44:21
has_more_ is a confusing name to me, given that we
nhiroki
2013/02/07 09:37:27
Done.
| |
82 | |
83 if (!TrackedCallback::IsPending(callback_)) | |
84 return; | |
85 | |
86 FillUpEntry(); | |
87 callback_->Run(params.result()); | |
88 } | |
89 | |
90 bool DirectoryReaderResource::FillUpEntry() { | |
91 DCHECK(output_); | |
92 | |
dmichael (off chromium)
2013/02/06 22:44:21
Couldn't you bail early if you haven't received th
nhiroki
2013/02/07 09:37:27
Done.
| |
93 if (!entries_.empty()) { | |
94 DirectoryEntry entry = entries_.front(); | |
95 entries_.pop(); | |
96 output_->file_ref = entry.file_resource.Release(); | |
dmichael (off chromium)
2013/02/06 22:44:21
The API doc says:
"If entry->file_ref is non-zero
nhiroki
2013/02/07 09:37:27
Oops... I missed it. Thank you for catching. Done.
| |
97 output_->file_type = entry.file_type; | |
98 output_ = NULL; | |
99 return true; | |
100 } | |
101 | |
102 if (!has_more_) { | |
dmichael (off chromium)
2013/02/06 22:44:21
This could instead be an else if you bailed early
nhiroki
2013/02/07 09:37:27
Done.
| |
103 output_->file_ref = 0; | |
dmichael (off chromium)
2013/02/06 22:44:21
I think you also need to release output_->file_ref
nhiroki
2013/02/07 09:37:27
Done.
| |
104 output_->file_type = PP_FILETYPE_OTHER; | |
105 output_ = NULL; | |
106 return true; | |
107 } | |
108 | |
109 return false; | |
110 } | |
111 | |
112 } // namespace proxy | |
113 } // namespace ppapi | |
OLD | NEW |