| 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/local_file_stream_writer.h" | 5 #include "webkit/browser/fileapi/local_file_stream_writer.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "net/base/file_stream.h" | 9 #include "net/base/file_stream.h" |
| 10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
| 11 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 12 | 12 |
| 13 namespace fileapi { | 13 namespace fileapi { |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 const int kOpenFlagsForWrite = base::PLATFORM_FILE_OPEN | | 17 const int kOpenFlagsForWrite = base::PLATFORM_FILE_OPEN | |
| 18 base::PLATFORM_FILE_WRITE | | 18 base::PLATFORM_FILE_WRITE | |
| 19 base::PLATFORM_FILE_ASYNC; | 19 base::PLATFORM_FILE_ASYNC; |
| 20 const int kCreateFlagsForWrite = base::PLATFORM_FILE_CREATE | |
| 21 base::PLATFORM_FILE_WRITE | |
| 22 base::PLATFORM_FILE_ASYNC; |
| 20 | 23 |
| 21 } // namespace | 24 } // namespace |
| 22 | 25 |
| 23 LocalFileStreamWriter::LocalFileStreamWriter(base::TaskRunner* task_runner, | 26 LocalFileStreamWriter::LocalFileStreamWriter(base::TaskRunner* task_runner, |
| 24 const base::FilePath& file_path, | 27 const base::FilePath& file_path, |
| 25 int64 initial_offset) | 28 int64 initial_offset, |
| 29 bool open_not_create) |
| 26 : file_path_(file_path), | 30 : file_path_(file_path), |
| 31 open_not_create_(open_not_create), |
| 27 initial_offset_(initial_offset), | 32 initial_offset_(initial_offset), |
| 28 has_pending_operation_(false), | 33 has_pending_operation_(false), |
| 29 weak_factory_(this), | 34 weak_factory_(this), |
| 30 task_runner_(task_runner) {} | 35 task_runner_(task_runner) {} |
| 31 | 36 |
| 32 LocalFileStreamWriter::~LocalFileStreamWriter() { | 37 LocalFileStreamWriter::~LocalFileStreamWriter() { |
| 33 // Invalidate weak pointers so that we won't receive any callbacks from | 38 // Invalidate weak pointers so that we won't receive any callbacks from |
| 34 // in-flight stream operations, which might be triggered during the file close | 39 // in-flight stream operations, which might be triggered during the file close |
| 35 // in the FileStream destructor. | 40 // in the FileStream destructor. |
| 36 weak_factory_.InvalidateWeakPtrs(); | 41 weak_factory_.InvalidateWeakPtrs(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 88 |
| 84 int LocalFileStreamWriter::InitiateOpen( | 89 int LocalFileStreamWriter::InitiateOpen( |
| 85 const net::CompletionCallback& error_callback, | 90 const net::CompletionCallback& error_callback, |
| 86 const base::Closure& main_operation) { | 91 const base::Closure& main_operation) { |
| 87 DCHECK(has_pending_operation_); | 92 DCHECK(has_pending_operation_); |
| 88 DCHECK(!stream_impl_.get()); | 93 DCHECK(!stream_impl_.get()); |
| 89 | 94 |
| 90 stream_impl_.reset(new net::FileStream(NULL, task_runner_)); | 95 stream_impl_.reset(new net::FileStream(NULL, task_runner_)); |
| 91 | 96 |
| 92 return stream_impl_->Open(file_path_, | 97 return stream_impl_->Open(file_path_, |
| 93 kOpenFlagsForWrite, | 98 open_not_create_ ? kOpenFlagsForWrite : |
| 99 kCreateFlagsForWrite, |
| 94 base::Bind(&LocalFileStreamWriter::DidOpen, | 100 base::Bind(&LocalFileStreamWriter::DidOpen, |
| 95 weak_factory_.GetWeakPtr(), | 101 weak_factory_.GetWeakPtr(), |
| 96 error_callback, | 102 error_callback, |
| 97 main_operation)); | 103 main_operation)); |
| 98 } | 104 } |
| 99 | 105 |
| 100 void LocalFileStreamWriter::DidOpen( | 106 void LocalFileStreamWriter::DidOpen( |
| 101 const net::CompletionCallback& error_callback, | 107 const net::CompletionCallback& error_callback, |
| 102 const base::Closure& main_operation, | 108 const base::Closure& main_operation, |
| 103 int result) { | 109 int result) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 return false; | 230 return false; |
| 225 | 231 |
| 226 net::CompletionCallback pending_cancel = cancel_callback_; | 232 net::CompletionCallback pending_cancel = cancel_callback_; |
| 227 has_pending_operation_ = false; | 233 has_pending_operation_ = false; |
| 228 cancel_callback_.Reset(); | 234 cancel_callback_.Reset(); |
| 229 pending_cancel.Run(net::OK); | 235 pending_cancel.Run(net::OK); |
| 230 return true; | 236 return true; |
| 231 } | 237 } |
| 232 | 238 |
| 233 } // namespace fileapi | 239 } // namespace fileapi |
| OLD | NEW |