Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: net/base/upload_bytes_element_reader.h

Issue 11439008: net: Change argument of URLRequest::set_upload from UploadData to UploadDataStream (Closed) Base URL: http://git.chromium.org/chromium/src.git@chunk
Patch Set: Fix android Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_BASE_UPLOAD_BYTES_ELEMENT_READER_H_ 5 #ifndef NET_BASE_UPLOAD_BYTES_ELEMENT_READER_H_
6 #define NET_BASE_UPLOAD_BYTES_ELEMENT_READER_H_ 6 #define NET_BASE_UPLOAD_BYTES_ELEMENT_READER_H_
7 7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
9 #include "net/base/upload_element_reader.h" 13 #include "net/base/upload_element_reader.h"
10 14
11 namespace net { 15 namespace net {
12 16
13 // An UploadElementReader implementation for bytes. 17 // An UploadElementReader implementation for bytes.
14 class NET_EXPORT_PRIVATE UploadBytesElementReader : public UploadElementReader { 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 {
15 public: 21 public:
16 UploadBytesElementReader(const char* bytes, int length); 22 UploadBytesElementReader(const char* bytes, uint64 length);
17 virtual ~UploadBytesElementReader(); 23 virtual ~UploadBytesElementReader();
18 24
19 const char* bytes() const { return bytes_; } 25 const char* bytes() const { return bytes_; }
20 int length() const { return length_; } 26 uint64 length() const { return length_; }
21 27
22 // UploadElementReader overrides: 28 // UploadElementReader overrides:
23 virtual const UploadBytesElementReader* AsBytesReader() const OVERRIDE; 29 virtual const UploadBytesElementReader* AsBytesReader() const OVERRIDE;
24 virtual int Init(const CompletionCallback& callback) OVERRIDE; 30 virtual int Init(const CompletionCallback& callback) OVERRIDE;
25 virtual int InitSync() OVERRIDE; 31 virtual int InitSync() OVERRIDE;
26 virtual uint64 GetContentLength() const OVERRIDE; 32 virtual uint64 GetContentLength() const OVERRIDE;
27 virtual uint64 BytesRemaining() const OVERRIDE; 33 virtual uint64 BytesRemaining() const OVERRIDE;
28 virtual bool IsInMemory() const OVERRIDE; 34 virtual bool IsInMemory() const OVERRIDE;
29 virtual int Read(IOBuffer* buf, 35 virtual int Read(IOBuffer* buf,
30 int buf_length, 36 int buf_length,
31 const CompletionCallback& callback) OVERRIDE; 37 const CompletionCallback& callback) OVERRIDE;
32 virtual int ReadSync(IOBuffer* buf, int buf_length) OVERRIDE; 38 virtual int ReadSync(IOBuffer* buf, int buf_length) OVERRIDE;
33 39
34 private: 40 private:
35 const char* const bytes_; 41 const char* const bytes_;
36 const int length_; 42 const uint64 length_;
37 int offset_; 43 uint64 offset_;
38 44
39 DISALLOW_COPY_AND_ASSIGN(UploadBytesElementReader); 45 DISALLOW_COPY_AND_ASSIGN(UploadBytesElementReader);
40 }; 46 };
41 47
48 // A subclass of UplodBytesElementReader which owns the data given as a vector.
49 class NET_EXPORT UploadOwnedBytesElementReader
50 : public UploadBytesElementReader {
51 public:
52 // |data| is cleared by this ctor.
53 explicit UploadOwnedBytesElementReader(std::vector<char>* data);
54 virtual ~UploadOwnedBytesElementReader();
55
56 // Creates UploadOwnedBytesElementReader with a string.
57 static UploadOwnedBytesElementReader* CreateWithString(
58 const std::string& string);
59
60 private:
61 std::vector<char> data_;
62
63 DISALLOW_COPY_AND_ASSIGN(UploadOwnedBytesElementReader);
64 };
65
42 } // namespace net 66 } // namespace net
43 67
44 #endif // NET_BASE_UPLOAD_BYTES_ELEMENT_READER_H_ 68 #endif // NET_BASE_UPLOAD_BYTES_ELEMENT_READER_H_
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_unittest.cc ('k') | net/base/upload_bytes_element_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698