Revert 97987 - Switching NaCl IRT to be built inside the chrome build.
[chromium-blink-merge.git] / net / url_request / url_request_simple_job.cc
blobf137490238a33002a98b901cf59ba721417074bd
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/url_request/url_request_simple_job.h"
7 #include "base/compiler_specific.h"
8 #include "base/message_loop.h"
9 #include "net/base/io_buffer.h"
10 #include "net/base/net_errors.h"
11 #include "net/url_request/url_request_status.h"
13 namespace net {
15 URLRequestSimpleJob::URLRequestSimpleJob(URLRequest* request)
16 : URLRequestJob(request),
17 data_offset_(0),
18 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {}
20 void URLRequestSimpleJob::Start() {
21 // Start reading asynchronously so that all error reporting and data
22 // callbacks happen as they would for network requests.
23 MessageLoop::current()->PostTask(
24 FROM_HERE,
25 method_factory_.NewRunnableMethod(&URLRequestSimpleJob::StartAsync));
28 bool URLRequestSimpleJob::GetMimeType(std::string* mime_type) const {
29 *mime_type = mime_type_;
30 return true;
33 bool URLRequestSimpleJob::GetCharset(std::string* charset) {
34 *charset = charset_;
35 return true;
38 URLRequestSimpleJob::~URLRequestSimpleJob() {}
40 bool URLRequestSimpleJob::ReadRawData(IOBuffer* buf, int buf_size,
41 int* bytes_read) {
42 DCHECK(bytes_read);
43 int remaining = static_cast<int>(data_.size()) - data_offset_;
44 if (buf_size > remaining)
45 buf_size = remaining;
46 memcpy(buf->data(), data_.data() + data_offset_, buf_size);
47 data_offset_ += buf_size;
48 *bytes_read = buf_size;
49 return true;
52 void URLRequestSimpleJob::StartAsync() {
53 if (!request_)
54 return;
56 if (GetData(&mime_type_, &charset_, &data_)) {
57 // Notify that the headers are complete
58 NotifyHeadersComplete();
59 } else {
60 // what should the error code be?
61 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED,
62 ERR_INVALID_URL));
66 } // namespace net