| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/file_system_provider/fileapi/file_stream_write
r.h" | 5 #include "chrome/browser/chromeos/file_system_provider/fileapi/file_stream_write
r.h" |
| 6 | 6 |
| 7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi
le_util.h" | 9 #include "chrome/browser/chromeos/file_system_provider/fileapi/provider_async_fi
le_util.h" |
| 10 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" | 10 #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" |
| 11 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" | 11 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_inte
rface.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 | 15 |
| 16 using content::BrowserThread; | 16 using content::BrowserThread; |
| 17 | 17 |
| 18 namespace chromeos { | 18 namespace chromeos { |
| 19 namespace file_system_provider { | 19 namespace file_system_provider { |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 // Dicards the callback from CloseFile(). | 22 // Dicards the callback from CloseFile(). |
| 23 void EmptyStatusCallback(base::File::Error /* result */) { | 23 void EmptyStatusCallback(base::File::Error /* result */) { |
| 24 } | 24 } |
| 25 | 25 |
| 26 // Opens a file for writing and calls the completion callback. Must be called | 26 // Opens a file for writing and calls the completion callback. Must be called |
| 27 // on UI thread. | 27 // on UI thread. |
| 28 void OpenFileOnUIThread( | 28 void OpenFileOnUIThread( |
| 29 const fileapi::FileSystemURL& url, | 29 const storage::FileSystemURL& url, |
| 30 const FileStreamWriter::OpenFileCompletedCallback& callback) { | 30 const FileStreamWriter::OpenFileCompletedCallback& callback) { |
| 31 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 31 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 32 | 32 |
| 33 util::FileSystemURLParser parser(url); | 33 util::FileSystemURLParser parser(url); |
| 34 if (!parser.Parse()) { | 34 if (!parser.Parse()) { |
| 35 callback.Run(base::WeakPtr<ProvidedFileSystemInterface>(), | 35 callback.Run(base::WeakPtr<ProvidedFileSystemInterface>(), |
| 36 base::FilePath(), | 36 base::FilePath(), |
| 37 0 /* file_handle */, | 37 0 /* file_handle */, |
| 38 base::File::FILE_ERROR_SECURITY); | 38 base::File::FILE_ERROR_SECURITY); |
| 39 return; | 39 return; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 70 } | 70 } |
| 71 | 71 |
| 72 // Requests writing bytes to the file. In case of either success or a failure | 72 // Requests writing bytes to the file. In case of either success or a failure |
| 73 // |callback| is executed. Must be called on UI thread. | 73 // |callback| is executed. Must be called on UI thread. |
| 74 void WriteFileOnUIThread( | 74 void WriteFileOnUIThread( |
| 75 base::WeakPtr<ProvidedFileSystemInterface> file_system, | 75 base::WeakPtr<ProvidedFileSystemInterface> file_system, |
| 76 int file_handle, | 76 int file_handle, |
| 77 scoped_refptr<net::IOBuffer> buffer, | 77 scoped_refptr<net::IOBuffer> buffer, |
| 78 int64 offset, | 78 int64 offset, |
| 79 int length, | 79 int length, |
| 80 const fileapi::AsyncFileUtil::StatusCallback& callback) { | 80 const storage::AsyncFileUtil::StatusCallback& callback) { |
| 81 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 81 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 82 | 82 |
| 83 // If the file system got unmounted, then abort the writing operation. | 83 // If the file system got unmounted, then abort the writing operation. |
| 84 if (!file_system.get()) { | 84 if (!file_system.get()) { |
| 85 callback.Run(base::File::FILE_ERROR_ABORT); | 85 callback.Run(base::File::FILE_ERROR_ABORT); |
| 86 return; | 86 return; |
| 87 } | 87 } |
| 88 | 88 |
| 89 file_system->WriteFile(file_handle, buffer, offset, length, callback); | 89 file_system->WriteFile(file_handle, buffer, offset, length, callback); |
| 90 } | 90 } |
| 91 | 91 |
| 92 // Forward the completion callback to IO thread. | 92 // Forward the completion callback to IO thread. |
| 93 void OnWriteFileCompletedOnUIThread( | 93 void OnWriteFileCompletedOnUIThread( |
| 94 const fileapi::AsyncFileUtil::StatusCallback& callback, | 94 const storage::AsyncFileUtil::StatusCallback& callback, |
| 95 base::File::Error result) { | 95 base::File::Error result) { |
| 96 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 96 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 97 BrowserThread::PostTask( | 97 BrowserThread::PostTask( |
| 98 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); | 98 BrowserThread::IO, FROM_HERE, base::Bind(callback, result)); |
| 99 } | 99 } |
| 100 | 100 |
| 101 } // namespace | 101 } // namespace |
| 102 | 102 |
| 103 FileStreamWriter::FileStreamWriter(const fileapi::FileSystemURL& url, | 103 FileStreamWriter::FileStreamWriter(const storage::FileSystemURL& url, |
| 104 int64 initial_offset) | 104 int64 initial_offset) |
| 105 : url_(url), | 105 : url_(url), |
| 106 current_offset_(initial_offset), | 106 current_offset_(initial_offset), |
| 107 state_(NOT_INITIALIZED), | 107 state_(NOT_INITIALIZED), |
| 108 file_handle_(0), | 108 file_handle_(0), |
| 109 weak_ptr_factory_(this) { | 109 weak_ptr_factory_(this) { |
| 110 } | 110 } |
| 111 | 111 |
| 112 FileStreamWriter::~FileStreamWriter() { | 112 FileStreamWriter::~FileStreamWriter() { |
| 113 BrowserThread::PostTask( | 113 BrowserThread::PostTask( |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 buffer_length, | 263 buffer_length, |
| 264 base::Bind(&OnWriteFileCompletedOnUIThread, | 264 base::Bind(&OnWriteFileCompletedOnUIThread, |
| 265 base::Bind(&FileStreamWriter::OnWriteFileCompleted, | 265 base::Bind(&FileStreamWriter::OnWriteFileCompleted, |
| 266 weak_ptr_factory_.GetWeakPtr(), | 266 weak_ptr_factory_.GetWeakPtr(), |
| 267 buffer_length, | 267 buffer_length, |
| 268 callback)))); | 268 callback)))); |
| 269 } | 269 } |
| 270 | 270 |
| 271 } // namespace file_system_provider | 271 } // namespace file_system_provider |
| 272 } // namespace chromeos | 272 } // namespace chromeos |
| OLD | NEW |