OLD | NEW |
---|---|
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 <vector> | |
9 | |
8 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
9 #include "net/base/upload_element_reader.h" | 11 #include "net/base/upload_element_reader.h" |
10 | 12 |
11 namespace net { | 13 namespace net { |
12 | 14 |
13 // An UploadElementReader implementation for bytes. | 15 // An UploadElementReader implementation for bytes. |
14 class NET_EXPORT_PRIVATE UploadBytesElementReader : public UploadElementReader { | 16 class NET_EXPORT UploadBytesElementReader : public UploadElementReader { |
kinuko
2012/12/12 01:19:17
Can we add a comment to note that this doesn't cop
hashimoto
2012/12/12 10:29:07
Done.
| |
15 public: | 17 public: |
16 UploadBytesElementReader(const char* bytes, int length); | 18 UploadBytesElementReader(const char* bytes, int length); |
17 virtual ~UploadBytesElementReader(); | 19 virtual ~UploadBytesElementReader(); |
18 | 20 |
19 const char* bytes() const { return bytes_; } | 21 const char* bytes() const { return bytes_; } |
20 int length() const { return length_; } | 22 int length() const { return length_; } |
21 | 23 |
22 // UploadElementReader overrides: | 24 // UploadElementReader overrides: |
23 virtual const UploadBytesElementReader* AsBytesReader() const OVERRIDE; | 25 virtual const UploadBytesElementReader* AsBytesReader() const OVERRIDE; |
24 virtual int Init(const CompletionCallback& callback) OVERRIDE; | 26 virtual int Init(const CompletionCallback& callback) OVERRIDE; |
25 virtual int InitSync() OVERRIDE; | 27 virtual int InitSync() OVERRIDE; |
26 virtual uint64 GetContentLength() const OVERRIDE; | 28 virtual uint64 GetContentLength() const OVERRIDE; |
27 virtual uint64 BytesRemaining() const OVERRIDE; | 29 virtual uint64 BytesRemaining() const OVERRIDE; |
28 virtual bool IsInMemory() const OVERRIDE; | 30 virtual bool IsInMemory() const OVERRIDE; |
29 virtual int Read(IOBuffer* buf, | 31 virtual int Read(IOBuffer* buf, |
30 int buf_length, | 32 int buf_length, |
31 const CompletionCallback& callback) OVERRIDE; | 33 const CompletionCallback& callback) OVERRIDE; |
32 virtual int ReadSync(IOBuffer* buf, int buf_length) OVERRIDE; | 34 virtual int ReadSync(IOBuffer* buf, int buf_length) OVERRIDE; |
33 | 35 |
34 private: | 36 private: |
35 const char* const bytes_; | 37 const char* const bytes_; |
36 const int length_; | 38 const int length_; |
37 int offset_; | 39 int offset_; |
38 | 40 |
39 DISALLOW_COPY_AND_ASSIGN(UploadBytesElementReader); | 41 DISALLOW_COPY_AND_ASSIGN(UploadBytesElementReader); |
40 }; | 42 }; |
41 | 43 |
44 // A subclass of UplodBytesElementReader which owns the data given as a vector. | |
45 class NET_EXPORT UploadOwnedBytesElementReader | |
46 : public UploadBytesElementReader { | |
47 public: | |
48 UploadOwnedBytesElementReader(std::vector<char>* data); | |
mmenke
2012/12/11 18:53:21
Think it's worth mentioning that we clear |data|.
mmenke
2012/12/11 18:53:21
Speaking of which...this function should also be e
hashimoto
2012/12/12 10:29:07
Oops, it seems presubmit check does not help for m
hashimoto
2012/12/12 10:29:07
Done.
| |
49 virtual ~UploadOwnedBytesElementReader(); | |
50 | |
51 private: | |
52 std::vector<char> data_; | |
mmenke
2012/12/11 18:53:21
May make life easier to make UploadOwnedBytesEleme
hashimoto
2012/12/12 10:29:07
Since yet there are only two places which uses Upl
mmenke
2012/12/12 19:26:41
I admit to a bit of a bias against vectors used in
kinuko
2012/12/13 00:07:55
As for the use of &(*data)[0] I think vector_as_ar
mmenke
2012/12/13 00:43:47
Whether we could get empty data or not depends on
hashimoto
2012/12/13 03:58:47
Good point, it seems cleaner to support empty data
| |
53 | |
54 DISALLOW_COPY_AND_ASSIGN(UploadOwnedBytesElementReader); | |
55 }; | |
56 | |
42 } // namespace net | 57 } // namespace net |
43 | 58 |
44 #endif // NET_BASE_UPLOAD_BYTES_ELEMENT_READER_H_ | 59 #endif // NET_BASE_UPLOAD_BYTES_ELEMENT_READER_H_ |
OLD | NEW |