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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 // The read operation implementation for the locally cached files. | 53 // The read operation implementation for the locally cached files. |
54 class LocalReaderProxy : public ReaderProxy { | 54 class LocalReaderProxy : public ReaderProxy { |
55 public: | 55 public: |
56 // The |file_reader| should be the instance which is already opened. | 56 // The |file_reader| should be the instance which is already opened. |
57 // This class takes its ownership. | 57 // This class takes its ownership. |
58 // |length| is the number of bytes to be read. It must be equal or | 58 // |length| is the number of bytes to be read. It must be equal or |
59 // smaller than the remaining data size in the |file_reader|. | 59 // smaller than the remaining data size in the |file_reader|. |
60 LocalReaderProxy( | 60 LocalReaderProxy( |
61 scoped_ptr<util::LocalFileReader> file_reader, int64 length); | 61 scoped_ptr<util::LocalFileReader> file_reader, int64 length); |
62 virtual ~LocalReaderProxy(); | 62 ~LocalReaderProxy() override; |
63 | 63 |
64 // ReaderProxy overrides. | 64 // ReaderProxy overrides. |
65 virtual int Read(net::IOBuffer* buffer, int buffer_length, | 65 int Read(net::IOBuffer* buffer, |
66 const net::CompletionCallback& callback) override; | 66 int buffer_length, |
67 virtual void OnGetContent(scoped_ptr<std::string> data) override; | 67 const net::CompletionCallback& callback) override; |
68 virtual void OnCompleted(FileError error) override; | 68 void OnGetContent(scoped_ptr<std::string> data) override; |
| 69 void OnCompleted(FileError error) override; |
69 | 70 |
70 private: | 71 private: |
71 scoped_ptr<util::LocalFileReader> file_reader_; | 72 scoped_ptr<util::LocalFileReader> file_reader_; |
72 | 73 |
73 // Callback for the LocalFileReader::Read. | 74 // Callback for the LocalFileReader::Read. |
74 void OnReadCompleted( | 75 void OnReadCompleted( |
75 const net::CompletionCallback& callback, int read_result); | 76 const net::CompletionCallback& callback, int read_result); |
76 | 77 |
77 // The number of remaining bytes to be read. | 78 // The number of remaining bytes to be read. |
78 int64 remaining_length_; | 79 int64 remaining_length_; |
79 | 80 |
80 // This should remain the last member so it'll be destroyed first and | 81 // This should remain the last member so it'll be destroyed first and |
81 // invalidate its weak pointers before other members are destroyed. | 82 // invalidate its weak pointers before other members are destroyed. |
82 base::WeakPtrFactory<LocalReaderProxy> weak_ptr_factory_; | 83 base::WeakPtrFactory<LocalReaderProxy> weak_ptr_factory_; |
83 DISALLOW_COPY_AND_ASSIGN(LocalReaderProxy); | 84 DISALLOW_COPY_AND_ASSIGN(LocalReaderProxy); |
84 }; | 85 }; |
85 | 86 |
86 // The read operation implementation for the file which is being downloaded. | 87 // The read operation implementation for the file which is being downloaded. |
87 class NetworkReaderProxy : public ReaderProxy { | 88 class NetworkReaderProxy : public ReaderProxy { |
88 public: | 89 public: |
89 // If the instance is deleted during the download process, it is necessary | 90 // If the instance is deleted during the download process, it is necessary |
90 // to cancel the job. |job_canceller| should be the callback to run the | 91 // to cancel the job. |job_canceller| should be the callback to run the |
91 // cancelling. |full_content_length| is necessary for determining whether the | 92 // cancelling. |full_content_length| is necessary for determining whether the |
92 // deletion is done in the middle of download process. | 93 // deletion is done in the middle of download process. |
93 NetworkReaderProxy( | 94 NetworkReaderProxy( |
94 int64 offset, int64 content_length, int64 full_content_length, | 95 int64 offset, int64 content_length, int64 full_content_length, |
95 const base::Closure& job_canceller); | 96 const base::Closure& job_canceller); |
96 virtual ~NetworkReaderProxy(); | 97 ~NetworkReaderProxy() override; |
97 | 98 |
98 // ReaderProxy overrides. | 99 // ReaderProxy overrides. |
99 virtual int Read(net::IOBuffer* buffer, int buffer_length, | 100 int Read(net::IOBuffer* buffer, |
100 const net::CompletionCallback& callback) override; | 101 int buffer_length, |
101 virtual void OnGetContent(scoped_ptr<std::string> data) override; | 102 const net::CompletionCallback& callback) override; |
102 virtual void OnCompleted(FileError error) override; | 103 void OnGetContent(scoped_ptr<std::string> data) override; |
| 104 void OnCompleted(FileError error) override; |
103 | 105 |
104 private: | 106 private: |
105 // The data received from the server, but not yet read. | 107 // The data received from the server, but not yet read. |
106 ScopedVector<std::string> pending_data_; | 108 ScopedVector<std::string> pending_data_; |
107 | 109 |
108 // The number of bytes to be skipped. | 110 // The number of bytes to be skipped. |
109 int64 remaining_offset_; | 111 int64 remaining_offset_; |
110 | 112 |
111 // The number of bytes of remaining data (including the data not yet | 113 // The number of bytes of remaining data (including the data not yet |
112 // received from the server). | 114 // received from the server). |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 | 216 |
215 // This should remain the last member so it'll be destroyed first and | 217 // This should remain the last member so it'll be destroyed first and |
216 // invalidate its weak pointers before other members are destroyed. | 218 // invalidate its weak pointers before other members are destroyed. |
217 base::WeakPtrFactory<DriveFileStreamReader> weak_ptr_factory_; | 219 base::WeakPtrFactory<DriveFileStreamReader> weak_ptr_factory_; |
218 DISALLOW_COPY_AND_ASSIGN(DriveFileStreamReader); | 220 DISALLOW_COPY_AND_ASSIGN(DriveFileStreamReader); |
219 }; | 221 }; |
220 | 222 |
221 } // namespace drive | 223 } // namespace drive |
222 | 224 |
223 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_FILE_STREAM_READER_H_ | 225 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_FILE_STREAM_READER_H_ |
OLD | NEW |