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/completion_callback.h" | |
10 #include "net/base/net_export.h" | |
11 | |
12 namespace net { | |
13 | |
14 class IOBuffer; | |
15 class UploadBytesElementReader; | |
16 class UploadFileElementReader; | |
17 | |
18 // An interface to read an upload data element. | |
19 class NET_EXPORT UploadElementReader { | |
20 public: | |
21 UploadElementReader() {} | |
22 virtual ~UploadElementReader() {} | |
23 | |
24 // Returns this instance's pointer as UploadBytesElementReader when possible, | |
25 // otherwise returns NULL. | |
26 virtual const UploadBytesElementReader* AsBytesReader() const; | |
27 | |
28 // Returns this instance's pointer as UploadFileElementReader when possible, | |
29 // otherwise returns NULL. | |
30 virtual const UploadFileElementReader* AsFileReader() const; | |
31 | |
32 // Initializes the instance synchronously when possible, otherwise does | |
33 // initialization aynschronously, returns ERR_IO_PENDING and runs callback. | |
34 // Calling this method again after a Init() success results in resetting the | |
35 // state. | |
36 virtual int Init(const CompletionCallback& callback) = 0; | |
37 | |
38 // Returns the byte-length of the element. For files that do not exist, 0 | |
39 // is returned. This is done for consistency with Mozilla. | |
40 virtual uint64 GetContentLength() const = 0; | |
41 | |
42 // Returns the number of bytes remaining to read. | |
43 virtual uint64 BytesRemaining() const = 0; | |
44 | |
45 // Returns true if the upload element is entirely in memory. | |
46 // The default implementation returns false. | |
47 virtual bool IsInMemory() const; | |
48 | |
49 // Reads up to |buf_length| bytes synchronously and returns the number of | |
50 // bytes read or error code when possible, otherwise, returns ERR_IO_PENDING | |
51 // and runs |callback| with the result. |buf_length| must be greater than 0. | |
52 virtual int Read(IOBuffer* buf, | |
53 int buf_length, | |
54 const CompletionCallback& callback) = 0; | |
55 | |
56 private: | |
57 DISALLOW_COPY_AND_ASSIGN(UploadElementReader); | |
58 }; | |
59 | |
60 } // namespace net | |
61 | |
62 #endif // NET_BASE_UPLOAD_ELEMENT_READER_H_ | |
OLD | NEW |