| 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 #ifndef WEBKIT_FILEAPI_LOCAL_FILE_STREAM_WRITER_H_ | 5 #ifndef WEBKIT_FILEAPI_LOCAL_FILE_STREAM_WRITER_H_ |
| 6 #define WEBKIT_FILEAPI_LOCAL_FILE_STREAM_WRITER_H_ | 6 #define WEBKIT_FILEAPI_LOCAL_FILE_STREAM_WRITER_H_ |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 namespace fileapi { | 23 namespace fileapi { |
| 24 | 24 |
| 25 // This class is a thin wrapper around net::FileStream for writing local files. | 25 // This class is a thin wrapper around net::FileStream for writing local files. |
| 26 class FILEAPI_EXPORT_PRIVATE LocalFileStreamWriter : public FileStreamWriter { | 26 class FILEAPI_EXPORT_PRIVATE LocalFileStreamWriter : public FileStreamWriter { |
| 27 public: | 27 public: |
| 28 // Create a writer for the existing file in the path |file_path| starting from | 28 // Create a writer for the existing file in the path |file_path| starting from |
| 29 // |initial_offset|. | 29 // |initial_offset|. |
| 30 LocalFileStreamWriter(const FilePath& file_path, int64 initial_offset); | 30 LocalFileStreamWriter(const FilePath& file_path, int64 initial_offset); |
| 31 virtual ~LocalFileStreamWriter(); | 31 virtual ~LocalFileStreamWriter(); |
| 32 | 32 |
| 33 // FileStreamWriteroverrides. | 33 // FileStreamWriter overrides. |
| 34 virtual int Write(net::IOBuffer* buf, int buf_len, | 34 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 35 const net::CompletionCallback& callback) OVERRIDE; | 35 const net::CompletionCallback& callback) OVERRIDE; |
| 36 virtual int Cancel(const net::CompletionCallback& callback) OVERRIDE; | 36 virtual int Cancel(const net::CompletionCallback& callback) OVERRIDE; |
| 37 virtual int Flush(const net::CompletionCallback& callback) OVERRIDE; |
| 37 | 38 |
| 38 private: | 39 private: |
| 39 // Opens |file_path_| and if it succeeds, proceeds to InitiateSeek(). | 40 // Opens |file_path_| and if it succeeds, proceeds to InitiateSeek(). |
| 40 // If failed, the error code is returned by calling |error_callback|. | 41 // If failed, the error code is returned by calling |error_callback|. |
| 41 int InitiateOpen(const net::CompletionCallback& error_callback, | 42 int InitiateOpen(const net::CompletionCallback& error_callback, |
| 42 const base::Closure& main_operation); | 43 const base::Closure& main_operation); |
| 43 void DidOpen(const net::CompletionCallback& error_callback, | 44 void DidOpen(const net::CompletionCallback& error_callback, |
| 44 const base::Closure& main_operation, | 45 const base::Closure& main_operation, |
| 45 int result); | 46 int result); |
| 46 | 47 |
| 47 // Seeks to |initial_offset_| and proceeds to |main_operation| if it succeeds. | 48 // Seeks to |initial_offset_| and proceeds to |main_operation| if it succeeds. |
| 48 // If failed, the error code is returned by calling |error_callback|. | 49 // If failed, the error code is returned by calling |error_callback|. |
| 49 void InitiateSeek(const net::CompletionCallback& error_callback, | 50 void InitiateSeek(const net::CompletionCallback& error_callback, |
| 50 const base::Closure& main_operation); | 51 const base::Closure& main_operation); |
| 51 void DidSeek(const net::CompletionCallback& error_callback, | 52 void DidSeek(const net::CompletionCallback& error_callback, |
| 52 const base::Closure& main_operation, | 53 const base::Closure& main_operation, |
| 53 int64 result); | 54 int64 result); |
| 54 | 55 |
| 55 // Passed as the |main_operation| of InitiateOpen() function. | 56 // Passed as the |main_operation| of InitiateOpen() function. |
| 56 void ReadyToWrite(net::IOBuffer* buf, int buf_len, | 57 void ReadyToWrite(net::IOBuffer* buf, int buf_len, |
| 57 const net::CompletionCallback& callback); | 58 const net::CompletionCallback& callback); |
| 58 | 59 |
| 59 // Writes asynchronously to the file. | 60 // Writes asynchronously to the file. |
| 60 int InitiateWrite(net::IOBuffer* buf, int buf_len, | 61 int InitiateWrite(net::IOBuffer* buf, int buf_len, |
| 61 const net::CompletionCallback& callback); | 62 const net::CompletionCallback& callback); |
| 62 void DidWrite(const net::CompletionCallback& callback, int result); | 63 void DidWrite(const net::CompletionCallback& callback, int result); |
| 63 | 64 |
| 65 // Flushes asynchronously to the file. |
| 66 int InitiateFlush(const net::CompletionCallback& callback); |
| 67 void DidFlush(const net::CompletionCallback& callback, int result); |
| 68 |
| 64 // Stops the in-flight operation and calls |cancel_callback_| if it has been | 69 // Stops the in-flight operation and calls |cancel_callback_| if it has been |
| 65 // set by Cancel() for the current operation. | 70 // set by Cancel() for the current operation. |
| 66 bool CancelIfRequested(); | 71 bool CancelIfRequested(); |
| 67 | 72 |
| 68 // Initialization parameters. | 73 // Initialization parameters. |
| 69 const FilePath file_path_; | 74 const FilePath file_path_; |
| 70 const int64 initial_offset_; | 75 const int64 initial_offset_; |
| 71 | 76 |
| 72 // Current states of the operation. | 77 // Current states of the operation. |
| 73 bool has_pending_operation_; | 78 bool has_pending_operation_; |
| 74 scoped_ptr<net::FileStream> stream_impl_; | 79 scoped_ptr<net::FileStream> stream_impl_; |
| 75 net::CompletionCallback cancel_callback_; | 80 net::CompletionCallback cancel_callback_; |
| 76 | 81 |
| 77 base::WeakPtrFactory<LocalFileStreamWriter> weak_factory_; | 82 base::WeakPtrFactory<LocalFileStreamWriter> weak_factory_; |
| 78 DISALLOW_COPY_AND_ASSIGN(LocalFileStreamWriter); | 83 DISALLOW_COPY_AND_ASSIGN(LocalFileStreamWriter); |
| 79 }; | 84 }; |
| 80 | 85 |
| 81 } // namespace fileapi | 86 } // namespace fileapi |
| 82 | 87 |
| 83 #endif // WEBKIT_FILEAPI_LOCAL_FILE_STREAM_WRITER_H_ | 88 #endif // WEBKIT_FILEAPI_LOCAL_FILE_STREAM_WRITER_H_ |
| OLD | NEW |