OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_DRIVE_DRIVE_FILE_STREAM_READER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_FILE_STREAM_READER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_FILE_STREAM_READER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_FILE_STREAM_READER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
| 10 #include <memory> |
10 #include <string> | 11 #include <string> |
11 | 12 |
12 #include "base/callback.h" | 13 #include "base/callback.h" |
13 #include "base/macros.h" | 14 #include "base/macros.h" |
14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | |
16 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
17 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
18 #include "components/drive/file_errors.h" | 18 #include "components/drive/file_errors.h" |
19 #include "google_apis/drive/drive_api_error_codes.h" | 19 #include "google_apis/drive/drive_api_error_codes.h" |
20 #include "net/base/completion_callback.h" | 20 #include "net/base/completion_callback.h" |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 class SequencedTaskRunner; | 23 class SequencedTaskRunner; |
24 } // namespace base | 24 } // namespace base |
25 | 25 |
(...skipping 14 matching lines...) Expand all Loading... |
40 // file is being downloaded from the server), NetworkReaderProxy will be used. | 40 // file is being downloaded from the server), NetworkReaderProxy will be used. |
41 class ReaderProxy { | 41 class ReaderProxy { |
42 public: | 42 public: |
43 virtual ~ReaderProxy() {} | 43 virtual ~ReaderProxy() {} |
44 | 44 |
45 // Called from DriveFileStreamReader::Read method. | 45 // Called from DriveFileStreamReader::Read method. |
46 virtual int Read(net::IOBuffer* buffer, int buffer_length, | 46 virtual int Read(net::IOBuffer* buffer, int buffer_length, |
47 const net::CompletionCallback& callback) = 0; | 47 const net::CompletionCallback& callback) = 0; |
48 | 48 |
49 // Called when the data from the server is received. | 49 // Called when the data from the server is received. |
50 virtual void OnGetContent(scoped_ptr<std::string> data) = 0; | 50 virtual void OnGetContent(std::unique_ptr<std::string> data) = 0; |
51 | 51 |
52 // Called when the accessing to the file system is completed. | 52 // Called when the accessing to the file system is completed. |
53 virtual void OnCompleted(FileError error) = 0; | 53 virtual void OnCompleted(FileError error) = 0; |
54 }; | 54 }; |
55 | 55 |
56 // The read operation implementation for the locally cached files. | 56 // The read operation implementation for the locally cached files. |
57 class LocalReaderProxy : public ReaderProxy { | 57 class LocalReaderProxy : public ReaderProxy { |
58 public: | 58 public: |
59 // The |file_reader| should be the instance which is already opened. | 59 // The |file_reader| should be the instance which is already opened. |
60 // This class takes its ownership. | 60 // This class takes its ownership. |
61 // |length| is the number of bytes to be read. It must be equal or | 61 // |length| is the number of bytes to be read. It must be equal or |
62 // smaller than the remaining data size in the |file_reader|. | 62 // smaller than the remaining data size in the |file_reader|. |
63 LocalReaderProxy(scoped_ptr<util::LocalFileReader> file_reader, | 63 LocalReaderProxy(std::unique_ptr<util::LocalFileReader> file_reader, |
64 int64_t length); | 64 int64_t length); |
65 ~LocalReaderProxy() override; | 65 ~LocalReaderProxy() override; |
66 | 66 |
67 // ReaderProxy overrides. | 67 // ReaderProxy overrides. |
68 int Read(net::IOBuffer* buffer, | 68 int Read(net::IOBuffer* buffer, |
69 int buffer_length, | 69 int buffer_length, |
70 const net::CompletionCallback& callback) override; | 70 const net::CompletionCallback& callback) override; |
71 void OnGetContent(scoped_ptr<std::string> data) override; | 71 void OnGetContent(std::unique_ptr<std::string> data) override; |
72 void OnCompleted(FileError error) override; | 72 void OnCompleted(FileError error) override; |
73 | 73 |
74 private: | 74 private: |
75 scoped_ptr<util::LocalFileReader> file_reader_; | 75 std::unique_ptr<util::LocalFileReader> file_reader_; |
76 | 76 |
77 // Callback for the LocalFileReader::Read. | 77 // Callback for the LocalFileReader::Read. |
78 void OnReadCompleted( | 78 void OnReadCompleted( |
79 const net::CompletionCallback& callback, int read_result); | 79 const net::CompletionCallback& callback, int read_result); |
80 | 80 |
81 // The number of remaining bytes to be read. | 81 // The number of remaining bytes to be read. |
82 int64_t remaining_length_; | 82 int64_t remaining_length_; |
83 | 83 |
84 base::ThreadChecker thread_checker_; | 84 base::ThreadChecker thread_checker_; |
85 | 85 |
(...skipping 13 matching lines...) Expand all Loading... |
99 NetworkReaderProxy(int64_t offset, | 99 NetworkReaderProxy(int64_t offset, |
100 int64_t content_length, | 100 int64_t content_length, |
101 int64_t full_content_length, | 101 int64_t full_content_length, |
102 const base::Closure& job_canceller); | 102 const base::Closure& job_canceller); |
103 ~NetworkReaderProxy() override; | 103 ~NetworkReaderProxy() override; |
104 | 104 |
105 // ReaderProxy overrides. | 105 // ReaderProxy overrides. |
106 int Read(net::IOBuffer* buffer, | 106 int Read(net::IOBuffer* buffer, |
107 int buffer_length, | 107 int buffer_length, |
108 const net::CompletionCallback& callback) override; | 108 const net::CompletionCallback& callback) override; |
109 void OnGetContent(scoped_ptr<std::string> data) override; | 109 void OnGetContent(std::unique_ptr<std::string> data) override; |
110 void OnCompleted(FileError error) override; | 110 void OnCompleted(FileError error) override; |
111 | 111 |
112 private: | 112 private: |
113 // The data received from the server, but not yet read. | 113 // The data received from the server, but not yet read. |
114 ScopedVector<std::string> pending_data_; | 114 ScopedVector<std::string> pending_data_; |
115 | 115 |
116 // The number of bytes to be skipped. | 116 // The number of bytes to be skipped. |
117 int64_t remaining_offset_; | 117 int64_t remaining_offset_; |
118 | 118 |
119 // The number of bytes of remaining data (including the data not yet | 119 // The number of bytes of remaining data (including the data not yet |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 class DriveFileStreamReader { | 153 class DriveFileStreamReader { |
154 public: | 154 public: |
155 // Callback to return the FileSystemInterface instance. This is an | 155 // Callback to return the FileSystemInterface instance. This is an |
156 // injecting point for testing. | 156 // injecting point for testing. |
157 // Note that the callback will be copied between threads (IO and UI), and | 157 // Note that the callback will be copied between threads (IO and UI), and |
158 // will be called on UI thread. | 158 // will be called on UI thread. |
159 typedef base::Callback<FileSystemInterface*()> FileSystemGetter; | 159 typedef base::Callback<FileSystemInterface*()> FileSystemGetter; |
160 | 160 |
161 // Callback to return the result of Initialize(). | 161 // Callback to return the result of Initialize(). |
162 // |error| is net::Error code. | 162 // |error| is net::Error code. |
163 typedef base::Callback<void(int error, scoped_ptr<ResourceEntry> entry)> | 163 typedef base::Callback<void(int error, std::unique_ptr<ResourceEntry> entry)> |
164 InitializeCompletionCallback; | 164 InitializeCompletionCallback; |
165 | 165 |
166 DriveFileStreamReader(const FileSystemGetter& file_system_getter, | 166 DriveFileStreamReader(const FileSystemGetter& file_system_getter, |
167 base::SequencedTaskRunner* file_task_runner); | 167 base::SequencedTaskRunner* file_task_runner); |
168 ~DriveFileStreamReader(); | 168 ~DriveFileStreamReader(); |
169 | 169 |
170 // Returns true if the reader is initialized. | 170 // Returns true if the reader is initialized. |
171 bool IsInitialized() const; | 171 bool IsInitialized() const; |
172 | 172 |
173 // Initializes the stream for the |drive_file_path|. | 173 // Initializes the stream for the |drive_file_path|. |
(...skipping 17 matching lines...) Expand all Loading... |
191 // Used to store the cancel closure returned by FileSystemInterface. | 191 // Used to store the cancel closure returned by FileSystemInterface. |
192 void StoreCancelDownloadClosure(const base::Closure& cancel_download_closure); | 192 void StoreCancelDownloadClosure(const base::Closure& cancel_download_closure); |
193 | 193 |
194 // Part of Initialize. Called after GetFileContent's initialization | 194 // Part of Initialize. Called after GetFileContent's initialization |
195 // is done. | 195 // is done. |
196 void InitializeAfterGetFileContentInitialized( | 196 void InitializeAfterGetFileContentInitialized( |
197 const net::HttpByteRange& byte_range, | 197 const net::HttpByteRange& byte_range, |
198 const InitializeCompletionCallback& callback, | 198 const InitializeCompletionCallback& callback, |
199 FileError error, | 199 FileError error, |
200 const base::FilePath& local_cache_file_path, | 200 const base::FilePath& local_cache_file_path, |
201 scoped_ptr<ResourceEntry> entry); | 201 std::unique_ptr<ResourceEntry> entry); |
202 | 202 |
203 // Part of Initialize. Called when the local file open process is done. | 203 // Part of Initialize. Called when the local file open process is done. |
204 void InitializeAfterLocalFileOpen( | 204 void InitializeAfterLocalFileOpen( |
205 int64_t length, | 205 int64_t length, |
206 const InitializeCompletionCallback& callback, | 206 const InitializeCompletionCallback& callback, |
207 scoped_ptr<ResourceEntry> entry, | 207 std::unique_ptr<ResourceEntry> entry, |
208 scoped_ptr<util::LocalFileReader> file_reader, | 208 std::unique_ptr<util::LocalFileReader> file_reader, |
209 int open_result); | 209 int open_result); |
210 | 210 |
211 // Called when the data is received from the server. | 211 // Called when the data is received from the server. |
212 void OnGetContent(google_apis::DriveApiErrorCode error_code, | 212 void OnGetContent(google_apis::DriveApiErrorCode error_code, |
213 scoped_ptr<std::string> data); | 213 std::unique_ptr<std::string> data); |
214 | 214 |
215 // Called when GetFileContent is completed. | 215 // Called when GetFileContent is completed. |
216 void OnGetFileContentCompletion( | 216 void OnGetFileContentCompletion( |
217 const InitializeCompletionCallback& callback, | 217 const InitializeCompletionCallback& callback, |
218 FileError error); | 218 FileError error); |
219 | 219 |
220 const FileSystemGetter file_system_getter_; | 220 const FileSystemGetter file_system_getter_; |
221 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; | 221 scoped_refptr<base::SequencedTaskRunner> file_task_runner_; |
222 base::Closure cancel_download_closure_; | 222 base::Closure cancel_download_closure_; |
223 scoped_ptr<internal::ReaderProxy> reader_proxy_; | 223 std::unique_ptr<internal::ReaderProxy> reader_proxy_; |
224 | 224 |
225 base::ThreadChecker thread_checker_; | 225 base::ThreadChecker thread_checker_; |
226 | 226 |
227 // This should remain the last member so it'll be destroyed first and | 227 // This should remain the last member so it'll be destroyed first and |
228 // invalidate its weak pointers before other members are destroyed. | 228 // invalidate its weak pointers before other members are destroyed. |
229 base::WeakPtrFactory<DriveFileStreamReader> weak_ptr_factory_; | 229 base::WeakPtrFactory<DriveFileStreamReader> weak_ptr_factory_; |
230 DISALLOW_COPY_AND_ASSIGN(DriveFileStreamReader); | 230 DISALLOW_COPY_AND_ASSIGN(DriveFileStreamReader); |
231 }; | 231 }; |
232 | 232 |
233 } // namespace drive | 233 } // namespace drive |
234 | 234 |
235 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_FILE_STREAM_READER_H_ | 235 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_FILE_STREAM_READER_H_ |
OLD | NEW |