OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_FILE_STREAM_WRITER_
H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_FILE_STREAM_WRITER_
H_ |
6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_FILE_STREAM_WRITER_
H_ | 6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_FILE_STREAM_WRITER_
H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 virtual int Cancel(const net::CompletionCallback& callback) override; | 33 virtual int Cancel(const net::CompletionCallback& callback) override; |
34 virtual int Flush(const net::CompletionCallback& callback) override; | 34 virtual int Flush(const net::CompletionCallback& callback) override; |
35 | 35 |
36 private: | 36 private: |
37 // Helper class for executing operations on the provided file system. All | 37 // Helper class for executing operations on the provided file system. All |
38 // of its methods must be called on UI thread. Callbacks are called on IO | 38 // of its methods must be called on UI thread. Callbacks are called on IO |
39 // thread. | 39 // thread. |
40 class OperationRunner; | 40 class OperationRunner; |
41 | 41 |
42 // State of the file stream writer. | 42 // State of the file stream writer. |
43 enum State { NOT_INITIALIZED, INITIALIZING, INITIALIZED, FAILED }; | 43 enum State { NOT_INITIALIZED, INITIALIZING, INITIALIZED, EXECUTING, FAILED }; |
44 | 44 |
45 // Called when OperationRunner::WriteOnUIThread is completed. | 45 // Called when OperationRunner::WriteOnUIThread is completed. |
46 void OnWriteFileCompleted(int buffer_length, | 46 void OnWriteFileCompleted(int buffer_length, |
47 const net::CompletionCallback& callback, | 47 const net::CompletionCallback& callback, |
48 base::File::Error result); | 48 base::File::Error result); |
49 | 49 |
50 // Called when Write() operation is completed with either a success or an | 50 // Called when Write() operation is completed with either a success or an |
51 // error. | 51 // error. |
52 void OnWriteCompleted(net::CompletionCallback callback, int result); | 52 void OnWriteCompleted(net::CompletionCallback callback, int result); |
53 | 53 |
54 // Called when Abort() operation is completed with either a success or an | |
55 // error. | |
56 void OnAbortCompleted(const net::CompletionCallback& callback, | |
57 base::File::Error result); | |
58 | |
59 // Initializes the writer by opening the file. When completed with success, | 54 // Initializes the writer by opening the file. When completed with success, |
60 // runs the |pending_closure|. Otherwise, calls the |error_callback|. | 55 // runs the |pending_closure|. Otherwise, calls the |error_callback|. |
61 void Initialize(const base::Closure& pending_closure, | 56 void Initialize(const base::Closure& pending_closure, |
62 const net::CompletionCallback& error_callback); | 57 const net::CompletionCallback& error_callback); |
63 | 58 |
64 // Called when opening a file is completed with either a success or an error. | 59 // Called when opening a file is completed with either a success or an error. |
65 void OnOpenFileCompleted( | 60 void OnOpenFileCompleted( |
66 const base::Closure& pending_closure, | 61 const base::Closure& pending_closure, |
67 const net::CompletionCallback& error_callback, | 62 const net::CompletionCallback& error_callback, |
68 base::File::Error result); | 63 base::File::Error result); |
69 | 64 |
70 // Same as Write(), but called after initializing is completed. | 65 // Same as Write(), but called after initializing is completed. |
71 void WriteAfterInitialized(scoped_refptr<net::IOBuffer> buffer, | 66 void WriteAfterInitialized(scoped_refptr<net::IOBuffer> buffer, |
72 int buffer_length, | 67 int buffer_length, |
73 const net::CompletionCallback& callback); | 68 const net::CompletionCallback& callback); |
74 | 69 |
75 storage::FileSystemURL url_; | 70 storage::FileSystemURL url_; |
76 int64 current_offset_; | 71 int64 current_offset_; |
77 scoped_refptr<OperationRunner> runner_; | 72 scoped_refptr<OperationRunner> runner_; |
78 State state_; | 73 State state_; |
79 | 74 |
80 base::WeakPtrFactory<FileStreamWriter> weak_ptr_factory_; | 75 base::WeakPtrFactory<FileStreamWriter> weak_ptr_factory_; |
81 DISALLOW_COPY_AND_ASSIGN(FileStreamWriter); | 76 DISALLOW_COPY_AND_ASSIGN(FileStreamWriter); |
82 }; | 77 }; |
83 | 78 |
84 } // namespace file_system_provider | 79 } // namespace file_system_provider |
85 } // namespace chromeos | 80 } // namespace chromeos |
86 | 81 |
87 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_FILE_STREAM_WRIT
ER_H_ | 82 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FILEAPI_FILE_STREAM_WRIT
ER_H_ |
OLD | NEW |