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 "webkit/browser/fileapi/file_system_operation_runner.h" | 5 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "net/url_request/url_request_context.h" | 8 #include "net/url_request/url_request_context.h" |
| 9 #include "webkit/browser/blob/blob_url_request_job_factory.h" |
9 #include "webkit/browser/fileapi/file_observers.h" | 10 #include "webkit/browser/fileapi/file_observers.h" |
10 #include "webkit/browser/fileapi/file_stream_writer.h" | 11 #include "webkit/browser/fileapi/file_stream_writer.h" |
11 #include "webkit/browser/fileapi/file_system_context.h" | 12 #include "webkit/browser/fileapi/file_system_context.h" |
12 #include "webkit/browser/fileapi/file_system_operation_impl.h" | 13 #include "webkit/browser/fileapi/file_system_operation_impl.h" |
13 #include "webkit/browser/fileapi/file_writer_delegate.h" | 14 #include "webkit/browser/fileapi/file_writer_delegate.h" |
14 #include "webkit/common/blob/shareable_file_reference.h" | 15 #include "webkit/common/blob/shareable_file_reference.h" |
15 | 16 |
16 namespace fileapi { | 17 namespace fileapi { |
17 | 18 |
18 typedef FileSystemOperationRunner::OperationID OperationID; | 19 typedef FileSystemOperationRunner::OperationID OperationID; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 operation->Remove( | 201 operation->Remove( |
201 url, recursive, | 202 url, recursive, |
202 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), | 203 base::Bind(&FileSystemOperationRunner::DidFinish, AsWeakPtr(), |
203 id, callback)); | 204 id, callback)); |
204 return id; | 205 return id; |
205 } | 206 } |
206 | 207 |
207 OperationID FileSystemOperationRunner::Write( | 208 OperationID FileSystemOperationRunner::Write( |
208 const net::URLRequestContext* url_request_context, | 209 const net::URLRequestContext* url_request_context, |
209 const FileSystemURL& url, | 210 const FileSystemURL& url, |
210 const GURL& blob_url, | 211 scoped_ptr<webkit_blob::BlobDataHandle> blob, |
211 int64 offset, | 212 int64 offset, |
212 const WriteCallback& callback) { | 213 const WriteCallback& callback) { |
213 base::PlatformFileError error = base::PLATFORM_FILE_OK; | 214 base::PlatformFileError error = base::PLATFORM_FILE_OK; |
214 FileSystemOperation* operation = | 215 FileSystemOperation* operation = |
215 file_system_context_->CreateFileSystemOperation(url, &error); | 216 file_system_context_->CreateFileSystemOperation(url, &error); |
216 if (!operation) { | 217 if (!operation) { |
217 callback.Run(error, 0, true); | 218 callback.Run(error, 0, true); |
218 return kErrorOperationID; | 219 return kErrorOperationID; |
219 } | 220 } |
220 | 221 |
221 scoped_ptr<FileStreamWriter> writer( | 222 scoped_ptr<FileStreamWriter> writer( |
222 file_system_context_->CreateFileStreamWriter(url, offset)); | 223 file_system_context_->CreateFileStreamWriter(url, offset)); |
223 if (!writer) { | 224 if (!writer) { |
224 // Write is not supported. | 225 // Write is not supported. |
225 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, 0, true); | 226 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, 0, true); |
226 return kErrorOperationID; | 227 return kErrorOperationID; |
227 } | 228 } |
228 | 229 |
229 DCHECK(blob_url.is_valid()); | |
230 scoped_ptr<FileWriterDelegate> writer_delegate( | 230 scoped_ptr<FileWriterDelegate> writer_delegate( |
231 new FileWriterDelegate(writer.Pass())); | 231 new FileWriterDelegate(writer.Pass())); |
232 scoped_ptr<net::URLRequest> blob_request(url_request_context->CreateRequest( | 232 |
233 blob_url, writer_delegate.get())); | 233 scoped_ptr<net::URLRequest> blob_request( |
| 234 webkit_blob::BlobProtocolHandler::CreateBlobRequest( |
| 235 blob.Pass(), |
| 236 url_request_context, |
| 237 writer_delegate.get())); |
234 | 238 |
235 OperationID id = operations_.Add(operation); | 239 OperationID id = operations_.Add(operation); |
236 PrepareForWrite(id, url); | 240 PrepareForWrite(id, url); |
237 operation->Write( | 241 operation->Write( |
238 url, writer_delegate.Pass(), blob_request.Pass(), | 242 url, writer_delegate.Pass(), blob_request.Pass(), |
239 base::Bind(&FileSystemOperationRunner::DidWrite, AsWeakPtr(), | 243 base::Bind(&FileSystemOperationRunner::DidWrite, AsWeakPtr(), |
240 id, callback)); | 244 id, callback)); |
241 return id; | 245 return id; |
242 } | 246 } |
243 | 247 |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 &FileUpdateObserver::OnEndUpdate, MakeTuple(*iter)); | 544 &FileUpdateObserver::OnEndUpdate, MakeTuple(*iter)); |
541 } | 545 } |
542 } | 546 } |
543 write_target_urls_.erase(found); | 547 write_target_urls_.erase(found); |
544 } | 548 } |
545 DCHECK(operations_.Lookup(id)); | 549 DCHECK(operations_.Lookup(id)); |
546 operations_.Remove(id); | 550 operations_.Remove(id); |
547 } | 551 } |
548 | 552 |
549 } // namespace fileapi | 553 } // namespace fileapi |
OLD | NEW |