| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 NET_BASE_UPLOAD_ELEMENT_READER_H_ | 5 #ifndef NET_BASE_UPLOAD_ELEMENT_READER_H_ |
| 6 #define NET_BASE_UPLOAD_ELEMENT_READER_H_ | 6 #define NET_BASE_UPLOAD_ELEMENT_READER_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "net/base/completion_callback.h" | 9 #include "net/base/completion_callback.h" |
| 10 #include "net/base/net_export.h" | 10 #include "net/base/net_export.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 class IOBuffer; |
| 14 class UploadElement; | 15 class UploadElement; |
| 15 | 16 |
| 16 // An interface to read an upload data element. | 17 // An interface to read an upload data element. |
| 17 class NET_EXPORT UploadElementReader { | 18 class NET_EXPORT UploadElementReader { |
| 18 public: | 19 public: |
| 19 UploadElementReader() {} | 20 UploadElementReader() {} |
| 20 virtual ~UploadElementReader() {} | 21 virtual ~UploadElementReader() {} |
| 21 | 22 |
| 22 // Creates an appropriate UploadElementReader instance for the given element. | 23 // Creates an appropriate UploadElementReader instance for the given element. |
| 23 static UploadElementReader* Create(const UploadElement& element); | 24 static UploadElementReader* Create(const UploadElement& element); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 34 // is returned. This is done for consistency with Mozilla. | 35 // is returned. This is done for consistency with Mozilla. |
| 35 virtual uint64 GetContentLength() const = 0; | 36 virtual uint64 GetContentLength() const = 0; |
| 36 | 37 |
| 37 // Returns the number of bytes remaining to read. | 38 // Returns the number of bytes remaining to read. |
| 38 virtual uint64 BytesRemaining() const = 0; | 39 virtual uint64 BytesRemaining() const = 0; |
| 39 | 40 |
| 40 // Returns true if the upload element is entirely in memory. | 41 // Returns true if the upload element is entirely in memory. |
| 41 // The default implementation returns false. | 42 // The default implementation returns false. |
| 42 virtual bool IsInMemory() const; | 43 virtual bool IsInMemory() const; |
| 43 | 44 |
| 44 // Reads up to |buf_length| bytes synchronously. Returns the number of bytes | 45 // Reads up to |buf_length| bytes synchronously and returns the number of |
| 45 // read. This function never fails. If there's less data to read than we | 46 // bytes read when possible, otherwise, returns ERR_IO_PENDING and runs |
| 46 // initially observed, then pad with zero (this can happen with files). | 47 // |callback| with the result. This function never fails. If there's less data |
| 47 // |buf_length| must be greater than 0. | 48 // to read than we initially observed, then pad with zero (this can happen |
| 48 virtual int ReadSync(char* buf, int buf_length) = 0; | 49 // with files). |buf_length| must be greater than 0. |
| 50 virtual int Read(IOBuffer* buf, |
| 51 int buf_length, |
| 52 const CompletionCallback& callback) = 0; |
| 53 |
| 54 // Reads the data always synchronously. |
| 55 // Use this method only if the thread is IO allowed or the data is in-memory. |
| 56 virtual int ReadSync(IOBuffer* buf, int buf_length); |
| 49 | 57 |
| 50 private: | 58 private: |
| 51 DISALLOW_COPY_AND_ASSIGN(UploadElementReader); | 59 DISALLOW_COPY_AND_ASSIGN(UploadElementReader); |
| 52 }; | 60 }; |
| 53 | 61 |
| 54 } // namespace net | 62 } // namespace net |
| 55 | 63 |
| 56 #endif // NET_BASE_UPLOAD_ELEMENT_READER_H_ | 64 #endif // NET_BASE_UPLOAD_ELEMENT_READER_H_ |
| OLD | NEW |