Chromium Code Reviews| 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 // Conceptually this is a part of implementation details for | |
|
hashimoto
2013/04/16 08:38:29
nit: Is this sentence needed? The name of the name
hidehiko
2013/04/16 08:57:11
Ok. Removed.
| |
| 28 // DriveFileStreamReader but exposed under internal namespace for testing | |
| 29 // purpose. | |
| 30 class ReaderProxy { | |
| 31 public: | |
| 32 virtual ~ReaderProxy() {} | |
| 33 | |
| 34 // Called from DriveFileStreamReader::Read method. | |
| 35 virtual int Read(net::IOBuffer* buffer, int buffer_length, | |
| 36 const net::CompletionCallback& callback) = 0; | |
| 37 | |
| 38 // Called when the data from the server is received. | |
| 39 virtual void OnGetContent(scoped_ptr<std::string> data) = 0; | |
|
hashimoto
2013/04/16 08:38:29
Does this method need to be in this interface?
Onl
hidehiko
2013/04/16 08:57:11
Yes, this needs to be a part of this interface, ot
| |
| 40 | |
| 41 // Called when an error is found, during the network downloading. | |
| 42 virtual void OnError(DriveFileError error) = 0; | |
|
hashimoto
2013/04/16 08:38:29
ditto.
hidehiko
2013/04/16 08:57:11
Acknowledged.
| |
| 43 }; | |
| 44 | |
| 45 // The read operation implementation for the locally cached files. | |
| 46 class LocalReaderProxy : public ReaderProxy { | |
| 47 public: | |
| 48 // The |file_stream| should be the instance which is already opened. | |
| 49 // This class takes its ownership. | |
| 50 explicit LocalReaderProxy(scoped_ptr<net::FileStream> file_stream); | |
| 51 virtual ~LocalReaderProxy(); | |
| 52 | |
| 53 // ReaderProxy overrides. | |
| 54 virtual int Read(net::IOBuffer* buffer, int buffer_length, | |
| 55 const net::CompletionCallback& callback) OVERRIDE; | |
| 56 virtual void OnGetContent(scoped_ptr<std::string> data) OVERRIDE; | |
| 57 virtual void OnError(DriveFileError error) OVERRIDE; | |
| 58 | |
| 59 private: | |
| 60 scoped_ptr<net::FileStream> file_stream_; | |
| 61 | |
| 62 DISALLOW_COPY_AND_ASSIGN(LocalReaderProxy); | |
| 63 }; | |
| 64 | |
| 65 // TODO(hidehiko): implement the NetworkReaderProxy. | |
| 66 | |
| 67 } // namespace internal | |
| 68 | |
| 69 // TODO(hidehiko): Simplify the interface by getting rid of | |
| 70 // webkit_blob::FileStreamReader inheritance. | |
| 13 class DriveFileStreamReader : public webkit_blob::FileStreamReader { | 71 class DriveFileStreamReader : public webkit_blob::FileStreamReader { |
| 14 public: | 72 public: |
| 15 DriveFileStreamReader(); | 73 DriveFileStreamReader(); |
| 16 virtual ~DriveFileStreamReader(); | 74 virtual ~DriveFileStreamReader(); |
| 17 | 75 |
| 18 // webkit_blob::FileStreamReader overrides. | 76 // webkit_blob::FileStreamReader overrides. |
| 19 virtual int Read(net::IOBuffer* buf, int buf_len, | 77 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 20 const net::CompletionCallback& callback) OVERRIDE; | 78 const net::CompletionCallback& callback) OVERRIDE; |
| 21 virtual int64 GetLength( | 79 virtual int64 GetLength( |
| 22 const net::Int64CompletionCallback& callback) OVERRIDE; | 80 const net::Int64CompletionCallback& callback) OVERRIDE; |
| 23 | 81 |
| 24 private: | 82 private: |
| 25 DISALLOW_COPY_AND_ASSIGN(DriveFileStreamReader); | 83 DISALLOW_COPY_AND_ASSIGN(DriveFileStreamReader); |
| 26 }; | 84 }; |
| 27 | 85 |
| 28 } // namespace drive | 86 } // namespace drive |
| 29 | 87 |
| 30 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_FILE_STREAM_READER_H_ | 88 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_FILE_STREAM_READER_H_ |
| OLD | NEW |