| 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_simple_job.h" | 5 #include "net/url_request/url_request_simple_job.h" |
| 6 | 6 |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "net/base/io_buffer.h" | 8 #include "net/base/io_buffer.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/url_request/url_request_status.h" | 10 #include "net/url_request/url_request_status.h" |
| 11 | 11 |
| 12 URLRequestSimpleJob::URLRequestSimpleJob(net::URLRequest* request) | 12 namespace net { |
| 13 : net::URLRequestJob(request), | 13 |
| 14 URLRequestSimpleJob::URLRequestSimpleJob(URLRequest* request) |
| 15 : URLRequestJob(request), |
| 14 data_offset_(0) { | 16 data_offset_(0) { |
| 15 } | 17 } |
| 16 | 18 |
| 17 void URLRequestSimpleJob::Start() { | 19 void URLRequestSimpleJob::Start() { |
| 18 // Start reading asynchronously so that all error reporting and data | 20 // Start reading asynchronously so that all error reporting and data |
| 19 // callbacks happen as they would for network requests. | 21 // callbacks happen as they would for network requests. |
| 20 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 22 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 21 this, &URLRequestSimpleJob::StartAsync)); | 23 this, &URLRequestSimpleJob::StartAsync)); |
| 22 } | 24 } |
| 23 | 25 |
| 24 bool URLRequestSimpleJob::GetMimeType(std::string* mime_type) const { | 26 bool URLRequestSimpleJob::GetMimeType(std::string* mime_type) const { |
| 25 *mime_type = mime_type_; | 27 *mime_type = mime_type_; |
| 26 return true; | 28 return true; |
| 27 } | 29 } |
| 28 | 30 |
| 29 bool URLRequestSimpleJob::GetCharset(std::string* charset) { | 31 bool URLRequestSimpleJob::GetCharset(std::string* charset) { |
| 30 *charset = charset_; | 32 *charset = charset_; |
| 31 return true; | 33 return true; |
| 32 } | 34 } |
| 33 | 35 |
| 34 bool URLRequestSimpleJob::ReadRawData(net::IOBuffer* buf, int buf_size, | 36 bool URLRequestSimpleJob::ReadRawData(IOBuffer* buf, int buf_size, |
| 35 int* bytes_read) { | 37 int* bytes_read) { |
| 36 DCHECK(bytes_read); | 38 DCHECK(bytes_read); |
| 37 int remaining = static_cast<int>(data_.size()) - data_offset_; | 39 int remaining = static_cast<int>(data_.size()) - data_offset_; |
| 38 if (buf_size > remaining) | 40 if (buf_size > remaining) |
| 39 buf_size = remaining; | 41 buf_size = remaining; |
| 40 memcpy(buf->data(), data_.data() + data_offset_, buf_size); | 42 memcpy(buf->data(), data_.data() + data_offset_, buf_size); |
| 41 data_offset_ += buf_size; | 43 data_offset_ += buf_size; |
| 42 *bytes_read = buf_size; | 44 *bytes_read = buf_size; |
| 43 return true; | 45 return true; |
| 44 } | 46 } |
| 45 | 47 |
| 46 void URLRequestSimpleJob::StartAsync() { | 48 void URLRequestSimpleJob::StartAsync() { |
| 47 if (!request_) | 49 if (!request_) |
| 48 return; | 50 return; |
| 49 | 51 |
| 50 if (GetData(&mime_type_, &charset_, &data_)) { | 52 if (GetData(&mime_type_, &charset_, &data_)) { |
| 51 // Notify that the headers are complete | 53 // Notify that the headers are complete |
| 52 NotifyHeadersComplete(); | 54 NotifyHeadersComplete(); |
| 53 } else { | 55 } else { |
| 54 // what should the error code be? | 56 // what should the error code be? |
| 55 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, | 57 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, |
| 56 net::ERR_INVALID_URL)); | 58 ERR_INVALID_URL)); |
| 57 } | 59 } |
| 58 } | 60 } |
| 61 |
| 62 } // namespace net |
| OLD | NEW |