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 "webkit/blob/blob_url_request_job.h" | 5 #include "webkit/blob/blob_url_request_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 27 matching lines...) Expand all Loading... | |
38 static const char kHTTPPartialContentText[] = "Partial Content"; | 38 static const char kHTTPPartialContentText[] = "Partial Content"; |
39 static const char kHTTPNotAllowedText[] = "Not Allowed"; | 39 static const char kHTTPNotAllowedText[] = "Not Allowed"; |
40 static const char kHTTPNotFoundText[] = "Not Found"; | 40 static const char kHTTPNotFoundText[] = "Not Found"; |
41 static const char kHTTPMethodNotAllowText[] = "Method Not Allowed"; | 41 static const char kHTTPMethodNotAllowText[] = "Method Not Allowed"; |
42 static const char kHTTPRequestedRangeNotSatisfiableText[] = | 42 static const char kHTTPRequestedRangeNotSatisfiableText[] = |
43 "Requested Range Not Satisfiable"; | 43 "Requested Range Not Satisfiable"; |
44 static const char kHTTPInternalErrorText[] = "Internal Server Error"; | 44 static const char kHTTPInternalErrorText[] = "Internal Server Error"; |
45 | 45 |
46 static const int kFileOpenFlags = base::PLATFORM_FILE_OPEN | | 46 static const int kFileOpenFlags = base::PLATFORM_FILE_OPEN | |
47 base::PLATFORM_FILE_READ | | 47 base::PLATFORM_FILE_READ | |
48 base::PLATFORM_FILE_ASYNC; | 48 base::PLATFORM_FILE_ASYNC; |
satorux1
2012/02/07 18:06:27
async
| |
49 | 49 |
50 BlobURLRequestJob::BlobURLRequestJob( | 50 BlobURLRequestJob::BlobURLRequestJob( |
51 net::URLRequest* request, | 51 net::URLRequest* request, |
52 BlobData* blob_data, | 52 BlobData* blob_data, |
53 base::MessageLoopProxy* file_thread_proxy) | 53 base::MessageLoopProxy* file_thread_proxy) |
54 : net::URLRequestJob(request), | 54 : net::URLRequestJob(request), |
55 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 55 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
56 blob_data_(blob_data), | 56 blob_data_(blob_data), |
57 file_thread_proxy_(file_thread_proxy), | 57 file_thread_proxy_(file_thread_proxy), |
58 item_index_(0), | 58 item_index_(0), |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 return; | 95 return; |
96 } | 96 } |
97 | 97 |
98 CountSize(); | 98 CountSize(); |
99 } | 99 } |
100 | 100 |
101 void BlobURLRequestJob::CloseStream() { | 101 void BlobURLRequestJob::CloseStream() { |
102 if (stream_ != NULL) { | 102 if (stream_ != NULL) { |
103 // stream_.Close() blocks the IO thread, see http://crbug.com/75548. | 103 // stream_.Close() blocks the IO thread, see http://crbug.com/75548. |
104 base::ThreadRestrictions::ScopedAllowIO allow_io; | 104 base::ThreadRestrictions::ScopedAllowIO allow_io; |
105 stream_->Close(); | 105 stream_->CloseSync(); |
106 stream_.reset(NULL); | 106 stream_.reset(NULL); |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 void BlobURLRequestJob::Kill() { | 110 void BlobURLRequestJob::Kill() { |
111 CloseStream(); | 111 CloseStream(); |
112 | 112 |
113 net::URLRequestJob::Kill(); | 113 net::URLRequestJob::Kill(); |
114 weak_factory_.InvalidateWeakPtrs(); | 114 weak_factory_.InvalidateWeakPtrs(); |
115 } | 115 } |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 | 322 |
323 void BlobURLRequestJob::DidOpen(base::PlatformFileError rv, | 323 void BlobURLRequestJob::DidOpen(base::PlatformFileError rv, |
324 base::PassPlatformFile file, | 324 base::PassPlatformFile file, |
325 bool created) { | 325 bool created) { |
326 if (rv != base::PLATFORM_FILE_OK) { | 326 if (rv != base::PLATFORM_FILE_OK) { |
327 NotifyFailure(net::ERR_FAILED); | 327 NotifyFailure(net::ERR_FAILED); |
328 return; | 328 return; |
329 } | 329 } |
330 | 330 |
331 DCHECK(!stream_.get()); | 331 DCHECK(!stream_.get()); |
332 stream_.reset(new net::FileStream(file.ReleaseValue(), kFileOpenFlags, NULL)); | 332 stream_.reset(new net::FileStream(file.ReleaseValue(), kFileOpenFlags, NULL)); |
satorux1
2012/02/07 18:06:27
async.
| |
333 | 333 |
334 const BlobData::Item& item = blob_data_->items().at(item_index_); | 334 const BlobData::Item& item = blob_data_->items().at(item_index_); |
335 { | 335 { |
336 // stream_.Seek() blocks the IO thread, see http://crbug.com/75548. | 336 // stream_.Seek() blocks the IO thread, see http://crbug.com/75548. |
337 base::ThreadRestrictions::ScopedAllowIO allow_io; | 337 base::ThreadRestrictions::ScopedAllowIO allow_io; |
338 int64 offset = current_item_offset_ + static_cast<int64>(item.offset); | 338 int64 offset = current_item_offset_ + static_cast<int64>(item.offset); |
339 if (offset > 0 && offset != stream_->Seek(net::FROM_BEGIN, offset)) { | 339 if (offset > 0 && offset != stream_->Seek(net::FROM_BEGIN, offset)) { |
340 NotifyFailure(net::ERR_FAILED); | 340 NotifyFailure(net::ERR_FAILED); |
341 return; | 341 return; |
342 } | 342 } |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
560 // We don't support multiple range requests in one single URL request, | 560 // We don't support multiple range requests in one single URL request, |
561 // because we need to do multipart encoding here. | 561 // because we need to do multipart encoding here. |
562 // TODO(jianli): Support multipart byte range requests. | 562 // TODO(jianli): Support multipart byte range requests. |
563 NotifyFailure(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); | 563 NotifyFailure(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); |
564 } | 564 } |
565 } | 565 } |
566 } | 566 } |
567 } | 567 } |
568 | 568 |
569 } // namespace webkit_blob | 569 } // namespace webkit_blob |
OLD | NEW |