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

Side by Side Diff: content/browser/renderer_host/pepper/pepper_internal_file_ref_backend.cc

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 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 "content/browser/renderer_host/pepper/pepper_internal_file_ref_backend. h" 5 #include "content/browser/renderer_host/pepper/pepper_internal_file_ref_backend. h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 15 matching lines...) Expand all
26 #include "ppapi/proxy/ppapi_messages.h" 26 #include "ppapi/proxy/ppapi_messages.h"
27 #include "ppapi/shared_impl/file_ref_create_info.h" 27 #include "ppapi/shared_impl/file_ref_create_info.h"
28 #include "ppapi/shared_impl/file_ref_util.h" 28 #include "ppapi/shared_impl/file_ref_util.h"
29 #include "ppapi/shared_impl/file_type_conversion.h" 29 #include "ppapi/shared_impl/file_type_conversion.h"
30 #include "ppapi/shared_impl/scoped_pp_var.h" 30 #include "ppapi/shared_impl/scoped_pp_var.h"
31 #include "ppapi/shared_impl/time_conversion.h" 31 #include "ppapi/shared_impl/time_conversion.h"
32 #include "ppapi/shared_impl/var.h" 32 #include "ppapi/shared_impl/var.h"
33 #include "ppapi/thunk/enter.h" 33 #include "ppapi/thunk/enter.h"
34 #include "ppapi/thunk/ppb_file_ref_api.h" 34 #include "ppapi/thunk/ppb_file_ref_api.h"
35 #include "ppapi/thunk/ppb_file_system_api.h" 35 #include "ppapi/thunk/ppb_file_system_api.h"
36 #include "webkit/browser/fileapi/file_system_operation.h" 36 #include "storage/browser/fileapi/file_system_operation.h"
37 #include "webkit/browser/fileapi/file_system_operation_runner.h" 37 #include "storage/browser/fileapi/file_system_operation_runner.h"
38 #include "webkit/browser/fileapi/file_system_url.h" 38 #include "storage/browser/fileapi/file_system_url.h"
39 #include "webkit/common/fileapi/file_system_util.h" 39 #include "storage/common/fileapi/file_system_util.h"
40 40
41 using ppapi::host::PpapiHost; 41 using ppapi::host::PpapiHost;
42 using ppapi::host::ResourceHost; 42 using ppapi::host::ResourceHost;
43 43
44 namespace content { 44 namespace content {
45 45
46 PepperInternalFileRefBackend::PepperInternalFileRefBackend( 46 PepperInternalFileRefBackend::PepperInternalFileRefBackend(
47 PpapiHost* host, 47 PpapiHost* host,
48 int render_process_id, 48 int render_process_id,
49 base::WeakPtr<PepperFileSystemBrowserHost> fs_host, 49 base::WeakPtr<PepperFileSystemBrowserHost> fs_host,
50 const std::string& path) 50 const std::string& path)
51 : host_(host), 51 : host_(host),
52 render_process_id_(render_process_id), 52 render_process_id_(render_process_id),
53 fs_host_(fs_host), 53 fs_host_(fs_host),
54 fs_type_(fs_host->GetType()), 54 fs_type_(fs_host->GetType()),
55 path_(path), 55 path_(path),
56 weak_factory_(this) { 56 weak_factory_(this) {
57 ppapi::NormalizeInternalPath(&path_); 57 ppapi::NormalizeInternalPath(&path_);
58 } 58 }
59 59
60 PepperInternalFileRefBackend::~PepperInternalFileRefBackend() {} 60 PepperInternalFileRefBackend::~PepperInternalFileRefBackend() {}
61 61
62 fileapi::FileSystemURL PepperInternalFileRefBackend::GetFileSystemURL() const { 62 storage::FileSystemURL PepperInternalFileRefBackend::GetFileSystemURL() const {
63 if (!fs_url_.is_valid() && fs_host_.get() && fs_host_->IsOpened()) { 63 if (!fs_url_.is_valid() && fs_host_.get() && fs_host_->IsOpened()) {
64 GURL fs_path = 64 GURL fs_path =
65 fs_host_->GetRootUrl().Resolve(net::EscapePath(path_.substr(1))); 65 fs_host_->GetRootUrl().Resolve(net::EscapePath(path_.substr(1)));
66 scoped_refptr<fileapi::FileSystemContext> fs_context = 66 scoped_refptr<storage::FileSystemContext> fs_context =
67 GetFileSystemContext(); 67 GetFileSystemContext();
68 if (fs_context.get()) 68 if (fs_context.get())
69 fs_url_ = fs_context->CrackURL(fs_path); 69 fs_url_ = fs_context->CrackURL(fs_path);
70 } 70 }
71 return fs_url_; 71 return fs_url_;
72 } 72 }
73 73
74 base::FilePath PepperInternalFileRefBackend::GetExternalFilePath() const { 74 base::FilePath PepperInternalFileRefBackend::GetExternalFilePath() const {
75 return base::FilePath(); 75 return base::FilePath();
76 } 76 }
77 77
78 scoped_refptr<fileapi::FileSystemContext> 78 scoped_refptr<storage::FileSystemContext>
79 PepperInternalFileRefBackend::GetFileSystemContext() const { 79 PepperInternalFileRefBackend::GetFileSystemContext() const {
80 if (!fs_host_.get()) 80 if (!fs_host_.get())
81 return NULL; 81 return NULL;
82 return fs_host_->GetFileSystemContext(); 82 return fs_host_->GetFileSystemContext();
83 } 83 }
84 84
85 void PepperInternalFileRefBackend::DidFinish( 85 void PepperInternalFileRefBackend::DidFinish(
86 ppapi::host::ReplyMessageContext context, 86 ppapi::host::ReplyMessageContext context,
87 const IPC::Message& msg, 87 const IPC::Message& msg,
88 base::File::Error error) { 88 base::File::Error error) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 PpapiPluginMsg_FileRef_DeleteReply())); 139 PpapiPluginMsg_FileRef_DeleteReply()));
140 return PP_OK_COMPLETIONPENDING; 140 return PP_OK_COMPLETIONPENDING;
141 } 141 }
142 142
143 int32_t PepperInternalFileRefBackend::Rename( 143 int32_t PepperInternalFileRefBackend::Rename(
144 ppapi::host::ReplyMessageContext reply_context, 144 ppapi::host::ReplyMessageContext reply_context,
145 PepperFileRefHost* new_file_ref) { 145 PepperFileRefHost* new_file_ref) {
146 if (!GetFileSystemURL().is_valid()) 146 if (!GetFileSystemURL().is_valid())
147 return PP_ERROR_FAILED; 147 return PP_ERROR_FAILED;
148 148
149 fileapi::FileSystemURL new_url = new_file_ref->GetFileSystemURL(); 149 storage::FileSystemURL new_url = new_file_ref->GetFileSystemURL();
150 if (!new_url.is_valid()) 150 if (!new_url.is_valid())
151 return PP_ERROR_FAILED; 151 return PP_ERROR_FAILED;
152 if (!new_url.IsInSameFileSystem(GetFileSystemURL())) 152 if (!new_url.IsInSameFileSystem(GetFileSystemURL()))
153 return PP_ERROR_FAILED; 153 return PP_ERROR_FAILED;
154 154
155 GetFileSystemContext()->operation_runner()->Move( 155 GetFileSystemContext()->operation_runner()->Move(
156 GetFileSystemURL(), 156 GetFileSystemURL(),
157 new_url, 157 new_url,
158 fileapi::FileSystemOperation::OPTION_NONE, 158 storage::FileSystemOperation::OPTION_NONE,
159 base::Bind(&PepperInternalFileRefBackend::DidFinish, 159 base::Bind(&PepperInternalFileRefBackend::DidFinish,
160 weak_factory_.GetWeakPtr(), 160 weak_factory_.GetWeakPtr(),
161 reply_context, 161 reply_context,
162 PpapiPluginMsg_FileRef_RenameReply())); 162 PpapiPluginMsg_FileRef_RenameReply()));
163 return PP_OK_COMPLETIONPENDING; 163 return PP_OK_COMPLETIONPENDING;
164 } 164 }
165 165
166 int32_t PepperInternalFileRefBackend::Query( 166 int32_t PepperInternalFileRefBackend::Query(
167 ppapi::host::ReplyMessageContext reply_context) { 167 ppapi::host::ReplyMessageContext reply_context) {
168 if (!GetFileSystemURL().is_valid()) 168 if (!GetFileSystemURL().is_valid())
(...skipping 21 matching lines...) Expand all
190 190
191 host_->SendReply(reply_context, 191 host_->SendReply(reply_context,
192 PpapiPluginMsg_FileRef_QueryReply(pp_file_info)); 192 PpapiPluginMsg_FileRef_QueryReply(pp_file_info));
193 } 193 }
194 194
195 int32_t PepperInternalFileRefBackend::ReadDirectoryEntries( 195 int32_t PepperInternalFileRefBackend::ReadDirectoryEntries(
196 ppapi::host::ReplyMessageContext reply_context) { 196 ppapi::host::ReplyMessageContext reply_context) {
197 if (!GetFileSystemURL().is_valid()) 197 if (!GetFileSystemURL().is_valid())
198 return PP_ERROR_FAILED; 198 return PP_ERROR_FAILED;
199 199
200 fileapi::FileSystemOperation::FileEntryList* accumulated_file_list = 200 storage::FileSystemOperation::FileEntryList* accumulated_file_list =
201 new fileapi::FileSystemOperation::FileEntryList; 201 new storage::FileSystemOperation::FileEntryList;
202 GetFileSystemContext()->operation_runner()->ReadDirectory( 202 GetFileSystemContext()->operation_runner()->ReadDirectory(
203 GetFileSystemURL(), 203 GetFileSystemURL(),
204 base::Bind(&PepperInternalFileRefBackend::ReadDirectoryComplete, 204 base::Bind(&PepperInternalFileRefBackend::ReadDirectoryComplete,
205 weak_factory_.GetWeakPtr(), 205 weak_factory_.GetWeakPtr(),
206 reply_context, 206 reply_context,
207 base::Owned(accumulated_file_list))); 207 base::Owned(accumulated_file_list)));
208 return PP_OK_COMPLETIONPENDING; 208 return PP_OK_COMPLETIONPENDING;
209 } 209 }
210 210
211 void PepperInternalFileRefBackend::ReadDirectoryComplete( 211 void PepperInternalFileRefBackend::ReadDirectoryComplete(
212 ppapi::host::ReplyMessageContext context, 212 ppapi::host::ReplyMessageContext context,
213 fileapi::FileSystemOperation::FileEntryList* accumulated_file_list, 213 storage::FileSystemOperation::FileEntryList* accumulated_file_list,
214 base::File::Error error, 214 base::File::Error error,
215 const fileapi::FileSystemOperation::FileEntryList& file_list, 215 const storage::FileSystemOperation::FileEntryList& file_list,
216 bool has_more) { 216 bool has_more) {
217 accumulated_file_list->insert( 217 accumulated_file_list->insert(
218 accumulated_file_list->end(), file_list.begin(), file_list.end()); 218 accumulated_file_list->end(), file_list.begin(), file_list.end());
219 if (has_more) 219 if (has_more)
220 return; 220 return;
221 221
222 context.params.set_result(ppapi::FileErrorToPepperError(error)); 222 context.params.set_result(ppapi::FileErrorToPepperError(error));
223 223
224 std::vector<ppapi::FileRefCreateInfo> infos; 224 std::vector<ppapi::FileRefCreateInfo> infos;
225 std::vector<PP_FileType> file_types; 225 std::vector<PP_FileType> file_types;
226 if (error == base::File::FILE_OK && fs_host_.get()) { 226 if (error == base::File::FILE_OK && fs_host_.get()) {
227 std::string dir_path = path_; 227 std::string dir_path = path_;
228 if (dir_path.empty() || dir_path[dir_path.size() - 1] != '/') 228 if (dir_path.empty() || dir_path[dir_path.size() - 1] != '/')
229 dir_path += '/'; 229 dir_path += '/';
230 230
231 for (fileapi::FileSystemOperation::FileEntryList::const_iterator it = 231 for (storage::FileSystemOperation::FileEntryList::const_iterator it =
232 accumulated_file_list->begin(); 232 accumulated_file_list->begin();
233 it != accumulated_file_list->end(); 233 it != accumulated_file_list->end();
234 ++it) { 234 ++it) {
235 if (it->is_directory) 235 if (it->is_directory)
236 file_types.push_back(PP_FILETYPE_DIRECTORY); 236 file_types.push_back(PP_FILETYPE_DIRECTORY);
237 else 237 else
238 file_types.push_back(PP_FILETYPE_REGULAR); 238 file_types.push_back(PP_FILETYPE_REGULAR);
239 239
240 ppapi::FileRefCreateInfo info; 240 ppapi::FileRefCreateInfo info;
241 info.file_system_type = fs_type_; 241 info.file_system_type = fs_type_;
242 info.file_system_plugin_resource = fs_host_->pp_resource(); 242 info.file_system_plugin_resource = fs_host_->pp_resource();
243 std::string path = 243 std::string path =
244 dir_path + fileapi::FilePathToString(base::FilePath(it->name)); 244 dir_path + storage::FilePathToString(base::FilePath(it->name));
245 info.internal_path = path; 245 info.internal_path = path;
246 info.display_name = ppapi::GetNameForInternalFilePath(path); 246 info.display_name = ppapi::GetNameForInternalFilePath(path);
247 infos.push_back(info); 247 infos.push_back(info);
248 } 248 }
249 } 249 }
250 250
251 host_->SendReply( 251 host_->SendReply(
252 context, 252 context,
253 PpapiPluginMsg_FileRef_ReadDirectoryEntriesReply(infos, file_types)); 253 PpapiPluginMsg_FileRef_ReadDirectoryEntriesReply(infos, file_types));
254 } 254 }
255 255
256 int32_t PepperInternalFileRefBackend::GetAbsolutePath( 256 int32_t PepperInternalFileRefBackend::GetAbsolutePath(
257 ppapi::host::ReplyMessageContext reply_context) { 257 ppapi::host::ReplyMessageContext reply_context) {
258 host_->SendReply(reply_context, 258 host_->SendReply(reply_context,
259 PpapiPluginMsg_FileRef_GetAbsolutePathReply(path_)); 259 PpapiPluginMsg_FileRef_GetAbsolutePathReply(path_));
260 return PP_OK_COMPLETIONPENDING; 260 return PP_OK_COMPLETIONPENDING;
261 } 261 }
262 262
263 int32_t PepperInternalFileRefBackend::CanRead() const { 263 int32_t PepperInternalFileRefBackend::CanRead() const {
264 fileapi::FileSystemURL url = GetFileSystemURL(); 264 storage::FileSystemURL url = GetFileSystemURL();
265 if (!FileSystemURLIsValid(GetFileSystemContext().get(), url)) 265 if (!FileSystemURLIsValid(GetFileSystemContext().get(), url))
266 return PP_ERROR_FAILED; 266 return PP_ERROR_FAILED;
267 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFileSystemFile( 267 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanReadFileSystemFile(
268 render_process_id_, url)) { 268 render_process_id_, url)) {
269 return PP_ERROR_NOACCESS; 269 return PP_ERROR_NOACCESS;
270 } 270 }
271 return PP_OK; 271 return PP_OK;
272 } 272 }
273 273
274 int32_t PepperInternalFileRefBackend::CanWrite() const { 274 int32_t PepperInternalFileRefBackend::CanWrite() const {
275 fileapi::FileSystemURL url = GetFileSystemURL(); 275 storage::FileSystemURL url = GetFileSystemURL();
276 if (!FileSystemURLIsValid(GetFileSystemContext().get(), url)) 276 if (!FileSystemURLIsValid(GetFileSystemContext().get(), url))
277 return PP_ERROR_FAILED; 277 return PP_ERROR_FAILED;
278 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanWriteFileSystemFile( 278 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanWriteFileSystemFile(
279 render_process_id_, url)) { 279 render_process_id_, url)) {
280 return PP_ERROR_NOACCESS; 280 return PP_ERROR_NOACCESS;
281 } 281 }
282 return PP_OK; 282 return PP_OK;
283 } 283 }
284 284
285 int32_t PepperInternalFileRefBackend::CanCreate() const { 285 int32_t PepperInternalFileRefBackend::CanCreate() const {
286 fileapi::FileSystemURL url = GetFileSystemURL(); 286 storage::FileSystemURL url = GetFileSystemURL();
287 if (!FileSystemURLIsValid(GetFileSystemContext().get(), url)) 287 if (!FileSystemURLIsValid(GetFileSystemContext().get(), url))
288 return PP_ERROR_FAILED; 288 return PP_ERROR_FAILED;
289 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanCreateFileSystemFile( 289 if (!ChildProcessSecurityPolicyImpl::GetInstance()->CanCreateFileSystemFile(
290 render_process_id_, url)) { 290 render_process_id_, url)) {
291 return PP_ERROR_NOACCESS; 291 return PP_ERROR_NOACCESS;
292 } 292 }
293 return PP_OK; 293 return PP_OK;
294 } 294 }
295 295
296 int32_t PepperInternalFileRefBackend::CanReadWrite() const { 296 int32_t PepperInternalFileRefBackend::CanReadWrite() const {
297 fileapi::FileSystemURL url = GetFileSystemURL(); 297 storage::FileSystemURL url = GetFileSystemURL();
298 if (!FileSystemURLIsValid(GetFileSystemContext().get(), url)) 298 if (!FileSystemURLIsValid(GetFileSystemContext().get(), url))
299 return PP_ERROR_FAILED; 299 return PP_ERROR_FAILED;
300 ChildProcessSecurityPolicyImpl* policy = 300 ChildProcessSecurityPolicyImpl* policy =
301 ChildProcessSecurityPolicyImpl::GetInstance(); 301 ChildProcessSecurityPolicyImpl::GetInstance();
302 if (!policy->CanReadFileSystemFile(render_process_id_, url) || 302 if (!policy->CanReadFileSystemFile(render_process_id_, url) ||
303 !policy->CanWriteFileSystemFile(render_process_id_, url)) { 303 !policy->CanWriteFileSystemFile(render_process_id_, url)) {
304 return PP_ERROR_NOACCESS; 304 return PP_ERROR_NOACCESS;
305 } 305 }
306 return PP_OK; 306 return PP_OK;
307 } 307 }
308 308
309 } // namespace content 309 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698