| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_writer_delegate.h" | 5 #include "webkit/browser/fileapi/file_writer_delegate.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/files/file_util_proxy.h" | 9 #include "base/files/file_util_proxy.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
| 12 #include "base/sequenced_task_runner.h" | 12 #include "base/sequenced_task_runner.h" |
| 13 #include "base/threading/thread_restrictions.h" | 13 #include "base/threading/thread_restrictions.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 #include "webkit/browser/fileapi/file_stream_writer.h" | 15 #include "webkit/browser/fileapi/file_stream_writer.h" |
| 16 #include "webkit/browser/fileapi/file_system_context.h" | 16 #include "webkit/browser/fileapi/file_system_context.h" |
| 17 #include "webkit/common/fileapi/file_system_util.h" |
| 17 | 18 |
| 18 namespace fileapi { | 19 namespace fileapi { |
| 19 | 20 |
| 20 static const int kReadBufSize = 32768; | 21 static const int kReadBufSize = 32768; |
| 21 | 22 |
| 22 namespace { | |
| 23 | |
| 24 base::PlatformFileError NetErrorToPlatformFileError(int error) { | |
| 25 // TODO(kinuko): Move this static method to more convenient place. | |
| 26 switch (error) { | |
| 27 case net::OK: | |
| 28 return base::PLATFORM_FILE_OK; | |
| 29 case net::ERR_FILE_NO_SPACE: | |
| 30 return base::PLATFORM_FILE_ERROR_NO_SPACE; | |
| 31 case net::ERR_FILE_NOT_FOUND: | |
| 32 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
| 33 case net::ERR_ACCESS_DENIED: | |
| 34 return base::PLATFORM_FILE_ERROR_ACCESS_DENIED; | |
| 35 default: | |
| 36 return base::PLATFORM_FILE_ERROR_FAILED; | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 } // namespace | |
| 41 | |
| 42 FileWriterDelegate::FileWriterDelegate( | 23 FileWriterDelegate::FileWriterDelegate( |
| 43 scoped_ptr<FileStreamWriter> file_stream_writer) | 24 scoped_ptr<FileStreamWriter> file_stream_writer) |
| 44 : file_stream_writer_(file_stream_writer.Pass()), | 25 : file_stream_writer_(file_stream_writer.Pass()), |
| 45 writing_started_(false), | 26 writing_started_(false), |
| 46 bytes_written_backlog_(0), | 27 bytes_written_backlog_(0), |
| 47 bytes_written_(0), | 28 bytes_written_(0), |
| 48 bytes_read_(0), | 29 bytes_read_(0), |
| 49 io_buffer_(new net::IOBufferWithSize(kReadBufSize)), | 30 io_buffer_(new net::IOBufferWithSize(kReadBufSize)), |
| 50 weak_factory_(this) { | 31 weak_factory_(this) { |
| 51 } | 32 } |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 if (error == base::PLATFORM_FILE_OK && flush_error != net::OK) { | 226 if (error == base::PLATFORM_FILE_OK && flush_error != net::OK) { |
| 246 // If the Flush introduced an error, overwrite the status. | 227 // If the Flush introduced an error, overwrite the status. |
| 247 // Otherwise, keep the original error status. | 228 // Otherwise, keep the original error status. |
| 248 error = NetErrorToPlatformFileError(flush_error); | 229 error = NetErrorToPlatformFileError(flush_error); |
| 249 progress_status = GetCompletionStatusOnError(); | 230 progress_status = GetCompletionStatusOnError(); |
| 250 } | 231 } |
| 251 write_callback_.Run(error, bytes_written, progress_status); | 232 write_callback_.Run(error, bytes_written, progress_status); |
| 252 } | 233 } |
| 253 | 234 |
| 254 } // namespace fileapi | 235 } // namespace fileapi |
| OLD | NEW |