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

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

Issue 23647008: Revert 221284 "Pepper: Move FileRef to the "new" resource proxy." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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
« no previous file with comments | « trunk/src/ppapi/proxy/file_ref_resource.h ('k') | trunk/src/ppapi/proxy/flash_drm_resource.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 FileRefCreateInfo& create_info) 25 const FileRef_CreateInfo& 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
37 create_info_.display_name = GetNameForInternalFilePath( 38 create_info_.display_name = GetNameForInternalFilePath(
38 create_info_.internal_path); 39 create_info_.internal_path);
39 } 40 }
40 name_var_ = new StringVar(create_info_.display_name); 41 name_var_ = new StringVar(create_info_.display_name);
41 42
42 if (create_info_.browser_pending_host_resource_id != 0 && 43 if (create_info_.pending_host_resource_id != 0) {
43 create_info_.renderer_pending_host_resource_id != 0) { 44 AttachToPendingHost(BROWSER, create_info_.pending_host_resource_id);
44 AttachToPendingHost(BROWSER, create_info_.browser_pending_host_resource_id);
45 AttachToPendingHost(RENDERER,
46 create_info_.renderer_pending_host_resource_id);
47 } else { 45 } else {
48 CHECK(create_info_.browser_pending_host_resource_id == 0);
49 CHECK(create_info_.renderer_pending_host_resource_id == 0);
50 CHECK(create_info_.file_system_type != PP_FILESYSTEMTYPE_EXTERNAL); 46 CHECK(create_info_.file_system_type != PP_FILESYSTEMTYPE_EXTERNAL);
51 SendCreate(BROWSER, PpapiHostMsg_FileRef_CreateInternal( 47 SendCreate(BROWSER, PpapiHostMsg_FileRef_CreateInternal(
52 create_info.file_system_plugin_resource, 48 create_info.file_system_plugin_resource,
53 create_info.internal_path)); 49 create_info.internal_path));
54 SendCreate(RENDERER, PpapiHostMsg_FileRef_CreateInternal(
55 create_info.file_system_plugin_resource,
56 create_info.internal_path));
57 } 50 }
58 } 51 }
59 52
60 FileRefResource::~FileRefResource() { 53 FileRefResource::~FileRefResource() {
61 } 54 }
62 55
63 //static 56 //static
64 PP_Resource FileRefResource::CreateFileRef( 57 PP_Resource FileRefResource::CreateFileRef(
65 Connection connection, 58 Connection connection,
66 PP_Instance instance, 59 PP_Instance instance,
67 const FileRefCreateInfo& create_info) { 60 const FileRef_CreateInfo& create_info) {
68 // If we have a valid file_system resource, ensure that its type matches that 61 // If we have a valid file_system resource, ensure that its type matches that
69 // of the fs_type parameter. 62 // of the fs_type parameter.
70 if (create_info.file_system_plugin_resource != 0) { 63 if (create_info.file_system_plugin_resource != 0) {
71 thunk::EnterResourceNoLock<thunk::PPB_FileSystem_API> enter( 64 thunk::EnterResourceNoLock<thunk::PPB_FileSystem_API> enter(
72 create_info.file_system_plugin_resource, true); 65 create_info.file_system_plugin_resource, true);
73 if (enter.failed()) 66 if (enter.failed())
74 return 0; 67 return 0;
75 if (enter.object()->GetType() != create_info.file_system_type) { 68 if (enter.object()->GetType() != create_info.file_system_type) {
76 NOTREACHED() << "file system type mismatch with resource"; 69 NOTREACHED() << "file system type mismatch with resource";
77 return 0; 70 return 0;
78 } 71 }
79 } 72 }
80 73
81 if (create_info.file_system_type == PP_FILESYSTEMTYPE_LOCALPERSISTENT || 74 if (create_info.file_system_type == PP_FILESYSTEMTYPE_LOCALPERSISTENT ||
82 create_info.file_system_type == PP_FILESYSTEMTYPE_LOCALTEMPORARY) { 75 create_info.file_system_type == PP_FILESYSTEMTYPE_LOCALTEMPORARY) {
83 if (!IsValidInternalPath(create_info.internal_path)) 76 if (!IsValidInternalPath(create_info.internal_path))
84 return 0; 77 return 0;
85 } 78 }
86 return (new FileRefResource(connection, 79 return (new FileRefResource(connection,
87 instance, 80 instance,
88 create_info))->GetReference(); 81 create_info))->GetReference();
89 } 82 }
90 83
91 thunk::PPB_FileRef_API* FileRefResource::AsPPB_FileRef_API() { 84 thunk::PPB_FileRef_API* FileRefResource::AsPPB_FileRef_API() {
92 return this; 85 // TODO: return "this" once we update PPB_FileRef_API.
86 NOTREACHED();
87 return NULL;
93 } 88 }
94 89
95 PP_FileSystemType FileRefResource::GetFileSystemType() const { 90 PP_FileSystemType FileRefResource::GetFileSystemType() const {
96 return create_info_.file_system_type; 91 return create_info_.file_system_type;
97 } 92 }
98 93
99 PP_Var FileRefResource::GetName() const { 94 PP_Var FileRefResource::GetName() const {
100 return name_var_->GetPPVar(); 95 return name_var_->GetPPVar();
101 } 96 }
102 97
103 PP_Var FileRefResource::GetPath() const { 98 PP_Var FileRefResource::GetPath() const {
104 if (create_info_.file_system_type == PP_FILESYSTEMTYPE_EXTERNAL) 99 if (create_info_.file_system_type == PP_FILESYSTEMTYPE_EXTERNAL)
105 return PP_MakeUndefined(); 100 return PP_MakeUndefined();
106 return path_var_->GetPPVar(); 101 return path_var_->GetPPVar();
107 } 102 }
108 103
109 PP_Resource FileRefResource::GetParent() { 104 PP_Resource FileRefResource::GetParent() {
110 if (create_info_.file_system_type == PP_FILESYSTEMTYPE_EXTERNAL) 105 if (create_info_.file_system_type == PP_FILESYSTEMTYPE_EXTERNAL)
111 return 0; 106 return 0;
112 107
113 size_t pos = create_info_.internal_path.rfind('/'); 108 size_t pos = create_info_.internal_path.rfind('/');
114 CHECK(pos != std::string::npos); 109 CHECK(pos != std::string::npos);
115 if (pos == 0) 110 if (pos == 0)
116 pos++; 111 pos++;
117 std::string parent_path = create_info_.internal_path.substr(0, pos); 112 std::string parent_path = create_info_.internal_path.substr(0, pos);
118 113
119 ppapi::FileRefCreateInfo parent_info; 114 ppapi::FileRef_CreateInfo parent_info;
120 parent_info.file_system_type = create_info_.file_system_type; 115 parent_info.file_system_type = create_info_.file_system_type;
121 parent_info.internal_path = parent_path; 116 parent_info.internal_path = parent_path;
122 parent_info.display_name = GetNameForInternalFilePath(parent_path); 117 parent_info.display_name = GetNameForInternalFilePath(parent_path);
123 parent_info.file_system_plugin_resource = 118 parent_info.file_system_plugin_resource =
124 create_info_.file_system_plugin_resource; 119 create_info_.file_system_plugin_resource;
125 120
126 return (new FileRefResource(connection(), 121 return (new FileRefResource(connection(),
127 pp_instance(), 122 pp_instance(),
128 parent_info))->GetReference(); 123 parent_info))->GetReference();
129 } 124 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 const PP_ArrayOutput& output, 177 const PP_ArrayOutput& output,
183 scoped_refptr<TrackedCallback> callback) { 178 scoped_refptr<TrackedCallback> callback) {
184 Call<PpapiPluginMsg_FileRef_ReadDirectoryEntriesReply>( 179 Call<PpapiPluginMsg_FileRef_ReadDirectoryEntriesReply>(
185 BROWSER, 180 BROWSER,
186 PpapiHostMsg_FileRef_ReadDirectoryEntries(), 181 PpapiHostMsg_FileRef_ReadDirectoryEntries(),
187 base::Bind(&FileRefResource::OnDirectoryEntriesReply, 182 base::Bind(&FileRefResource::OnDirectoryEntriesReply,
188 this, output, callback)); 183 this, output, callback));
189 return PP_OK_COMPLETIONPENDING; 184 return PP_OK_COMPLETIONPENDING;
190 } 185 }
191 186
192 const FileRefCreateInfo& FileRefResource::GetCreateInfo() const { 187 /*
188 const FileRef_CreateInfo& FileRefResource::GetCreateInfo() const {
193 return create_info_; 189 return create_info_;
194 } 190 }
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 }
195 214
196 PP_Var FileRefResource::GetAbsolutePath() { 215 PP_Var FileRefResource::GetAbsolutePath() {
197 if (!absolute_path_var_.get()) { 216 if (!absolute_path_var_.get()) {
198 std::string absolute_path; 217 std::string absolute_path;
199 int32_t result = SyncCall<PpapiPluginMsg_FileRef_GetAbsolutePathReply>( 218 int32_t result = SyncCall<PpapiPluginMsg_FileRef_GetAbsolutePathReply>(
200 BROWSER, PpapiHostMsg_FileRef_GetAbsolutePath(), &absolute_path); 219 BROWSER, PpapiHostMsg_FileRef_GetAbsolutePath(), &absolute_path);
201 if (result != PP_OK) 220 if (result != PP_OK)
202 return PP_MakeUndefined(); 221 return PP_MakeUndefined();
203 absolute_path_var_ = new StringVar(absolute_path); 222 absolute_path_var_ = new StringVar(absolute_path);
204 } 223 }
(...skipping 17 matching lines...) Expand all
222 241
223 if (params.result() == PP_OK) 242 if (params.result() == PP_OK)
224 *out_info = info; 243 *out_info = info;
225 callback->Run(params.result()); 244 callback->Run(params.result());
226 } 245 }
227 246
228 void FileRefResource::OnDirectoryEntriesReply( 247 void FileRefResource::OnDirectoryEntriesReply(
229 const PP_ArrayOutput& output, 248 const PP_ArrayOutput& output,
230 scoped_refptr<TrackedCallback> callback, 249 scoped_refptr<TrackedCallback> callback,
231 const ResourceMessageReplyParams& params, 250 const ResourceMessageReplyParams& params,
232 const std::vector<ppapi::FileRefCreateInfo>& infos, 251 const std::vector<ppapi::FileRef_CreateInfo>& infos,
233 const std::vector<PP_FileType>& file_types) { 252 const std::vector<PP_FileType>& file_types) {
234 if (!TrackedCallback::IsPending(callback)) 253 if (!TrackedCallback::IsPending(callback))
235 return; 254 return;
236 255
237 if (params.result() == PP_OK) { 256 if (params.result() == PP_OK) {
238 ArrayWriter writer(output); 257 ArrayWriter writer(output);
239 if (!writer.is_valid()) { 258 if (!writer.is_valid()) {
240 callback->Run(PP_ERROR_BADARGUMENT); 259 callback->Run(PP_ERROR_BADARGUMENT);
241 return; 260 return;
242 } 261 }
243 262
244 std::vector<PP_DirectoryEntry> entries; 263 std::vector<PP_DirectoryEntry> entries;
245 for (size_t i = 0; i < infos.size(); ++i) { 264 for (size_t i = 0; i < infos.size(); ++i) {
246 PP_DirectoryEntry entry; 265 PP_DirectoryEntry entry;
247 entry.file_ref = FileRefResource::CreateFileRef(connection(), 266 entry.file_ref = FileRefResource::CreateFileRef(connection(),
248 pp_instance(), 267 pp_instance(),
249 infos[i]); 268 infos[i]);
250 entry.file_type = file_types[i]; 269 entry.file_type = file_types[i];
251 entries.push_back(entry); 270 entries.push_back(entry);
252 } 271 }
253 272
254 writer.StoreVector(entries); 273 writer.StoreVector(entries);
255 } 274 }
256 callback->Run(params.result()); 275 callback->Run(params.result());
257 } 276 }
258 277
259 } // namespace proxy 278 } // namespace proxy
260 } // namespace ppapi 279 } // namespace ppapi
OLDNEW
« no previous file with comments | « trunk/src/ppapi/proxy/file_ref_resource.h ('k') | trunk/src/ppapi/proxy/flash_drm_resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698