Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_BASE_UPLOAD_ELEMENT_READER_H_ | |
| 6 #define NET_BASE_UPLOAD_ELEMENT_READER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "net/base/net_export.h" | |
| 10 | |
| 11 namespace net { | |
| 12 | |
| 13 class UploadElement; | |
| 14 | |
| 15 // An interface to read an upload data element. | |
| 16 class NET_EXPORT UploadElementReader { | |
| 17 public: | |
| 18 UploadElementReader() {} | |
| 19 virtual ~UploadElementReader() {} | |
| 20 | |
| 21 // Creates an appropriate UploadElementReader instance for the given element. | |
| 22 static UploadElementReader* Create(const UploadElement& element); | |
| 23 | |
| 24 // Initializes the instance synchronously. | |
| 25 virtual int InitSync() = 0; | |
| 26 | |
| 27 // Returns the byte-length of the element. For files that do not exist, 0 | |
| 28 // is returned. This is done for consistency with Mozilla. | |
| 29 virtual uint64 GetContentLength() const = 0; | |
| 30 | |
| 31 // Returns the number of bytes remaining to read. | |
| 32 virtual uint64 BytesRemaining() const = 0; | |
| 33 | |
| 34 // Returns true if the upload element is entirely in memory. | |
| 35 // The default implementation returns false. | |
| 36 virtual bool IsInMemory() const; | |
| 37 | |
| 38 // Reads up to |buf_length| bytes synchronously. Returns the number of bytes | |
|
willchan no longer on Chromium
2012/09/06 01:06:01
Is it valid to read 0 bytes? What happens when Byt
hashimoto
2012/09/06 01:55:39
No behavior change from the current code.
Reading
| |
| 39 // 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). | |
| 41 // |buf_length| must be greater than 0. | |
| 42 virtual int ReadSync(char* buf, int buf_length) = 0; | |
| 43 | |
| 44 private: | |
| 45 DISALLOW_COPY_AND_ASSIGN(UploadElementReader); | |
| 46 }; | |
| 47 | |
| 48 } // namespace net | |
| 49 | |
| 50 #endif // NET_BASE_UPLOAD_ELEMENT_READER_H_ | |
| OLD | NEW |