OLD | NEW |
---|---|
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_file_io_host.h" | 5 #include "content/browser/renderer_host/pepper/pepper_file_io_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/files/file_util_proxy.h" | 10 #include "base/files/file_util_proxy.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 if (!host) | 71 if (!host) |
72 return false; | 72 return false; |
73 return client->IsPluginAllowedToCallRequestOSFileHandle( | 73 return client->IsPluginAllowedToCallRequestOSFileHandle( |
74 host->GetBrowserContext(), document_url); | 74 host->GetBrowserContext(), document_url); |
75 } | 75 } |
76 | 76 |
77 bool FileOpenForWrite(int32_t open_flags) { | 77 bool FileOpenForWrite(int32_t open_flags) { |
78 return (open_flags & (PP_FILEOPENFLAG_WRITE | PP_FILEOPENFLAG_APPEND)) != 0; | 78 return (open_flags & (PP_FILEOPENFLAG_WRITE | PP_FILEOPENFLAG_APPEND)) != 0; |
79 } | 79 } |
80 | 80 |
81 void FileCloser(base::File auto_close) { | |
82 } | |
83 | |
84 class OpenFileAdapter { | |
85 public: | |
86 OpenFileAdapter(PepperFileIOHost* file_host, | |
87 fileapi::FileSystemOperation::OpenFileCallback callback); | |
88 | |
89 void DidOpenFile(base::File file, | |
90 const base::Closure& on_close_callback); | |
91 private: | |
92 base::WeakPtr<PepperFileIOHost> file_host_; | |
93 fileapi::FileSystemOperation::OpenFileCallback callback_; | |
94 DISALLOW_COPY_AND_ASSIGN(OpenFileAdapter); | |
95 }; | |
96 | |
97 OpenFileAdapter::OpenFileAdapter( | |
98 PepperFileIOHost* file_host, | |
99 fileapi::FileSystemOperation::OpenFileCallback callback) | |
100 : file_host_(AsWeakPtr(file_host)), | |
101 callback_(callback) { | |
102 } | |
103 | |
104 void OpenFileAdapter::DidOpenFile(base::File file, | |
105 const base::Closure& on_close_callback) { | |
106 if (file_host_) { | |
107 callback_.Run(file.Pass(), on_close_callback); | |
108 } else { | |
109 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
110 base::Bind(&FileCloser, Passed(&file))); | |
bbudge
2014/06/03 18:21:53
Shouldn't we call 'on_close_callback' on this path
rvargas (doing something else)
2014/06/03 23:04:54
That is an interesting question.
FileSystemOperat
rvargas (doing something else)
2014/06/03 23:19:58
On second thought, now there is code to invoke the
| |
111 } | |
112 } | |
113 | |
81 } // namespace | 114 } // namespace |
82 | 115 |
83 PepperFileIOHost::PepperFileIOHost(BrowserPpapiHostImpl* host, | 116 PepperFileIOHost::PepperFileIOHost(BrowserPpapiHostImpl* host, |
84 PP_Instance instance, | 117 PP_Instance instance, |
85 PP_Resource resource) | 118 PP_Resource resource) |
86 : ResourceHost(host->GetPpapiHost(), instance, resource), | 119 : ResourceHost(host->GetPpapiHost(), instance, resource), |
87 browser_ppapi_host_(host), | 120 browser_ppapi_host_(host), |
88 render_process_host_(NULL), | 121 render_process_host_(NULL), |
89 file_(BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)), | 122 file_(BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)), |
90 open_flags_(0), | 123 open_flags_(0), |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 } | 253 } |
221 | 254 |
222 if (!file_system_context_->GetFileSystemBackend(file_system_url_.type())) { | 255 if (!file_system_context_->GetFileSystemBackend(file_system_url_.type())) { |
223 reply_context.params.set_result(PP_ERROR_FAILED); | 256 reply_context.params.set_result(PP_ERROR_FAILED); |
224 SendOpenErrorReply(reply_context); | 257 SendOpenErrorReply(reply_context); |
225 return; | 258 return; |
226 } | 259 } |
227 | 260 |
228 DCHECK(file_system_host_.get()); | 261 DCHECK(file_system_host_.get()); |
229 DCHECK(file_system_host_->GetFileSystemOperationRunner()); | 262 DCHECK(file_system_host_->GetFileSystemOperationRunner()); |
263 | |
264 OpenFileAdapter* open_adapter(new OpenFileAdapter( | |
265 this, | |
266 base::Bind(&PepperFileIOHost::DidOpenInternalFile, | |
267 weak_factory_.GetWeakPtr(), | |
268 reply_context))); | |
269 | |
230 file_system_host_->GetFileSystemOperationRunner()->OpenFile( | 270 file_system_host_->GetFileSystemOperationRunner()->OpenFile( |
231 file_system_url_, | 271 file_system_url_, |
232 platform_file_flags, | 272 platform_file_flags, |
233 base::Bind(&PepperFileIOHost::DidOpenInternalFile, | 273 base::Bind(&OpenFileAdapter::DidOpenFile, base::Owned(open_adapter))); |
bbudge
2014/06/03 18:21:53
Rather than define a new class, could you could de
rvargas (doing something else)
2014/06/03 23:04:54
Done.
| |
234 weak_factory_.GetWeakPtr(), | |
235 reply_context)); | |
236 } | 274 } |
237 | 275 |
238 void PepperFileIOHost::DidOpenInternalFile( | 276 void PepperFileIOHost::DidOpenInternalFile( |
239 ppapi::host::ReplyMessageContext reply_context, | 277 ppapi::host::ReplyMessageContext reply_context, |
240 base::File file, | 278 base::File file, |
241 const base::Closure& on_close_callback) { | 279 const base::Closure& on_close_callback) { |
242 if (file.IsValid()) { | 280 if (file.IsValid()) { |
243 on_close_callback_ = on_close_callback; | 281 on_close_callback_ = on_close_callback; |
244 | 282 |
245 if (FileOpenForWrite(open_flags_) && file_system_host_->ChecksQuota()) { | 283 if (FileOpenForWrite(open_flags_) && file_system_host_->ChecksQuota()) { |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 | 501 |
464 ppapi::proxy::SerializedHandle file_handle; | 502 ppapi::proxy::SerializedHandle file_handle; |
465 // A non-zero resource id signals NaClIPCAdapter to create a NaClQuotaDesc. | 503 // A non-zero resource id signals NaClIPCAdapter to create a NaClQuotaDesc. |
466 PP_Resource quota_file_io = check_quota_ ? pp_resource() : 0; | 504 PP_Resource quota_file_io = check_quota_ ? pp_resource() : 0; |
467 file_handle.set_file_handle(transit_file, open_flags, quota_file_io); | 505 file_handle.set_file_handle(transit_file, open_flags, quota_file_io); |
468 reply_context->params.AppendHandle(file_handle); | 506 reply_context->params.AppendHandle(file_handle); |
469 return true; | 507 return true; |
470 } | 508 } |
471 | 509 |
472 } // namespace content | 510 } // namespace content |
OLD | NEW |