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> |
| 9 |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "chrome/browser/chromeos/drive/drive_file_error.h" |
| 13 #include "net/base/completion_callback.h" |
9 #include "webkit/blob/file_stream_reader.h" | 14 #include "webkit/blob/file_stream_reader.h" |
10 | 15 |
| 16 namespace net { |
| 17 class FileStream; |
| 18 class IOBuffer; |
| 19 } // namespace net |
| 20 |
11 namespace drive { | 21 namespace drive { |
| 22 namespace internal { |
12 | 23 |
| 24 // An interface to dispatch the reading operation. If the file is locally |
| 25 // cached, LocalReaderProxy defined below will be used. Otherwise (i.e. the |
| 26 // file is being downloaded from the server), NetworkReaderProxy will be used. |
| 27 class ReaderProxy { |
| 28 public: |
| 29 virtual ~ReaderProxy() {} |
| 30 |
| 31 // Called from DriveFileStreamReader::Read method. |
| 32 virtual int Read(net::IOBuffer* buffer, int buffer_length, |
| 33 const net::CompletionCallback& callback) = 0; |
| 34 |
| 35 // Called when the data from the server is received. |
| 36 virtual void OnGetContent(scoped_ptr<std::string> data) = 0; |
| 37 |
| 38 // Called when an error is found, during the network downloading. |
| 39 virtual void OnError(DriveFileError error) = 0; |
| 40 }; |
| 41 |
| 42 // The read operation implementation for the locally cached files. |
| 43 class LocalReaderProxy : public ReaderProxy { |
| 44 public: |
| 45 // The |file_stream| should be the instance which is already opened. |
| 46 // This class takes its ownership. |
| 47 explicit LocalReaderProxy(scoped_ptr<net::FileStream> file_stream); |
| 48 virtual ~LocalReaderProxy(); |
| 49 |
| 50 // ReaderProxy overrides. |
| 51 virtual int Read(net::IOBuffer* buffer, int buffer_length, |
| 52 const net::CompletionCallback& callback) OVERRIDE; |
| 53 virtual void OnGetContent(scoped_ptr<std::string> data) OVERRIDE; |
| 54 virtual void OnError(DriveFileError error) OVERRIDE; |
| 55 |
| 56 private: |
| 57 scoped_ptr<net::FileStream> file_stream_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(LocalReaderProxy); |
| 60 }; |
| 61 |
| 62 // TODO(hidehiko): implement the NetworkReaderProxy. |
| 63 |
| 64 } // namespace internal |
| 65 |
| 66 // TODO(hidehiko): Simplify the interface by getting rid of |
| 67 // webkit_blob::FileStreamReader inheritance. |
13 class DriveFileStreamReader : public webkit_blob::FileStreamReader { | 68 class DriveFileStreamReader : public webkit_blob::FileStreamReader { |
14 public: | 69 public: |
15 DriveFileStreamReader(); | 70 DriveFileStreamReader(); |
16 virtual ~DriveFileStreamReader(); | 71 virtual ~DriveFileStreamReader(); |
17 | 72 |
18 // webkit_blob::FileStreamReader overrides. | 73 // webkit_blob::FileStreamReader overrides. |
19 virtual int Read(net::IOBuffer* buf, int buf_len, | 74 virtual int Read(net::IOBuffer* buf, int buf_len, |
20 const net::CompletionCallback& callback) OVERRIDE; | 75 const net::CompletionCallback& callback) OVERRIDE; |
21 virtual int64 GetLength( | 76 virtual int64 GetLength( |
22 const net::Int64CompletionCallback& callback) OVERRIDE; | 77 const net::Int64CompletionCallback& callback) OVERRIDE; |
23 | 78 |
24 private: | 79 private: |
25 DISALLOW_COPY_AND_ASSIGN(DriveFileStreamReader); | 80 DISALLOW_COPY_AND_ASSIGN(DriveFileStreamReader); |
26 }; | 81 }; |
27 | 82 |
28 } // namespace drive | 83 } // namespace drive |
29 | 84 |
30 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_FILE_STREAM_READER_H_ | 85 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_FILE_STREAM_READER_H_ |
OLD | NEW |