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/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 content_length_computed_(false), | 24 content_length_computed_(false), |
25 content_length_(-1), | 25 content_length_(-1), |
26 file_stream_(NULL) { | 26 file_stream_(NULL) { |
27 } | 27 } |
28 | 28 |
29 UploadData::Element::~Element() { | 29 UploadData::Element::~Element() { |
30 // In the common case |file__stream_| will be null. | 30 // In the common case |file__stream_| will be null. |
31 if (file_stream_) { | 31 if (file_stream_) { |
32 // Temporarily allow until fix: http://crbug.com/72001. | 32 // Temporarily allow until fix: http://crbug.com/72001. |
33 base::ThreadRestrictions::ScopedAllowIO allow_io; | 33 base::ThreadRestrictions::ScopedAllowIO allow_io; |
34 file_stream_->Close(); | 34 file_stream_->CloseSync(); |
35 delete file_stream_; | 35 delete file_stream_; |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
39 void UploadData::Element::SetToChunk(const char* bytes, | 39 void UploadData::Element::SetToChunk(const char* bytes, |
40 int bytes_len, | 40 int bytes_len, |
41 bool is_last_chunk) { | 41 bool is_last_chunk) { |
42 bytes_.clear(); | 42 bytes_.clear(); |
43 bytes_.insert(bytes_.end(), bytes, bytes + bytes_len); | 43 bytes_.insert(bytes_.end(), bytes, bytes + bytes_len); |
44 type_ = TYPE_CHUNK; | 44 type_ = TYPE_CHUNK; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 file_stream_ = NULL; | 100 file_stream_ = NULL; |
101 return file; | 101 return file; |
102 } | 102 } |
103 | 103 |
104 // TODO(tzik): | 104 // TODO(tzik): |
105 // FileStream::Open and FileStream::Seek may cause blocking IO. | 105 // FileStream::Open and FileStream::Seek may cause blocking IO. |
106 // Temporary allow until fix: http://crbug.com/72001. | 106 // Temporary allow until fix: http://crbug.com/72001. |
107 base::ThreadRestrictions::ScopedAllowIO allow_io; | 107 base::ThreadRestrictions::ScopedAllowIO allow_io; |
108 | 108 |
109 scoped_ptr<FileStream> file(new FileStream(NULL)); | 109 scoped_ptr<FileStream> file(new FileStream(NULL)); |
110 int64 rv = file->Open(file_path_, | 110 int64 rv = file->OpenSync( |
111 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ); | 111 file_path_, |
| 112 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ); |
112 if (rv != OK) { | 113 if (rv != OK) { |
113 // If the file can't be opened, we'll just upload an empty file. | 114 // If the file can't be opened, we'll just upload an empty file. |
114 DLOG(WARNING) << "Failed to open \"" << file_path_.value() | 115 DLOG(WARNING) << "Failed to open \"" << file_path_.value() |
115 << "\" for reading: " << rv; | 116 << "\" for reading: " << rv; |
116 return NULL; | 117 return NULL; |
117 } | 118 } |
118 if (file_range_offset_) { | 119 if (file_range_offset_) { |
119 rv = file->Seek(FROM_BEGIN, file_range_offset_); | 120 rv = file->Seek(FROM_BEGIN, file_range_offset_); |
120 if (rv < 0) { | 121 if (rv < 0) { |
121 DLOG(WARNING) << "Failed to seek \"" << file_path_.value() | 122 DLOG(WARNING) << "Failed to seek \"" << file_path_.value() |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 } | 200 } |
200 | 201 |
201 void UploadData::SetElements(const std::vector<Element>& elements) { | 202 void UploadData::SetElements(const std::vector<Element>& elements) { |
202 elements_ = elements; | 203 elements_ = elements; |
203 } | 204 } |
204 | 205 |
205 UploadData::~UploadData() { | 206 UploadData::~UploadData() { |
206 } | 207 } |
207 | 208 |
208 } // namespace net | 209 } // namespace net |
OLD | NEW |