| 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/net_errors.h" | 8 #include "net/base/net_errors.h" |
| 9 | 9 |
| 10 URLRequestSimpleJob::URLRequestSimpleJob(URLRequest* request) | 10 URLRequestSimpleJob::URLRequestSimpleJob(URLRequest* request) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 bool URLRequestSimpleJob::GetMimeType(std::string* mime_type) { | 22 bool URLRequestSimpleJob::GetMimeType(std::string* mime_type) { |
| 23 *mime_type = mime_type_; | 23 *mime_type = mime_type_; |
| 24 return true; | 24 return true; |
| 25 } | 25 } |
| 26 | 26 |
| 27 bool URLRequestSimpleJob::GetCharset(std::string* charset) { | 27 bool URLRequestSimpleJob::GetCharset(std::string* charset) { |
| 28 *charset = charset_; | 28 *charset = charset_; |
| 29 return true; | 29 return true; |
| 30 } | 30 } |
| 31 | 31 |
| 32 bool URLRequestSimpleJob::ReadRawData(char* buf, int buf_size, | 32 bool URLRequestSimpleJob::ReadRawData(net::IOBuffer* buf, int buf_size, |
| 33 int* bytes_read) { | 33 int* bytes_read) { |
| 34 DCHECK(bytes_read); | 34 DCHECK(bytes_read); |
| 35 int remaining = static_cast<int>(data_.size()) - data_offset_; | 35 int remaining = static_cast<int>(data_.size()) - data_offset_; |
| 36 if (buf_size > remaining) | 36 if (buf_size > remaining) |
| 37 buf_size = remaining; | 37 buf_size = remaining; |
| 38 memcpy(buf, data_.data() + data_offset_, buf_size); | 38 memcpy(buf->data(), data_.data() + data_offset_, buf_size); |
| 39 data_offset_ += buf_size; | 39 data_offset_ += buf_size; |
| 40 *bytes_read = buf_size; | 40 *bytes_read = buf_size; |
| 41 return true; | 41 return true; |
| 42 } | 42 } |
| 43 | 43 |
| 44 void URLRequestSimpleJob::StartAsync() { | 44 void URLRequestSimpleJob::StartAsync() { |
| 45 if (!request_) | 45 if (!request_) |
| 46 return; | 46 return; |
| 47 | 47 |
| 48 if (GetData(&mime_type_, &charset_, &data_)) { | 48 if (GetData(&mime_type_, &charset_, &data_)) { |
| 49 // Notify that the headers are complete | 49 // Notify that the headers are complete |
| 50 NotifyHeadersComplete(); | 50 NotifyHeadersComplete(); |
| 51 } else { | 51 } else { |
| 52 // what should the error code be? | 52 // what should the error code be? |
| 53 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, | 53 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, |
| 54 net::ERR_INVALID_URL)); | 54 net::ERR_INVALID_URL)); |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| OLD | NEW |