| 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/net_export.h" | 10 #include "net/base/net_export.h" |
| 10 | 11 |
| 11 namespace net { | 12 namespace net { |
| 12 | 13 |
| 13 class UploadElement; | 14 class UploadElement; |
| 14 | 15 |
| 15 // An interface to read an upload data element. | 16 // An interface to read an upload data element. |
| 16 class NET_EXPORT UploadElementReader { | 17 class NET_EXPORT UploadElementReader { |
| 17 public: | 18 public: |
| 18 UploadElementReader() {} | 19 UploadElementReader() {} |
| 19 virtual ~UploadElementReader() {} | 20 virtual ~UploadElementReader() {} |
| 20 | 21 |
| 21 // Creates an appropriate UploadElementReader instance for the given element. | 22 // Creates an appropriate UploadElementReader instance for the given element. |
| 22 static UploadElementReader* Create(const UploadElement& element); | 23 static UploadElementReader* Create(const UploadElement& element); |
| 23 | 24 |
| 24 // Initializes the instance synchronously. | 25 // Initializes the instance synchronously when possible, otherwise does |
| 25 virtual int InitSync() = 0; | 26 // initialization aynschronously, returns ERR_IO_PENDING and runs callback. |
| 27 virtual int Init(const CompletionCallback& callback) = 0; |
| 28 |
| 29 // Initializes the instance always synchronously. |
| 30 // Use this method only in tests and Chrome Frame. |
| 31 virtual int InitSync(); |
| 26 | 32 |
| 27 // Returns the byte-length of the element. For files that do not exist, 0 | 33 // Returns the byte-length of the element. For files that do not exist, 0 |
| 28 // is returned. This is done for consistency with Mozilla. | 34 // is returned. This is done for consistency with Mozilla. |
| 29 virtual uint64 GetContentLength() const = 0; | 35 virtual uint64 GetContentLength() const = 0; |
| 30 | 36 |
| 31 // Returns the number of bytes remaining to read. | 37 // Returns the number of bytes remaining to read. |
| 32 virtual uint64 BytesRemaining() const = 0; | 38 virtual uint64 BytesRemaining() const = 0; |
| 33 | 39 |
| 34 // Returns true if the upload element is entirely in memory. | 40 // Returns true if the upload element is entirely in memory. |
| 35 // The default implementation returns false. | 41 // The default implementation returns false. |
| 36 virtual bool IsInMemory() const; | 42 virtual bool IsInMemory() const; |
| 37 | 43 |
| 38 // Reads up to |buf_length| bytes synchronously. Returns the number of bytes | 44 // Reads up to |buf_length| bytes synchronously. Returns the number of bytes |
| 39 // read. This function never fails. If there's less data to read than we | 45 // read. This function never fails. If there's less data to read than we |
| 40 // initially observed, then pad with zero (this can happen with files). | 46 // initially observed, then pad with zero (this can happen with files). |
| 41 // |buf_length| must be greater than 0. | 47 // |buf_length| must be greater than 0. |
| 42 virtual int ReadSync(char* buf, int buf_length) = 0; | 48 virtual int ReadSync(char* buf, int buf_length) = 0; |
| 43 | 49 |
| 44 private: | 50 private: |
| 45 DISALLOW_COPY_AND_ASSIGN(UploadElementReader); | 51 DISALLOW_COPY_AND_ASSIGN(UploadElementReader); |
| 46 }; | 52 }; |
| 47 | 53 |
| 48 } // namespace net | 54 } // namespace net |
| 49 | 55 |
| 50 #endif // NET_BASE_UPLOAD_ELEMENT_READER_H_ | 56 #endif // NET_BASE_UPLOAD_ELEMENT_READER_H_ |
| OLD | NEW |