| 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_BROWSER_FILEAPI_LOCAL_FILE_STREAM_WRITER_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_LOCAL_FILE_STREAM_WRITER_H_ |
| 6 #define WEBKIT_BROWSER_FILEAPI_LOCAL_FILE_STREAM_WRITER_H_ | 6 #define WEBKIT_BROWSER_FILEAPI_LOCAL_FILE_STREAM_WRITER_H_ |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 namespace fileapi { | 24 namespace fileapi { |
| 25 | 25 |
| 26 // This class is a thin wrapper around net::FileStream for writing local files. | 26 // This class is a thin wrapper around net::FileStream for writing local files. |
| 27 class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE LocalFileStreamWriter | 27 class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE LocalFileStreamWriter |
| 28 : public FileStreamWriter { | 28 : public FileStreamWriter { |
| 29 public: | 29 public: |
| 30 // Creates a writer for the existing file in the path |file_path| starting | 30 // Creates a writer for the existing file in the path |file_path| starting |
| 31 // from |initial_offset|. Uses |task_runner| for async file operations. | 31 // from |initial_offset|. Uses |task_runner| for async file operations. |
| 32 LocalFileStreamWriter(base::TaskRunner* task_runner, | 32 LocalFileStreamWriter(base::TaskRunner* task_runner, |
| 33 const base::FilePath& file_path, int64 initial_offset); | 33 const base::FilePath& file_path, int64 initial_offset, |
| 34 bool open_not_create); |
| 34 virtual ~LocalFileStreamWriter(); | 35 virtual ~LocalFileStreamWriter(); |
| 35 | 36 |
| 36 // FileStreamWriter overrides. | 37 // FileStreamWriter overrides. |
| 37 virtual int Write(net::IOBuffer* buf, int buf_len, | 38 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 38 const net::CompletionCallback& callback) OVERRIDE; | 39 const net::CompletionCallback& callback) OVERRIDE; |
| 39 virtual int Cancel(const net::CompletionCallback& callback) OVERRIDE; | 40 virtual int Cancel(const net::CompletionCallback& callback) OVERRIDE; |
| 40 virtual int Flush(const net::CompletionCallback& callback) OVERRIDE; | 41 virtual int Flush(const net::CompletionCallback& callback) OVERRIDE; |
| 41 | 42 |
| 42 private: | 43 private: |
| 43 // Opens |file_path_| and if it succeeds, proceeds to InitiateSeek(). | 44 // Opens |file_path_| and if it succeeds, proceeds to InitiateSeek(). |
| (...skipping 24 matching lines...) Expand all Loading... |
| 68 // Flushes asynchronously to the file. | 69 // Flushes asynchronously to the file. |
| 69 int InitiateFlush(const net::CompletionCallback& callback); | 70 int InitiateFlush(const net::CompletionCallback& callback); |
| 70 void DidFlush(const net::CompletionCallback& callback, int result); | 71 void DidFlush(const net::CompletionCallback& callback, int result); |
| 71 | 72 |
| 72 // Stops the in-flight operation and calls |cancel_callback_| if it has been | 73 // Stops the in-flight operation and calls |cancel_callback_| if it has been |
| 73 // set by Cancel() for the current operation. | 74 // set by Cancel() for the current operation. |
| 74 bool CancelIfRequested(); | 75 bool CancelIfRequested(); |
| 75 | 76 |
| 76 // Initialization parameters. | 77 // Initialization parameters. |
| 77 const base::FilePath file_path_; | 78 const base::FilePath file_path_; |
| 79 bool open_not_create_; |
| 78 const int64 initial_offset_; | 80 const int64 initial_offset_; |
| 79 scoped_refptr<base::TaskRunner> task_runner_; | 81 scoped_refptr<base::TaskRunner> task_runner_; |
| 80 | 82 |
| 81 // Current states of the operation. | 83 // Current states of the operation. |
| 82 bool has_pending_operation_; | 84 bool has_pending_operation_; |
| 83 scoped_ptr<net::FileStream> stream_impl_; | 85 scoped_ptr<net::FileStream> stream_impl_; |
| 84 net::CompletionCallback cancel_callback_; | 86 net::CompletionCallback cancel_callback_; |
| 85 | 87 |
| 86 base::WeakPtrFactory<LocalFileStreamWriter> weak_factory_; | 88 base::WeakPtrFactory<LocalFileStreamWriter> weak_factory_; |
| 87 DISALLOW_COPY_AND_ASSIGN(LocalFileStreamWriter); | 89 DISALLOW_COPY_AND_ASSIGN(LocalFileStreamWriter); |
| 88 }; | 90 }; |
| 89 | 91 |
| 90 } // namespace fileapi | 92 } // namespace fileapi |
| 91 | 93 |
| 92 #endif // WEBKIT_BROWSER_FILEAPI_LOCAL_FILE_STREAM_WRITER_H_ | 94 #endif // WEBKIT_BROWSER_FILEAPI_LOCAL_FILE_STREAM_WRITER_H_ |
| OLD | NEW |