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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 107 } |
108 | 108 |
109 NOTREACHED(); | 109 NOTREACHED(); |
110 return 0; | 110 return 0; |
111 } | 111 } |
112 | 112 |
113 uint64 UploadData::Element::BytesRemaining() { | 113 uint64 UploadData::Element::BytesRemaining() { |
114 return GetContentLength() - offset_; | 114 return GetContentLength() - offset_; |
115 } | 115 } |
116 | 116 |
117 void UploadData::Element::ResetOffset() { | |
118 offset_ = 0; | |
119 | |
120 // Delete the file stream if already opened, so we can reread the file from | |
121 // the beginning. | |
122 if (file_stream_) { | |
123 // Temporarily allow until fix: http://crbug.com/72001. | |
124 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
125 file_stream_->CloseSync(); | |
126 delete file_stream_; | |
127 file_stream_ = NULL; | |
128 } | |
129 } | |
130 | |
131 FileStream* UploadData::Element::OpenFileStream() { | 117 FileStream* UploadData::Element::OpenFileStream() { |
132 scoped_ptr<FileStream> file(new FileStream(NULL)); | 118 scoped_ptr<FileStream> file(new FileStream(NULL)); |
133 int64 rv = file->OpenSync( | 119 int64 rv = file->OpenSync( |
134 file_path_, | 120 file_path_, |
135 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ); | 121 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ); |
136 if (rv != OK) { | 122 if (rv != OK) { |
137 // If the file can't be opened, we'll just upload an empty file. | 123 // If the file can't be opened, we'll just upload an empty file. |
138 DLOG(WARNING) << "Failed to open \"" << file_path_.value() | 124 DLOG(WARNING) << "Failed to open \"" << file_path_.value() |
139 << "\" for reading: " << rv; | 125 << "\" for reading: " << rv; |
140 return NULL; | 126 return NULL; |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 return; | 285 return; |
300 | 286 |
301 for (size_t i = 0; i < elements_.size(); ++i) | 287 for (size_t i = 0; i < elements_.size(); ++i) |
302 *content_length += elements_[i].GetContentLength(); | 288 *content_length += elements_[i].GetContentLength(); |
303 } | 289 } |
304 | 290 |
305 UploadData::~UploadData() { | 291 UploadData::~UploadData() { |
306 } | 292 } |
307 | 293 |
308 } // namespace net | 294 } // namespace net |
OLD | NEW |