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" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 124 |
125 int UploadDataStream::InitInternal(int start_index, | 125 int UploadDataStream::InitInternal(int start_index, |
126 const CompletionCallback& callback) { | 126 const CompletionCallback& callback) { |
127 DCHECK(!initialized_successfully_); | 127 DCHECK(!initialized_successfully_); |
128 | 128 |
129 // Call Init() for all elements. | 129 // Call Init() for all elements. |
130 for (size_t i = start_index; i < element_readers_.size(); ++i) { | 130 for (size_t i = start_index; i < element_readers_.size(); ++i) { |
131 UploadElementReader* reader = element_readers_[i]; | 131 UploadElementReader* reader = element_readers_[i]; |
132 // When new_result is ERR_IO_PENDING, InitInternal() will be called | 132 // When new_result is ERR_IO_PENDING, InitInternal() will be called |
133 // with start_index == i + 1 when reader->Init() finishes. | 133 // with start_index == i + 1 when reader->Init() finishes. |
134 const int result = reader->Init( | 134 const int result = |
135 base::Bind(&UploadDataStream::ResumePendingInit, | 135 reader->Init(base::Bind(&UploadDataStream::ResumePendingInit, |
136 weak_ptr_factory_.GetWeakPtr(), | 136 weak_ptr_factory_.GetWeakPtr(), |
137 i + 1, | 137 i + 1, |
138 callback)); | 138 callback)); |
139 if (result != OK) { | 139 if (result != OK) { |
140 DCHECK(result != ERR_IO_PENDING || !callback.is_null()); | 140 DCHECK(result != ERR_IO_PENDING || !callback.is_null()); |
141 return result; | 141 return result; |
142 } | 142 } |
143 } | 143 } |
144 | 144 |
145 // Finalize initialization. | 145 // Finalize initialization. |
146 if (!is_chunked_) { | 146 if (!is_chunked_) { |
147 uint64 total_size = 0; | 147 uint64 total_size = 0; |
148 for (size_t i = 0; i < element_readers_.size(); ++i) { | 148 for (size_t i = 0; i < element_readers_.size(); ++i) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 DCHECK_NE(ERR_IO_PENDING, result); | 255 DCHECK_NE(ERR_IO_PENDING, result); |
256 DCHECK(!read_failed_); | 256 DCHECK(!read_failed_); |
257 | 257 |
258 if (result >= 0) | 258 if (result >= 0) |
259 buf->DidConsume(result); | 259 buf->DidConsume(result); |
260 else | 260 else |
261 read_failed_ = true; | 261 read_failed_ = true; |
262 } | 262 } |
263 | 263 |
264 } // namespace net | 264 } // namespace net |
OLD | NEW |