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/plugin_globals.h" | |
12 #include "ppapi/proxy/ppapi_messages.h" | |
13 #include "ppapi/proxy/ppb_file_ref_proxy.h" | |
14 #include "ppapi/shared_impl/ppapi_globals.h" | |
15 #include "ppapi/shared_impl/resource.h" | |
16 #include "ppapi/shared_impl/resource_tracker.h" | |
17 #include "ppapi/thunk/enter.h" | |
18 #include "ppapi/thunk/ppb_file_ref_api.h" | |
19 | |
20 using ppapi::proxy::PPB_FileRef_Proxy; | |
21 | |
22 namespace ppapi { | |
23 namespace proxy { | |
24 | |
25 DirectoryReaderResource::DirectoryReaderResource( | |
26 Connection connection, | |
27 PP_Instance instance, | |
28 PP_Resource directory_ref) | |
29 : PluginResource(connection, instance), | |
30 directory_ref_(directory_ref), | |
31 has_more_(true) {} | |
yzshen1
2013/01/24 21:55:43
please init |entry_|.
nhiroki
2013/01/25 12:27:17
Done.
| |
32 | |
33 thunk::PPB_DirectoryReader_API* | |
34 DirectoryReaderResource::AsPPB_DirectoryReader_API() { | |
35 return this; | |
36 } | |
37 | |
38 int32_t DirectoryReaderResource::GetNextEntry( | |
39 PP_DirectoryEntry_Dev* entry, | |
40 scoped_refptr<TrackedCallback> callback) { | |
41 if (TrackedCallback::IsPending(callback_)) | |
42 return PP_ERROR_INPROGRESS; | |
43 | |
44 entry_ = entry; | |
45 callback_ = callback; | |
46 | |
47 if (FillUpEntry()) | |
48 return PP_OK; | |
49 | |
50 if (!sent_create_to_renderer()) | |
51 SendCreate(RENDERER, PpapiHostMsg_DirectoryReader_Create()); | |
52 | |
53 ppapi::ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker(); | |
54 PpapiHostMsg_DirectoryReader_GetNextEntry msg( | |
55 tracker->GetResource(directory_ref_)->host_resource()); | |
56 Call<PpapiPluginMsg_DirectoryReader_GetNextEntryReply>( | |
57 RENDERER, msg, | |
58 base::Bind(&DirectoryReaderResource::OnPluginMsgGetNextEntryReply, this)); | |
59 return PP_OK_COMPLETIONPENDING; | |
60 } | |
61 | |
62 void DirectoryReaderResource::OnPluginMsgGetNextEntryReply( | |
63 const ResourceMessageReplyParams& params, | |
64 const std::vector<ppapi::PPB_FileRef_CreateInfo> infos, | |
65 const std::vector<PP_FileType> file_types) { | |
66 DCHECK_EQ(infos.size(), file_types.size()); | |
yzshen1
2013/01/24 21:55:43
Please make it a CHECK. Something must be really w
nhiroki
2013/01/25 12:27:17
Done.
| |
67 | |
68 for (std::vector<ppapi::PPB_FileRef_CreateInfo>::size_type i = 0; | |
69 i < infos.size(); ++i) { | |
70 PP_DirectoryEntry_Dev entry; | |
71 entry.file_ref = PPB_FileRef_Proxy::DeserializeFileRef(infos[i]); | |
yzshen1
2013/01/24 21:55:43
Where do you release the ref? If the ref is not re
nhiroki
2013/01/25 12:27:17
Added release routine into the dtor.
| |
72 entry.file_type = file_types[i]; | |
73 entries_.push(entry); | |
74 } | |
75 | |
76 // Current implementation returns all entries at once. | |
77 // TODO(nhiroki): DirectoryReader should return directory entries in multiple | |
78 // chunks. | |
79 has_more_ = false; | |
80 | |
81 FillUpEntry(); | |
yzshen1
2013/01/24 21:55:43
[optional]
Please check that callback_ is still pe
nhiroki
2013/01/25 12:27:17
Done.
| |
82 entry_ = NULL; | |
83 | |
84 callback_->Run(params.result()); | |
85 } | |
86 | |
87 bool DirectoryReaderResource::FillUpEntry() { | |
88 DCHECK(entry_); | |
89 if (!entries_.empty()) { | |
90 *entry_ = entries_.front(); | |
91 entries_.pop(); | |
92 return true; | |
93 } | |
94 | |
95 if (!has_more_) { | |
96 entry_->file_ref = 0; | |
yzshen1
2013/01/24 21:55:43
Please also init the other field in |entry_|.
nhiroki
2013/01/25 12:27:17
Done.
| |
97 return true; | |
98 } | |
99 | |
100 return false; | |
101 } | |
102 | |
103 } // namespace proxy | |
104 } // namespace ppapi | |
OLD | NEW |