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 // For loading files, we make use of overlapped i/o to ensure that reading from | 5 // For loading files, we make use of overlapped i/o to ensure that reading from |
6 // the filesystem (e.g., a network filesystem) does not block the calling | 6 // the filesystem (e.g., a network filesystem) does not block the calling |
7 // thread. An alternative approach would be to use a background thread or pool | 7 // thread. An alternative approach would be to use a background thread or pool |
8 // of threads, but it seems better to leverage the operating system's ability | 8 // of threads, but it seems better to leverage the operating system's ability |
9 // to do background file reads for us. | 9 // to do background file reads for us. |
10 // | 10 // |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 void URLRequestFileJob::Kill() { | 80 void URLRequestFileJob::Kill() { |
81 stream_.reset(); | 81 stream_.reset(); |
82 weak_ptr_factory_.InvalidateWeakPtrs(); | 82 weak_ptr_factory_.InvalidateWeakPtrs(); |
83 | 83 |
84 URLRequestJob::Kill(); | 84 URLRequestJob::Kill(); |
85 } | 85 } |
86 | 86 |
87 bool URLRequestFileJob::ReadRawData(IOBuffer* dest, | 87 bool URLRequestFileJob::ReadRawData(IOBuffer* dest, |
88 int dest_size, | 88 int dest_size, |
89 int* bytes_read) { | 89 int* bytes_read) { |
| 90 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. |
| 91 tracked_objects::ScopedTracker tracking_profile( |
| 92 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 93 "423948 URLRequestFileJob::ReadRawData")); |
| 94 |
90 DCHECK_NE(dest_size, 0); | 95 DCHECK_NE(dest_size, 0); |
91 DCHECK(bytes_read); | 96 DCHECK(bytes_read); |
92 DCHECK_GE(remaining_bytes_, 0); | 97 DCHECK_GE(remaining_bytes_, 0); |
93 | 98 |
94 if (remaining_bytes_ < dest_size) | 99 if (remaining_bytes_ < dest_size) |
95 dest_size = static_cast<int>(remaining_bytes_); | 100 dest_size = static_cast<int>(remaining_bytes_); |
96 | 101 |
97 // If we should copy zero bytes because |remaining_bytes_| is zero, short | 102 // If we should copy zero bytes because |remaining_bytes_| is zero, short |
98 // circuit here. | 103 // circuit here. |
99 if (!dest_size) { | 104 if (!dest_size) { |
100 *bytes_read = 0; | 105 *bytes_read = 0; |
101 return true; | 106 return true; |
102 } | 107 } |
103 | 108 |
104 int rv = stream_->Read(dest, | 109 int rv = stream_->Read(dest, |
105 dest_size, | 110 dest_size, |
106 base::Bind(&URLRequestFileJob::DidRead, | 111 base::Bind(&URLRequestFileJob::DidRead, |
107 weak_ptr_factory_.GetWeakPtr(), | 112 weak_ptr_factory_.GetWeakPtr(), |
108 make_scoped_refptr(dest))); | 113 make_scoped_refptr(dest))); |
| 114 |
| 115 // TODO(vadimt): Remove ScopedTracker below once crbug.com/423948 is fixed. |
| 116 tracked_objects::ScopedTracker tracking_profile1( |
| 117 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 118 "423948 URLRequestFileJob::ReadRawData1")); |
| 119 |
109 if (rv >= 0) { | 120 if (rv >= 0) { |
110 // Data is immediately available. | 121 // Data is immediately available. |
111 *bytes_read = rv; | 122 *bytes_read = rv; |
112 remaining_bytes_ -= rv; | 123 remaining_bytes_ -= rv; |
113 DCHECK_GE(remaining_bytes_, 0); | 124 DCHECK_GE(remaining_bytes_, 0); |
114 return true; | 125 return true; |
115 } | 126 } |
116 | 127 |
117 // Otherwise, a read error occured. We may just need to wait... | 128 // Otherwise, a read error occured. We may just need to wait... |
118 if (rv == ERR_IO_PENDING) { | 129 if (rv == ERR_IO_PENDING) { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 if (result == 0) { | 328 if (result == 0) { |
318 NotifyDone(URLRequestStatus()); | 329 NotifyDone(URLRequestStatus()); |
319 } else if (result < 0) { | 330 } else if (result < 0) { |
320 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); | 331 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); |
321 } | 332 } |
322 | 333 |
323 NotifyReadComplete(result); | 334 NotifyReadComplete(result); |
324 } | 335 } |
325 | 336 |
326 } // namespace net | 337 } // namespace net |
OLD | NEW |