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_BYTES_ELEMENT_READER_H_
6 #define NET_BASE_UPLOAD_BYTES_ELEMENT_READER_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "net/base/upload_element_reader.h"
17 // An UploadElementReader implementation for bytes.
18 // |data| should outlive this class because this class does not take the
19 // ownership of the data.
20 class NET_EXPORT UploadBytesElementReader : public UploadElementReader {
22 UploadBytesElementReader(const char* bytes, uint64 length);
23 virtual ~UploadBytesElementReader();
25 const char* bytes() const { return bytes_; }
26 uint64 length() const { return length_; }
28 // UploadElementReader overrides:
29 virtual const UploadBytesElementReader* AsBytesReader() const OVERRIDE;
30 virtual int Init(const CompletionCallback& callback) OVERRIDE;
31 virtual uint64 GetContentLength() const OVERRIDE;
32 virtual uint64 BytesRemaining() const OVERRIDE;
33 virtual bool IsInMemory() const OVERRIDE;
34 virtual int Read(IOBuffer* buf,
36 const CompletionCallback& callback) OVERRIDE;
39 const char* const bytes_;
43 DISALLOW_COPY_AND_ASSIGN(UploadBytesElementReader);
46 // A subclass of UplodBytesElementReader which owns the data given as a vector.
47 class NET_EXPORT UploadOwnedBytesElementReader
48 : public UploadBytesElementReader {
50 // |data| is cleared by this ctor.
51 explicit UploadOwnedBytesElementReader(std::vector<char>* data);
52 virtual ~UploadOwnedBytesElementReader();
54 // Creates UploadOwnedBytesElementReader with a string.
55 static UploadOwnedBytesElementReader* CreateWithString(
56 const std::string& string);
59 std::vector<char> data_;
61 DISALLOW_COPY_AND_ASSIGN(UploadOwnedBytesElementReader);
66 #endif // NET_BASE_UPLOAD_BYTES_ELEMENT_READER_H_