Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / net / base / upload_bytes_element_reader.h
bloba5ee8a707caf5f086caa23b70fc535e82dbe10a7
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_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "net/base/net_export.h"
14 #include "net/base/upload_element_reader.h"
16 namespace net {
18 // An UploadElementReader implementation for bytes. The caller owns |bytes|,
19 // and is responsible for ensuring it outlives the UploadBytesElementReader.
20 class NET_EXPORT UploadBytesElementReader : public UploadElementReader {
21 public:
22 UploadBytesElementReader(const char* bytes, uint64_t length);
23 ~UploadBytesElementReader() override;
25 const char* bytes() const { return bytes_; }
26 uint64_t length() const { return length_; }
28 // UploadElementReader overrides:
29 const UploadBytesElementReader* AsBytesReader() const override;
30 int Init(const CompletionCallback& callback) override;
31 uint64_t GetContentLength() const override;
32 uint64_t BytesRemaining() const override;
33 bool IsInMemory() const override;
34 int Read(IOBuffer* buf,
35 int buf_length,
36 const CompletionCallback& callback) override;
38 private:
39 const char* const bytes_;
40 const uint64_t length_;
41 uint64_t offset_;
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 {
49 public:
50 // |data| is cleared by this ctor.
51 explicit UploadOwnedBytesElementReader(std::vector<char>* data);
52 ~UploadOwnedBytesElementReader() override;
54 // Creates UploadOwnedBytesElementReader with a string.
55 static UploadOwnedBytesElementReader* CreateWithString(
56 const std::string& string);
58 private:
59 std::vector<char> data_;
61 DISALLOW_COPY_AND_ASSIGN(UploadOwnedBytesElementReader);
64 } // namespace net
66 #endif // NET_BASE_UPLOAD_BYTES_ELEMENT_READER_H_