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

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

Issue 11958033: Implement Pepper proxy for PPB_DirectoryReader (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge PPB_DirectoryReader_Impl into PepperDirectoryReaderHost Created 7 years, 10 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
(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 directory_ref_(directory_ref),
30 output_(NULL),
31 has_more_(true) {
32 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(directory_ref_);
33 }
34
35 DirectoryReaderResource::~DirectoryReaderResource() {
36 ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
37 while (!entries_.empty()) {
38 tracker->ReleaseResource(entries_.front().file_ref);
39 entries_.pop();
40 }
41 tracker->ReleaseResource(directory_ref_);
42 }
43
44 thunk::PPB_DirectoryReader_API*
45 DirectoryReaderResource::AsPPB_DirectoryReader_API() {
46 return this;
47 }
48
49 int32_t DirectoryReaderResource::GetNextEntry(
50 PP_DirectoryEntry_Dev* entry,
51 scoped_refptr<TrackedCallback> callback) {
52 if (TrackedCallback::IsPending(callback_))
53 return PP_ERROR_INPROGRESS;
54
55 output_ = entry;
56 callback_ = callback;
57
58 if (FillUpEntry())
59 return PP_OK;
60
61 if (!sent_create_to_renderer())
62 SendCreate(RENDERER, PpapiHostMsg_DirectoryReader_Create());
63
64 ppapi::ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
65 PpapiHostMsg_DirectoryReader_GetEntries msg(
66 tracker->GetResource(directory_ref_)->host_resource());
67 Call<PpapiPluginMsg_DirectoryReader_GetEntriesReply>(
68 RENDERER, msg,
69 base::Bind(&DirectoryReaderResource::OnPluginMsgGetEntriesReply, this));
70 return PP_OK_COMPLETIONPENDING;
71 }
72
73 void DirectoryReaderResource::OnPluginMsgGetEntriesReply(
74 const ResourceMessageReplyParams& params,
75 const std::vector<ppapi::PPB_FileRef_CreateInfo>& infos,
76 const std::vector<PP_FileType>& file_types,
77 bool has_more) {
78 CHECK_EQ(infos.size(), file_types.size());
79
80 for (std::vector<ppapi::PPB_FileRef_CreateInfo>::size_type i = 0;
81 i < infos.size(); ++i) {
82 PP_DirectoryEntry_Dev entry;
83 entry.file_ref = PPB_FileRef_Proxy::DeserializeFileRef(infos[i]);
84 entry.file_type = file_types[i];
85 entries_.push(entry);
86 }
87
88 // Current implementation returns all entries at once from the host-side.
89 // TODO(nhiroki): The host-side should return entries in multiple chunks.
90 has_more_ = has_more;
91 DCHECK(!has_more_);
dmichael (off chromium) 2013/01/29 21:22:42 If we never use this parameter currently, maybe we
nhiroki 2013/01/30 09:24:51 Done.
92
93 if (!TrackedCallback::IsPending(callback_))
94 return;
95
96 FillUpEntry();
97 callback_->Run(params.result());
98 }
99
100 bool DirectoryReaderResource::FillUpEntry() {
101 DCHECK(output_);
102
103 if (!entries_.empty()) {
104 *output_ = entries_.front();
105 entries_.pop();
106 output_ = NULL;
107 return true;
108 }
109
110 if (!has_more_) {
111 output_->file_ref = 0;
112 output_->file_type = PP_FILETYPE_OTHER;
113 output_ = NULL;
114 return true;
115 }
116
117 return false;
118 }
119
120 } // namespace proxy
121 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698