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 #include "net/base/upload_data_stream.h" | 5 #include "net/base/upload_data_stream.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/base/upload_bytes_element_reader.h" | 10 #include "net/base/upload_bytes_element_reader.h" |
11 #include "net/base/upload_element_reader.h" | 11 #include "net/base/upload_element_reader.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 namespace { | |
16 | |
17 // A subclass of UplodBytesElementReader which owns the data given as a vector. | |
18 class UploadOwnedBytesElementReader : public UploadBytesElementReader { | |
19 public: | |
20 UploadOwnedBytesElementReader(std::vector<char>* data) | |
21 : UploadBytesElementReader(&(*data)[0], data->size()) { | |
22 data_.swap(*data); | |
23 } | |
24 | |
25 virtual ~UploadOwnedBytesElementReader() {} | |
26 | |
27 private: | |
28 std::vector<char> data_; | |
29 }; | |
30 | |
31 } // namespace | |
32 | |
33 bool UploadDataStream::merge_chunks_ = true; | 15 bool UploadDataStream::merge_chunks_ = true; |
34 | 16 |
35 // static | 17 // static |
36 void UploadDataStream::ResetMergeChunks() { | 18 void UploadDataStream::ResetMergeChunks() { |
37 // WARNING: merge_chunks_ must match the above initializer. | 19 // WARNING: merge_chunks_ must match the above initializer. |
38 merge_chunks_ = true; | 20 merge_chunks_ = true; |
39 } | 21 } |
40 | 22 |
41 UploadDataStream::UploadDataStream( | 23 UploadDataStream::UploadDataStream( |
42 ScopedVector<UploadElementReader>* element_readers, | 24 ScopedVector<UploadElementReader>* element_readers, |
(...skipping 16 matching lines...) Expand all Loading... |
59 identifier_(identifier), | 41 identifier_(identifier), |
60 is_chunked_(true), | 42 is_chunked_(true), |
61 last_chunk_appended_(false), | 43 last_chunk_appended_(false), |
62 initialized_successfully_(false), | 44 initialized_successfully_(false), |
63 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 45 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
64 } | 46 } |
65 | 47 |
66 UploadDataStream::~UploadDataStream() { | 48 UploadDataStream::~UploadDataStream() { |
67 } | 49 } |
68 | 50 |
| 51 UploadDataStream* UploadDataStream::CreateWithReader( |
| 52 scoped_ptr<UploadElementReader> reader, |
| 53 int64 identifier) { |
| 54 ScopedVector<UploadElementReader> readers; |
| 55 readers.push_back(reader.release()); |
| 56 return new UploadDataStream(&readers, identifier); |
| 57 } |
| 58 |
69 int UploadDataStream::Init(const CompletionCallback& callback) { | 59 int UploadDataStream::Init(const CompletionCallback& callback) { |
70 Reset(); | 60 Reset(); |
71 // Use fast path when initialization can be done synchronously. | 61 // Use fast path when initialization can be done synchronously. |
72 if (IsInMemory()) | 62 if (IsInMemory()) |
73 return InitSync(); | 63 return InitSync(); |
74 | 64 |
75 return InitInternal(0, callback); | 65 return InitInternal(0, callback); |
76 } | 66 } |
77 | 67 |
78 int UploadDataStream::InitSync() { | 68 int UploadDataStream::InitSync() { |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 // Add the last result. | 271 // Add the last result. |
282 buf->DidConsume(previous_result); | 272 buf->DidConsume(previous_result); |
283 | 273 |
284 DCHECK(!callback.is_null()); | 274 DCHECK(!callback.is_null()); |
285 const int result = ReadInternal(buf, callback); | 275 const int result = ReadInternal(buf, callback); |
286 if (result != ERR_IO_PENDING) | 276 if (result != ERR_IO_PENDING) |
287 callback.Run(result); | 277 callback.Run(result); |
288 } | 278 } |
289 | 279 |
290 } // namespace net | 280 } // namespace net |
OLD | NEW |