| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/url_request/url_request_file_dir_job.h" | 5 #include "net/url_request/url_request_file_dir_job.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
| 12 #include "net/base/net_util.h" | 12 #include "net/base/net_util.h" |
| 13 #include "net/url_request/url_request.h" | 13 #include "net/url_request/url_request.h" |
| 14 | 14 |
| 15 #if defined(OS_POSIX) | 15 #if defined(OS_POSIX) |
| 16 #include <sys/stat.h> | 16 #include <sys/stat.h> |
| 17 #endif | 17 #endif |
| 18 | 18 |
| 19 using std::string; | 19 using std::string; |
| 20 | 20 |
| 21 URLRequestFileDirJob::URLRequestFileDirJob(URLRequest* request, | 21 URLRequestFileDirJob::URLRequestFileDirJob(URLRequest* request, |
| 22 const FilePath& dir_path) | 22 const FilePath& dir_path) |
| 23 : URLRequestJob(request), | 23 : URLRequestJob(request), |
| 24 dir_path_(dir_path), | 24 dir_path_(dir_path), |
| 25 canceled_(false), | 25 canceled_(false), |
| 26 list_complete_(false), | 26 list_complete_(false), |
| 27 wrote_header_(false), | 27 wrote_header_(false), |
| 28 read_pending_(false), | 28 read_pending_(false), |
| 29 read_buffer_(NULL), | |
| 30 read_buffer_length_(0) { | 29 read_buffer_length_(0) { |
| 31 } | 30 } |
| 32 | 31 |
| 33 URLRequestFileDirJob::~URLRequestFileDirJob() { | 32 URLRequestFileDirJob::~URLRequestFileDirJob() { |
| 34 DCHECK(read_pending_ == false); | 33 DCHECK(read_pending_ == false); |
| 35 DCHECK(lister_ == NULL); | 34 DCHECK(lister_ == NULL); |
| 36 } | 35 } |
| 37 | 36 |
| 38 void URLRequestFileDirJob::Start() { | 37 void URLRequestFileDirJob::Start() { |
| 39 // Start reading asynchronously so that all error reporting and data | 38 // Start reading asynchronously so that all error reporting and data |
| (...skipping 21 matching lines...) Expand all Loading... |
| 61 | 60 |
| 62 canceled_ = true; | 61 canceled_ = true; |
| 63 | 62 |
| 64 // Don't call CloseLister or dispatch an error to the URLRequest because we | 63 // Don't call CloseLister or dispatch an error to the URLRequest because we |
| 65 // want OnListDone to be called to also write the error to the output stream. | 64 // want OnListDone to be called to also write the error to the output stream. |
| 66 // OnListDone will notify the URLRequest at this time. | 65 // OnListDone will notify the URLRequest at this time. |
| 67 if (lister_) | 66 if (lister_) |
| 68 lister_->Cancel(); | 67 lister_->Cancel(); |
| 69 } | 68 } |
| 70 | 69 |
| 71 bool URLRequestFileDirJob::ReadRawData(char* buf, int buf_size, | 70 bool URLRequestFileDirJob::ReadRawData(net::IOBuffer* buf, int buf_size, |
| 72 int *bytes_read) { | 71 int *bytes_read) { |
| 73 DCHECK(bytes_read); | 72 DCHECK(bytes_read); |
| 74 *bytes_read = 0; | 73 *bytes_read = 0; |
| 75 | 74 |
| 76 if (is_done()) | 75 if (is_done()) |
| 77 return true; | 76 return true; |
| 78 | 77 |
| 79 if (FillReadBuffer(buf, buf_size, bytes_read)) | 78 if (FillReadBuffer(buf->data(), buf_size, bytes_read)) |
| 80 return true; | 79 return true; |
| 81 | 80 |
| 82 // We are waiting for more data | 81 // We are waiting for more data |
| 83 read_pending_ = true; | 82 read_pending_ = true; |
| 84 read_buffer_ = buf; | 83 read_buffer_ = buf; |
| 85 read_buffer_length_ = buf_size; | 84 read_buffer_length_ = buf_size; |
| 86 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 85 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
| 87 return false; | 86 return false; |
| 88 } | 87 } |
| 89 | 88 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 } else if (list_complete_) { | 175 } else if (list_complete_) { |
| 177 // EOF | 176 // EOF |
| 178 return true; | 177 return true; |
| 179 } | 178 } |
| 180 return false; | 179 return false; |
| 181 } | 180 } |
| 182 | 181 |
| 183 void URLRequestFileDirJob::CompleteRead() { | 182 void URLRequestFileDirJob::CompleteRead() { |
| 184 if (read_pending_) { | 183 if (read_pending_) { |
| 185 int bytes_read; | 184 int bytes_read; |
| 186 if (FillReadBuffer(read_buffer_, read_buffer_length_, &bytes_read)) { | 185 if (FillReadBuffer(read_buffer_->data(), read_buffer_length_, |
| 186 &bytes_read)) { |
| 187 // We completed the read, so reset the read buffer. | 187 // We completed the read, so reset the read buffer. |
| 188 read_pending_ = false; | 188 read_pending_ = false; |
| 189 read_buffer_ = NULL; | 189 read_buffer_ = NULL; |
| 190 read_buffer_length_ = 0; | 190 read_buffer_length_ = 0; |
| 191 | 191 |
| 192 SetStatus(URLRequestStatus()); | 192 SetStatus(URLRequestStatus()); |
| 193 NotifyReadComplete(bytes_read); | 193 NotifyReadComplete(bytes_read); |
| 194 } else { | 194 } else { |
| 195 NOTREACHED(); | 195 NOTREACHED(); |
| 196 // TODO: Better error code. | 196 // TODO: Better error code. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 213 replacements.SetPathStr(new_path); | 213 replacements.SetPathStr(new_path); |
| 214 | 214 |
| 215 *location = request_->url().ReplaceComponents(replacements); | 215 *location = request_->url().ReplaceComponents(replacements); |
| 216 *http_status_code = 301; // simulate a permanent redirect | 216 *http_status_code = 301; // simulate a permanent redirect |
| 217 return true; | 217 return true; |
| 218 } | 218 } |
| 219 | 219 |
| 220 return false; | 220 return false; |
| 221 } | 221 } |
| 222 | 222 |
| OLD | NEW |