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"
15 URLRequestSimpleJob::URLRequestSimpleJob(URLRequest
* request
)
16 : URLRequestJob(request
),
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(
25 method_factory_
.NewRunnableMethod(&URLRequestSimpleJob::StartAsync
));
28 bool URLRequestSimpleJob::GetMimeType(std::string
* mime_type
) const {
29 *mime_type
= mime_type_
;
33 bool URLRequestSimpleJob::GetCharset(std::string
* charset
) {
38 URLRequestSimpleJob::~URLRequestSimpleJob() {}
40 bool URLRequestSimpleJob::ReadRawData(IOBuffer
* buf
, int buf_size
,
43 int remaining
= static_cast<int>(data_
.size()) - data_offset_
;
44 if (buf_size
> remaining
)
46 memcpy(buf
->data(), data_
.data() + data_offset_
, buf_size
);
47 data_offset_
+= buf_size
;
48 *bytes_read
= buf_size
;
52 void URLRequestSimpleJob::StartAsync() {
56 if (GetData(&mime_type_
, &charset_
, &data_
)) {
57 // Notify that the headers are complete
58 NotifyHeadersComplete();
60 // what should the error code be?
61 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED
,