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" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/task_runner.h" | 16 #include "base/task_runner.h" |
17 #include "webkit/browser/fileapi/file_stream_writer.h" | 17 #include "storage/browser/fileapi/file_stream_writer.h" |
18 #include "webkit/browser/webkit_storage_browser_export.h" | 18 #include "storage/common/storage_export.h" |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 class LocalFileStreamWriterTest; | 21 class LocalFileStreamWriterTest; |
22 } | 22 } |
23 | 23 |
24 namespace net { | 24 namespace net { |
25 class FileStream; | 25 class FileStream; |
26 } | 26 } |
27 | 27 |
28 namespace fileapi { | 28 namespace storage { |
29 | 29 |
30 // This class is a thin wrapper around net::FileStream for writing local files. | 30 // This class is a thin wrapper around net::FileStream for writing local files. |
31 class WEBKIT_STORAGE_BROWSER_EXPORT LocalFileStreamWriter | 31 class STORAGE_EXPORT LocalFileStreamWriter |
32 : public NON_EXPORTED_BASE(FileStreamWriter) { | 32 : public NON_EXPORTED_BASE(FileStreamWriter) { |
33 public: | 33 public: |
34 virtual ~LocalFileStreamWriter(); | 34 virtual ~LocalFileStreamWriter(); |
35 | 35 |
36 // FileStreamWriter overrides. | 36 // FileStreamWriter overrides. |
37 virtual int Write(net::IOBuffer* buf, int buf_len, | 37 virtual int Write(net::IOBuffer* buf, |
| 38 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 friend class content::LocalFileStreamWriterTest; | 44 friend class content::LocalFileStreamWriterTest; |
44 friend class FileStreamWriter; | 45 friend class FileStreamWriter; |
45 LocalFileStreamWriter(base::TaskRunner* task_runner, | 46 LocalFileStreamWriter(base::TaskRunner* task_runner, |
46 const base::FilePath& file_path, | 47 const base::FilePath& file_path, |
47 int64 initial_offset, | 48 int64 initial_offset, |
48 OpenOrCreate open_or_create); | 49 OpenOrCreate open_or_create); |
49 | 50 |
50 // Opens |file_path_| and if it succeeds, proceeds to InitiateSeek(). | 51 // Opens |file_path_| and if it succeeds, proceeds to InitiateSeek(). |
51 // If failed, the error code is returned by calling |error_callback|. | 52 // If failed, the error code is returned by calling |error_callback|. |
52 int InitiateOpen(const net::CompletionCallback& error_callback, | 53 int InitiateOpen(const net::CompletionCallback& error_callback, |
53 const base::Closure& main_operation); | 54 const base::Closure& main_operation); |
54 void DidOpen(const net::CompletionCallback& error_callback, | 55 void DidOpen(const net::CompletionCallback& error_callback, |
55 const base::Closure& main_operation, | 56 const base::Closure& main_operation, |
56 int result); | 57 int result); |
57 | 58 |
58 // Seeks to |initial_offset_| and proceeds to |main_operation| if it succeeds. | 59 // Seeks to |initial_offset_| and proceeds to |main_operation| if it succeeds. |
59 // If failed, the error code is returned by calling |error_callback|. | 60 // If failed, the error code is returned by calling |error_callback|. |
60 void InitiateSeek(const net::CompletionCallback& error_callback, | 61 void InitiateSeek(const net::CompletionCallback& error_callback, |
61 const base::Closure& main_operation); | 62 const base::Closure& main_operation); |
62 void DidSeek(const net::CompletionCallback& error_callback, | 63 void DidSeek(const net::CompletionCallback& error_callback, |
63 const base::Closure& main_operation, | 64 const base::Closure& main_operation, |
64 int64 result); | 65 int64 result); |
65 | 66 |
66 // Passed as the |main_operation| of InitiateOpen() function. | 67 // Passed as the |main_operation| of InitiateOpen() function. |
67 void ReadyToWrite(net::IOBuffer* buf, int buf_len, | 68 void ReadyToWrite(net::IOBuffer* buf, |
| 69 int buf_len, |
68 const net::CompletionCallback& callback); | 70 const net::CompletionCallback& callback); |
69 | 71 |
70 // Writes asynchronously to the file. | 72 // Writes asynchronously to the file. |
71 int InitiateWrite(net::IOBuffer* buf, int buf_len, | 73 int InitiateWrite(net::IOBuffer* buf, |
| 74 int buf_len, |
72 const net::CompletionCallback& callback); | 75 const net::CompletionCallback& callback); |
73 void DidWrite(const net::CompletionCallback& callback, int result); | 76 void DidWrite(const net::CompletionCallback& callback, int result); |
74 | 77 |
75 // Flushes asynchronously to the file. | 78 // Flushes asynchronously to the file. |
76 int InitiateFlush(const net::CompletionCallback& callback); | 79 int InitiateFlush(const net::CompletionCallback& callback); |
77 void DidFlush(const net::CompletionCallback& callback, int result); | 80 void DidFlush(const net::CompletionCallback& callback, int result); |
78 | 81 |
79 // Stops the in-flight operation and calls |cancel_callback_| if it has been | 82 // Stops the in-flight operation and calls |cancel_callback_| if it has been |
80 // set by Cancel() for the current operation. | 83 // set by Cancel() for the current operation. |
81 bool CancelIfRequested(); | 84 bool CancelIfRequested(); |
82 | 85 |
83 // Initialization parameters. | 86 // Initialization parameters. |
84 const base::FilePath file_path_; | 87 const base::FilePath file_path_; |
85 OpenOrCreate open_or_create_; | 88 OpenOrCreate open_or_create_; |
86 const int64 initial_offset_; | 89 const int64 initial_offset_; |
87 scoped_refptr<base::TaskRunner> task_runner_; | 90 scoped_refptr<base::TaskRunner> task_runner_; |
88 | 91 |
89 // Current states of the operation. | 92 // Current states of the operation. |
90 bool has_pending_operation_; | 93 bool has_pending_operation_; |
91 scoped_ptr<net::FileStream> stream_impl_; | 94 scoped_ptr<net::FileStream> stream_impl_; |
92 net::CompletionCallback cancel_callback_; | 95 net::CompletionCallback cancel_callback_; |
93 | 96 |
94 base::WeakPtrFactory<LocalFileStreamWriter> weak_factory_; | 97 base::WeakPtrFactory<LocalFileStreamWriter> weak_factory_; |
95 DISALLOW_COPY_AND_ASSIGN(LocalFileStreamWriter); | 98 DISALLOW_COPY_AND_ASSIGN(LocalFileStreamWriter); |
96 }; | 99 }; |
97 | 100 |
98 } // namespace fileapi | 101 } // namespace storage |
99 | 102 |
100 #endif // WEBKIT_BROWSER_FILEAPI_LOCAL_FILE_STREAM_WRITER_H_ | 103 #endif // WEBKIT_BROWSER_FILEAPI_LOCAL_FILE_STREAM_WRITER_H_ |
OLD | NEW |