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_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/net_errors.h" | 8 #include "net/base/net_errors.h" |
9 | 9 |
10 namespace net { | 10 namespace net { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 advance_to_next_element = true; | 58 advance_to_next_element = true; |
59 } else { | 59 } else { |
60 next_element_offset_ += bytes_copied; | 60 next_element_offset_ += bytes_copied; |
61 } | 61 } |
62 } else { | 62 } else { |
63 DCHECK(element.type() == UploadData::TYPE_FILE); | 63 DCHECK(element.type() == UploadData::TYPE_FILE); |
64 | 64 |
65 if (!next_element_stream_.IsOpen()) { | 65 if (!next_element_stream_.IsOpen()) { |
66 int flags = base::PLATFORM_FILE_OPEN | | 66 int flags = base::PLATFORM_FILE_OPEN | |
67 base::PLATFORM_FILE_READ; | 67 base::PLATFORM_FILE_READ; |
68 int rv = next_element_stream_.Open( | 68 int rv = next_element_stream_.Open(element.file_path(), flags); |
69 FilePath::FromWStringHack(element.file_path()), flags); | |
70 // If the file does not exist, that's technically okay.. we'll just | 69 // If the file does not exist, that's technically okay.. we'll just |
71 // upload an empty file. This is for consistency with Mozilla. | 70 // upload an empty file. This is for consistency with Mozilla. |
72 DLOG_IF(WARNING, rv != OK) << "Failed to open \"" << | 71 DLOG_IF(WARNING, rv != OK) << "Failed to open \"" |
73 element.file_path() << "\" for reading: " << rv; | 72 << element.file_path().value() |
| 73 << "\" for reading: " << rv; |
74 | 74 |
75 next_element_remaining_ = 0; // Default to reading nothing. | 75 next_element_remaining_ = 0; // Default to reading nothing. |
76 if (rv == OK) { | 76 if (rv == OK) { |
77 uint64 offset = element.file_range_offset(); | 77 uint64 offset = element.file_range_offset(); |
78 if (offset && next_element_stream_.Seek(FROM_BEGIN, offset) < 0) { | 78 if (offset && next_element_stream_.Seek(FROM_BEGIN, offset) < 0) { |
79 DLOG(WARNING) << "Failed to seek \"" << element.file_path() << | 79 DLOG(WARNING) << "Failed to seek \"" << element.file_path().value() |
80 "\" to offset: " << offset; | 80 << "\" to offset: " << offset; |
81 } else { | 81 } else { |
82 next_element_remaining_ = element.file_range_length(); | 82 next_element_remaining_ = element.file_range_length(); |
83 } | 83 } |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 int rv = 0; | 87 int rv = 0; |
88 int count = static_cast<int>(std::min( | 88 int count = static_cast<int>(std::min( |
89 static_cast<uint64>(size_remaining), next_element_remaining_)); | 89 static_cast<uint64>(size_remaining), next_element_remaining_)); |
90 if (count > 0 && | 90 if (count > 0 && |
91 (rv = next_element_stream_.Read(buf_ + buf_len_, count, NULL)) > 0) { | 91 (rv = next_element_stream_.Read(buf_ + buf_len_, count, NULL)) > 0) { |
92 buf_len_ += rv; | 92 buf_len_ += rv; |
93 next_element_remaining_ -= rv; | 93 next_element_remaining_ -= rv; |
94 } else { | 94 } else { |
95 advance_to_next_element = true; | 95 advance_to_next_element = true; |
96 } | 96 } |
97 } | 97 } |
98 | 98 |
99 if (advance_to_next_element) { | 99 if (advance_to_next_element) { |
100 ++next_element_; | 100 ++next_element_; |
101 next_element_offset_ = 0; | 101 next_element_offset_ = 0; |
102 next_element_stream_.Close(); | 102 next_element_stream_.Close(); |
103 } | 103 } |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 } // namespace net | 107 } // namespace net |
OLD | NEW |