Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 | 9 |
| 10 namespace net { | 10 namespace net { |
| 11 | 11 |
| 12 uint64 UploadData::GetContentLength() const { | 12 uint64 UploadData::GetContentLength() const { |
| 13 uint64 len = 0; | 13 uint64 len = 0; |
| 14 std::vector<Element>::const_iterator it = elements_.begin(); | 14 std::vector<Element>::const_iterator it = elements_.begin(); |
| 15 for (; it != elements_.end(); ++it) | 15 for (; it != elements_.end(); ++it) |
| 16 len += (*it).GetContentLength(); | 16 len += (*it).GetContentLength(); |
| 17 return len; | 17 return len; |
| 18 } | 18 } |
| 19 | 19 |
| 20 uint64 UploadData::Element::GetContentLength() const { | 20 uint64 UploadData::Element::GetContentLength() const { |
| 21 if (type_ == TYPE_BYTES) | 21 if (type_ == TYPE_BYTES) |
| 22 return static_cast<uint64>(bytes_.size()); | 22 return static_cast<uint64>(bytes_.size()); |
| 23 | 23 |
| 24 DCHECK(type_ == TYPE_FILE); | 24 DCHECK(type_ == TYPE_FILE); |
| 25 | 25 |
| 26 // TODO(darin): This size calculation could be out of sync with the state of | 26 expected_file_length_ = 0; |
| 27 // the file when we get around to reading it. We should probably find a way | |
| 28 // to lock the file or somehow protect against this error condition. | |
| 29 | 27 |
| 30 int64 length = 0; | 28 if (!file_util::PathIsReadable(file_path_)) |
|
darin (slow to review)
2010/01/12 07:57:45
on windows, it might be nice to combine these two
agl
2010/01/25 14:14:09
PathIsReadable no longer obtains a file handle, so
| |
| 29 return 0; | |
| 30 | |
| 31 int64 length; | |
| 31 if (!file_util::GetFileSize(file_path_, &length)) | 32 if (!file_util::GetFileSize(file_path_, &length)) |
| 32 return 0; | 33 return 0; |
| 33 | 34 |
| 34 if (file_range_offset_ >= static_cast<uint64>(length)) | 35 if (file_range_offset_ >= static_cast<uint64>(length)) |
| 35 return 0; // range is beyond eof | 36 return 0; // range is beyond eof |
| 36 | 37 |
| 37 // compensate for the offset and clip file_range_length_ to eof | 38 // compensate for the offset and clip file_range_length_ to eof |
| 38 return std::min(length - file_range_offset_, file_range_length_); | 39 expected_file_length_ = std::min(length - file_range_offset_, |
| 40 file_range_length_); | |
| 41 return expected_file_length_; | |
| 39 } | 42 } |
| 40 | 43 |
| 41 } // namespace net | 44 } // namespace net |
| OLD | NEW |