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

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

Issue 21966004: Pepper: Move FileRef to the "new" resource proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor fixes for dmichael Created 7 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/file_ref_resource.h" 5 #include "ppapi/proxy/file_ref_resource.h"
6 6
7 #include "ppapi/c/pp_directory_entry.h" 7 #include "ppapi/c/pp_directory_entry.h"
8 #include "ppapi/c/pp_instance.h" 8 #include "ppapi/c/pp_instance.h"
9 #include "ppapi/c/pp_resource.h" 9 #include "ppapi/c/pp_resource.h"
10 #include "ppapi/proxy/ppapi_messages.h" 10 #include "ppapi/proxy/ppapi_messages.h"
11 #include "ppapi/shared_impl/array_writer.h" 11 #include "ppapi/shared_impl/array_writer.h"
12 #include "ppapi/shared_impl/file_ref_util.h" 12 #include "ppapi/shared_impl/file_ref_util.h"
13 #include "ppapi/shared_impl/resource.h" 13 #include "ppapi/shared_impl/resource.h"
14 #include "ppapi/shared_impl/resource_tracker.h" 14 #include "ppapi/shared_impl/resource_tracker.h"
15 #include "ppapi/shared_impl/var.h" 15 #include "ppapi/shared_impl/var.h"
16 #include "ppapi/thunk/enter.h" 16 #include "ppapi/thunk/enter.h"
17 #include "ppapi/thunk/ppb_file_system_api.h" 17 #include "ppapi/thunk/ppb_file_system_api.h"
18 18
19 namespace ppapi { 19 namespace ppapi {
20 namespace proxy { 20 namespace proxy {
21 21
22 FileRefResource::FileRefResource( 22 FileRefResource::FileRefResource(
23 Connection connection, 23 Connection connection,
24 PP_Instance instance, 24 PP_Instance instance,
25 const FileRef_CreateInfo& create_info) 25 const FileRefCreateInfo& create_info)
26 : PluginResource(connection, instance), 26 : PluginResource(connection, instance),
27 create_info_(create_info), 27 create_info_(create_info),
28 file_system_resource_(create_info.file_system_plugin_resource) { 28 file_system_resource_(create_info.file_system_plugin_resource) {
29 if (create_info_.file_system_type != PP_FILESYSTEMTYPE_EXTERNAL) { 29 if (create_info_.file_system_type != PP_FILESYSTEMTYPE_EXTERNAL) {
30 // If path ends with a slash, then normalize it away unless path is 30 // If path ends with a slash, then normalize it away unless path is
31 // the root path. 31 // the root path.
32 int path_size = create_info_.internal_path.size(); 32 int path_size = create_info_.internal_path.size();
33 if (path_size > 1 && create_info_.internal_path.at(path_size - 1) == '/') 33 if (path_size > 1 && create_info_.internal_path.at(path_size - 1) == '/')
34 create_info_.internal_path.erase(path_size - 1, 1); 34 create_info_.internal_path.erase(path_size - 1, 1);
35 35
36 path_var_ = new StringVar(create_info_.internal_path); 36 path_var_ = new StringVar(create_info_.internal_path);
37
38 create_info_.display_name = GetNameForInternalFilePath( 37 create_info_.display_name = GetNameForInternalFilePath(
39 create_info_.internal_path); 38 create_info_.internal_path);
40 } 39 }
41 name_var_ = new StringVar(create_info_.display_name); 40 name_var_ = new StringVar(create_info_.display_name);
42 41
43 if (create_info_.pending_host_resource_id != 0) { 42 if (create_info_.browser_pending_host_resource_id != 0 &&
yzshen1 2013/09/04 18:31:49 Do we need to handle the case in which one of them
teravest 2013/09/04 19:28:46 I'm not sure what the right thing is to do in that
yzshen1 2013/09/04 20:27:24 It is better to explicitly handle that case, eithe
44 AttachToPendingHost(BROWSER, create_info_.pending_host_resource_id); 43 create_info_.renderer_pending_host_resource_id != 0) {
44 AttachToPendingHost(BROWSER, create_info_.browser_pending_host_resource_id);
45 AttachToPendingHost(RENDERER,
46 create_info_.renderer_pending_host_resource_id);
45 } else { 47 } else {
46 CHECK(create_info_.file_system_type != PP_FILESYSTEMTYPE_EXTERNAL); 48 CHECK(create_info_.file_system_type != PP_FILESYSTEMTYPE_EXTERNAL);
47 SendCreate(BROWSER, PpapiHostMsg_FileRef_CreateInternal( 49 SendCreate(BROWSER, PpapiHostMsg_FileRef_CreateInternal(
48 create_info.file_system_plugin_resource, 50 create_info.file_system_plugin_resource,
49 create_info.internal_path)); 51 create_info.internal_path));
52 SendCreate(RENDERER, PpapiHostMsg_FileRef_CreateInternal(
53 create_info.file_system_plugin_resource,
54 create_info.internal_path));
50 } 55 }
51 } 56 }
52 57
53 FileRefResource::~FileRefResource() { 58 FileRefResource::~FileRefResource() {
54 } 59 }
55 60
56 //static 61 //static
57 PP_Resource FileRefResource::CreateFileRef( 62 PP_Resource FileRefResource::CreateFileRef(
58 Connection connection, 63 Connection connection,
59 PP_Instance instance, 64 PP_Instance instance,
60 const FileRef_CreateInfo& create_info) { 65 const FileRefCreateInfo& create_info) {
61 // If we have a valid file_system resource, ensure that its type matches that 66 // If we have a valid file_system resource, ensure that its type matches that
62 // of the fs_type parameter. 67 // of the fs_type parameter.
63 if (create_info.file_system_plugin_resource != 0) { 68 if (create_info.file_system_plugin_resource != 0) {
64 thunk::EnterResourceNoLock<thunk::PPB_FileSystem_API> enter( 69 thunk::EnterResourceNoLock<thunk::PPB_FileSystem_API> enter(
65 create_info.file_system_plugin_resource, true); 70 create_info.file_system_plugin_resource, true);
66 if (enter.failed()) 71 if (enter.failed())
67 return 0; 72 return 0;
68 if (enter.object()->GetType() != create_info.file_system_type) { 73 if (enter.object()->GetType() != create_info.file_system_type) {
69 NOTREACHED() << "file system type mismatch with resource"; 74 NOTREACHED() << "file system type mismatch with resource";
70 return 0; 75 return 0;
71 } 76 }
72 } 77 }
73 78
74 if (create_info.file_system_type == PP_FILESYSTEMTYPE_LOCALPERSISTENT || 79 if (create_info.file_system_type == PP_FILESYSTEMTYPE_LOCALPERSISTENT ||
75 create_info.file_system_type == PP_FILESYSTEMTYPE_LOCALTEMPORARY) { 80 create_info.file_system_type == PP_FILESYSTEMTYPE_LOCALTEMPORARY) {
76 if (!IsValidInternalPath(create_info.internal_path)) 81 if (!IsValidInternalPath(create_info.internal_path))
77 return 0; 82 return 0;
78 } 83 }
79 return (new FileRefResource(connection, 84 return (new FileRefResource(connection,
80 instance, 85 instance,
81 create_info))->GetReference(); 86 create_info))->GetReference();
82 } 87 }
83 88
84 thunk::PPB_FileRef_API* FileRefResource::AsPPB_FileRef_API() { 89 thunk::PPB_FileRef_API* FileRefResource::AsPPB_FileRef_API() {
85 // TODO: return "this" once we update PPB_FileRef_API. 90 return this;
86 NOTREACHED();
87 return NULL;
88 } 91 }
89 92
90 PP_FileSystemType FileRefResource::GetFileSystemType() const { 93 PP_FileSystemType FileRefResource::GetFileSystemType() const {
91 return create_info_.file_system_type; 94 return create_info_.file_system_type;
92 } 95 }
93 96
94 PP_Var FileRefResource::GetName() const { 97 PP_Var FileRefResource::GetName() const {
95 return name_var_->GetPPVar(); 98 return name_var_->GetPPVar();
96 } 99 }
97 100
98 PP_Var FileRefResource::GetPath() const { 101 PP_Var FileRefResource::GetPath() const {
99 if (create_info_.file_system_type == PP_FILESYSTEMTYPE_EXTERNAL) 102 if (create_info_.file_system_type == PP_FILESYSTEMTYPE_EXTERNAL)
100 return PP_MakeUndefined(); 103 return PP_MakeUndefined();
101 return path_var_->GetPPVar(); 104 return path_var_->GetPPVar();
102 } 105 }
103 106
104 PP_Resource FileRefResource::GetParent() { 107 PP_Resource FileRefResource::GetParent() {
105 if (create_info_.file_system_type == PP_FILESYSTEMTYPE_EXTERNAL) 108 if (create_info_.file_system_type == PP_FILESYSTEMTYPE_EXTERNAL)
106 return 0; 109 return 0;
107 110
108 size_t pos = create_info_.internal_path.rfind('/'); 111 size_t pos = create_info_.internal_path.rfind('/');
109 CHECK(pos != std::string::npos); 112 CHECK(pos != std::string::npos);
110 if (pos == 0) 113 if (pos == 0)
111 pos++; 114 pos++;
112 std::string parent_path = create_info_.internal_path.substr(0, pos); 115 std::string parent_path = create_info_.internal_path.substr(0, pos);
113 116
114 ppapi::FileRef_CreateInfo parent_info; 117 ppapi::FileRefCreateInfo parent_info;
115 parent_info.file_system_type = create_info_.file_system_type; 118 parent_info.file_system_type = create_info_.file_system_type;
116 parent_info.internal_path = parent_path; 119 parent_info.internal_path = parent_path;
117 parent_info.display_name = GetNameForInternalFilePath(parent_path); 120 parent_info.display_name = GetNameForInternalFilePath(parent_path);
118 parent_info.file_system_plugin_resource = 121 parent_info.file_system_plugin_resource =
119 create_info_.file_system_plugin_resource; 122 create_info_.file_system_plugin_resource;
120 123
121 return (new FileRefResource(connection(), 124 return (new FileRefResource(connection(),
122 pp_instance(), 125 pp_instance(),
123 parent_info))->GetReference(); 126 parent_info))->GetReference();
124 } 127 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 const PP_ArrayOutput& output, 180 const PP_ArrayOutput& output,
178 scoped_refptr<TrackedCallback> callback) { 181 scoped_refptr<TrackedCallback> callback) {
179 Call<PpapiPluginMsg_FileRef_ReadDirectoryEntriesReply>( 182 Call<PpapiPluginMsg_FileRef_ReadDirectoryEntriesReply>(
180 BROWSER, 183 BROWSER,
181 PpapiHostMsg_FileRef_ReadDirectoryEntries(), 184 PpapiHostMsg_FileRef_ReadDirectoryEntries(),
182 base::Bind(&FileRefResource::OnDirectoryEntriesReply, 185 base::Bind(&FileRefResource::OnDirectoryEntriesReply,
183 this, output, callback)); 186 this, output, callback));
184 return PP_OK_COMPLETIONPENDING; 187 return PP_OK_COMPLETIONPENDING;
185 } 188 }
186 189
187 /* 190 const FileRefCreateInfo& FileRefResource::GetCreateInfo() const {
188 const FileRef_CreateInfo& FileRefResource::GetCreateInfo() const {
189 return create_info_; 191 return create_info_;
190 } 192 }
191 */
192 const PPB_FileRef_CreateInfo& FileRefResource::GetCreateInfo() const {
193 // FIXME
194 NOTREACHED();
195 PPB_FileRef_CreateInfo *info = new PPB_FileRef_CreateInfo();
196 return *info;
197 }
198
199 // TODO(teravest): Remove this when we are finished moving to the new proxy.
200 int32_t FileRefResource::QueryInHost(linked_ptr<PP_FileInfo> info,
201 scoped_refptr<TrackedCallback> callback) {
202 NOTREACHED();
203 return PP_ERROR_FAILED;
204 }
205
206 // TODO(teravest): Remove this when we are finished moving to the new proxy.
207 int32_t FileRefResource::ReadDirectoryEntriesInHost(
208 linked_ptr<std::vector<ppapi::PPB_FileRef_CreateInfo> > files,
209 linked_ptr<std::vector<PP_FileType> > file_types,
210 scoped_refptr<TrackedCallback> callback) {
211 NOTREACHED();
212 return PP_ERROR_FAILED;
213 }
214 193
215 PP_Var FileRefResource::GetAbsolutePath() { 194 PP_Var FileRefResource::GetAbsolutePath() {
216 if (!absolute_path_var_.get()) { 195 if (!absolute_path_var_.get()) {
217 std::string absolute_path; 196 std::string absolute_path;
218 int32_t result = SyncCall<PpapiPluginMsg_FileRef_GetAbsolutePathReply>( 197 int32_t result = SyncCall<PpapiPluginMsg_FileRef_GetAbsolutePathReply>(
219 BROWSER, PpapiHostMsg_FileRef_GetAbsolutePath(), &absolute_path); 198 BROWSER, PpapiHostMsg_FileRef_GetAbsolutePath(), &absolute_path);
220 if (result != PP_OK) 199 if (result != PP_OK)
221 return PP_MakeUndefined(); 200 return PP_MakeUndefined();
222 absolute_path_var_ = new StringVar(absolute_path); 201 absolute_path_var_ = new StringVar(absolute_path);
223 } 202 }
(...skipping 17 matching lines...) Expand all
241 220
242 if (params.result() == PP_OK) 221 if (params.result() == PP_OK)
243 *out_info = info; 222 *out_info = info;
244 callback->Run(params.result()); 223 callback->Run(params.result());
245 } 224 }
246 225
247 void FileRefResource::OnDirectoryEntriesReply( 226 void FileRefResource::OnDirectoryEntriesReply(
248 const PP_ArrayOutput& output, 227 const PP_ArrayOutput& output,
249 scoped_refptr<TrackedCallback> callback, 228 scoped_refptr<TrackedCallback> callback,
250 const ResourceMessageReplyParams& params, 229 const ResourceMessageReplyParams& params,
251 const std::vector<ppapi::FileRef_CreateInfo>& infos, 230 const std::vector<ppapi::FileRefCreateInfo>& infos,
252 const std::vector<PP_FileType>& file_types) { 231 const std::vector<PP_FileType>& file_types) {
253 if (!TrackedCallback::IsPending(callback)) 232 if (!TrackedCallback::IsPending(callback))
254 return; 233 return;
255 234
256 if (params.result() == PP_OK) { 235 if (params.result() == PP_OK) {
257 ArrayWriter writer(output); 236 ArrayWriter writer(output);
258 if (!writer.is_valid()) { 237 if (!writer.is_valid()) {
259 callback->Run(PP_ERROR_BADARGUMENT); 238 callback->Run(PP_ERROR_BADARGUMENT);
260 return; 239 return;
261 } 240 }
262 241
263 std::vector<PP_DirectoryEntry> entries; 242 std::vector<PP_DirectoryEntry> entries;
264 for (size_t i = 0; i < infos.size(); ++i) { 243 for (size_t i = 0; i < infos.size(); ++i) {
265 PP_DirectoryEntry entry; 244 PP_DirectoryEntry entry;
266 entry.file_ref = FileRefResource::CreateFileRef(connection(), 245 entry.file_ref = FileRefResource::CreateFileRef(connection(),
267 pp_instance(), 246 pp_instance(),
268 infos[i]); 247 infos[i]);
269 entry.file_type = file_types[i]; 248 entry.file_type = file_types[i];
270 entries.push_back(entry); 249 entries.push_back(entry);
271 } 250 }
272 251
273 writer.StoreVector(entries); 252 writer.StoreVector(entries);
274 } 253 }
275 callback->Run(params.result()); 254 callback->Run(params.result());
276 } 255 }
277 256
278 } // namespace proxy 257 } // namespace proxy
279 } // namespace ppapi 258 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698