Move AsyncPolicyProvider, etc. to components/policy/.
[chromium-blink-merge.git] / net / base / upload_element_reader.h
blobd71f57cdb6462924b4c573f7b473c5cfc02301fd
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.
5 #ifndef NET_BASE_UPLOAD_ELEMENT_READER_H_
6 #define NET_BASE_UPLOAD_ELEMENT_READER_H_
8 #include "base/basictypes.h"
9 #include "net/base/completion_callback.h"
10 #include "net/base/net_export.h"
12 namespace net {
14 class IOBuffer;
15 class UploadBytesElementReader;
16 class UploadFileElementReader;
18 // An interface to read an upload data element.
19 class NET_EXPORT UploadElementReader {
20 public:
21 UploadElementReader() {}
22 virtual ~UploadElementReader() {}
24 // Returns this instance's pointer as UploadBytesElementReader when possible,
25 // otherwise returns NULL.
26 virtual const UploadBytesElementReader* AsBytesReader() const;
28 // Returns this instance's pointer as UploadFileElementReader when possible,
29 // otherwise returns NULL.
30 virtual const UploadFileElementReader* AsFileReader() const;
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;
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;
42 // Returns the number of bytes remaining to read.
43 virtual uint64 BytesRemaining() const = 0;
45 // Returns true if the upload element is entirely in memory.
46 // The default implementation returns false.
47 virtual bool IsInMemory() const;
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;
56 private:
57 DISALLOW_COPY_AND_ASSIGN(UploadElementReader);
60 } // namespace net
62 #endif // NET_BASE_UPLOAD_ELEMENT_READER_H_