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.h" | 5 #include "net/base/upload_data.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/threading/worker_pool.h" | 10 #include "base/threading/worker_pool.h" |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 // Helper function for GetContentLength(). | 16 // Helper function for GetContentLength(). |
17 void OnGetContentLengthComplete( | 17 void OnGetContentLengthComplete( |
18 const UploadData::ContentLengthCallback& callback, | 18 const UploadData::ContentLengthCallback& callback, |
19 uint64* content_length) { | 19 uint64* content_length) { |
20 callback.Run(*content_length); | 20 callback.Run(*content_length); |
21 } | 21 } |
22 | 22 |
23 } // namespace | 23 } // namespace |
24 | 24 |
25 UploadData::UploadData() | 25 UploadData::UploadData() |
26 : identifier_(0), | 26 : identifier_(0), |
27 chunk_callback_(NULL), | 27 chunk_callback_(NULL), |
28 is_chunked_(false) { | 28 is_chunked_(false), |
| 29 last_chunk_appended_(false) { |
29 } | 30 } |
30 | 31 |
31 void UploadData::AppendBytes(const char* bytes, int bytes_len) { | 32 void UploadData::AppendBytes(const char* bytes, int bytes_len) { |
32 DCHECK(!is_chunked_); | 33 DCHECK(!is_chunked_); |
33 if (bytes_len > 0) { | 34 if (bytes_len > 0) { |
34 elements_.push_back(UploadElement()); | 35 elements_.push_back(UploadElement()); |
35 elements_.back().SetToBytes(bytes, bytes_len); | 36 elements_.back().SetToBytes(bytes, bytes_len); |
36 } | 37 } |
37 } | 38 } |
38 | 39 |
39 void UploadData::AppendFileRange(const FilePath& file_path, | 40 void UploadData::AppendFileRange(const FilePath& file_path, |
40 uint64 offset, uint64 length, | 41 uint64 offset, uint64 length, |
41 const base::Time& expected_modification_time) { | 42 const base::Time& expected_modification_time) { |
42 DCHECK(!is_chunked_); | 43 DCHECK(!is_chunked_); |
43 elements_.push_back(UploadElement()); | 44 elements_.push_back(UploadElement()); |
44 elements_.back().SetToFilePathRange(file_path, offset, length, | 45 elements_.back().SetToFilePathRange(file_path, offset, length, |
45 expected_modification_time); | 46 expected_modification_time); |
46 } | 47 } |
47 | 48 |
48 void UploadData::AppendChunk(const char* bytes, | 49 void UploadData::AppendChunk(const char* bytes, |
49 int bytes_len, | 50 int bytes_len, |
50 bool is_last_chunk) { | 51 bool is_last_chunk) { |
51 DCHECK(is_chunked_); | 52 DCHECK(is_chunked_); |
| 53 DCHECK(!last_chunk_appended_); |
52 elements_.push_back(UploadElement()); | 54 elements_.push_back(UploadElement()); |
53 elements_.back().SetToChunk(bytes, bytes_len, is_last_chunk); | 55 elements_.back().SetToBytes(bytes, bytes_len); |
| 56 last_chunk_appended_ = is_last_chunk; |
54 if (chunk_callback_) | 57 if (chunk_callback_) |
55 chunk_callback_->OnChunkAvailable(); | 58 chunk_callback_->OnChunkAvailable(); |
56 } | 59 } |
57 | 60 |
58 void UploadData::set_chunk_callback(ChunkCallback* callback) { | 61 void UploadData::set_chunk_callback(ChunkCallback* callback) { |
59 chunk_callback_ = callback; | 62 chunk_callback_ = callback; |
60 } | 63 } |
61 | 64 |
62 void UploadData::GetContentLength(const ContentLengthCallback& callback) { | 65 void UploadData::GetContentLength(const ContentLengthCallback& callback) { |
63 uint64* result = new uint64(0); | 66 uint64* result = new uint64(0); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 return; | 111 return; |
109 | 112 |
110 for (size_t i = 0; i < elements_.size(); ++i) | 113 for (size_t i = 0; i < elements_.size(); ++i) |
111 *content_length += elements_[i].GetContentLength(); | 114 *content_length += elements_[i].GetContentLength(); |
112 } | 115 } |
113 | 116 |
114 UploadData::~UploadData() { | 117 UploadData::~UploadData() { |
115 } | 118 } |
116 | 119 |
117 } // namespace net | 120 } // namespace net |
OLD | NEW |