Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: net/base/upload_data_stream.cc

Issue 9321003: net: Make UploadData::GetContentLength() asynchronous. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/upload_data.cc ('k') | net/base/upload_data_stream_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_stream.h" 5 #include "net/base/upload_data_stream.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 #include "base/threading/thread_restrictions.h" 9 #include "base/threading/thread_restrictions.h"
10 #include "net/base/file_stream.h" 10 #include "net/base/file_stream.h"
(...skipping 13 matching lines...) Expand all
24 current_position_(0), 24 current_position_(0),
25 initialized_successfully_(false) { 25 initialized_successfully_(false) {
26 } 26 }
27 27
28 UploadDataStream::~UploadDataStream() { 28 UploadDataStream::~UploadDataStream() {
29 } 29 }
30 30
31 int UploadDataStream::Init() { 31 int UploadDataStream::Init() {
32 DCHECK(!initialized_successfully_); 32 DCHECK(!initialized_successfully_);
33 33
34 total_size_ = upload_data_->GetContentLength(); 34 {
35 base::ThreadRestrictions::ScopedAllowIO allow_io;
36 total_size_ = upload_data_->GetContentLengthSync();
37 }
35 38
36 // If the underlying file has been changed and the expected file 39 // If the underlying file has been changed and the expected file
37 // modification time is set, treat it as error. Note that the expected 40 // modification time is set, treat it as error. Note that the expected
38 // modification time from WebKit is based on time_t precision. So we 41 // modification time from WebKit is based on time_t precision. So we
39 // have to convert both to time_t to compare. This check is used for 42 // have to convert both to time_t to compare. This check is used for
40 // sliced files. 43 // sliced files.
41 const std::vector<UploadData::Element>& elements = *upload_data_->elements(); 44 const std::vector<UploadData::Element>& elements = *upload_data_->elements();
42 for (size_t i = 0; i < elements.size(); ++i) { 45 for (size_t i = 0; i < elements.size(); ++i) {
43 const UploadData::Element& element = elements[i]; 46 const UploadData::Element& element = elements[i];
44 if (element.type() == UploadData::TYPE_FILE && 47 if (element.type() == UploadData::TYPE_FILE &&
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 // Advance to the next element if we have consumed all data in the 94 // Advance to the next element if we have consumed all data in the
92 // current element. 95 // current element.
93 if (element_offset_ == element_data.size()) 96 if (element_offset_ == element_data.size())
94 advance_to_next_element = true; 97 advance_to_next_element = true;
95 } else { 98 } else {
96 DCHECK(element.type() == UploadData::TYPE_FILE); 99 DCHECK(element.type() == UploadData::TYPE_FILE);
97 100
98 // Open the file of the current element if not yet opened. 101 // Open the file of the current element if not yet opened.
99 if (!element_file_stream_.get()) { 102 if (!element_file_stream_.get()) {
100 element_file_bytes_remaining_ = element.GetContentLength(); 103 element_file_bytes_remaining_ = element.GetContentLength();
104 // Temporarily allow until fix: http://crbug.com/72001.
105 base::ThreadRestrictions::ScopedAllowIO allow_io;
101 element_file_stream_.reset(element.NewFileStreamForReading()); 106 element_file_stream_.reset(element.NewFileStreamForReading());
102 } 107 }
103 108
104 const int num_bytes_to_read = 109 const int num_bytes_to_read =
105 static_cast<int>(std::min(element_file_bytes_remaining_, 110 static_cast<int>(std::min(element_file_bytes_remaining_,
106 static_cast<uint64>(free_buffer_space))); 111 static_cast<uint64>(free_buffer_space)));
107 if (num_bytes_to_read > 0) { 112 if (num_bytes_to_read > 0) {
108 int num_bytes_consumed = 0; 113 int num_bytes_consumed = 0;
109 // Temporarily allow until fix: http://crbug.com/72001. 114 // Temporarily allow until fix: http://crbug.com/72001.
110 base::ThreadRestrictions::ScopedAllowIO allow_io; 115 base::ThreadRestrictions::ScopedAllowIO allow_io;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 return false; 179 return false;
175 } 180 }
176 181
177 bool UploadDataStream::IsInMemory() const { 182 bool UploadDataStream::IsInMemory() const {
178 DCHECK(initialized_successfully_); 183 DCHECK(initialized_successfully_);
179 184
180 return upload_data_->IsInMemory(); 185 return upload_data_->IsInMemory();
181 } 186 }
182 187
183 } // namespace net 188 } // namespace net
OLDNEW
« no previous file with comments | « net/base/upload_data.cc ('k') | net/base/upload_data_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698