blob: 633a2e7af47755b5ba5c0f7d379cbce4addc3a05 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// Copyright (c) 2012 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.
4
5#ifndef NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_
6#define NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_
7
8#include <string>
9
10#include "base/memory/weak_ptr.h"
11#include "net/base/completion_callback.h"
12#include "net/base/net_export.h"
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000013#include "net/url_request/url_range_request_job.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000014
15namespace net {
16
17class URLRequest;
18
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000019class NET_EXPORT URLRequestSimpleJob : public URLRangeRequestJob {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000020 public:
21 URLRequestSimpleJob(URLRequest* request, NetworkDelegate* network_delegate);
22
23 virtual void Start() OVERRIDE;
24 virtual bool ReadRawData(IOBuffer* buf,
25 int buf_size,
26 int *bytes_read) OVERRIDE;
27 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
28 virtual bool GetCharset(std::string* charset) OVERRIDE;
29
30 protected:
31 virtual ~URLRequestSimpleJob();
32
33 // Subclasses must override the way response data is determined.
34 // The return value should be:
35 // - OK if data is obtained;
36 // - ERR_IO_PENDING if async processing is needed to finish obtaining data.
37 // This is the only case when |callback| should be called after
38 // completion of the operation. In other situations |callback| should
39 // never be called;
40 // - any other ERR_* code to indicate an error. This code will be used
41 // as the error code in the URLRequestStatus when the URLRequest
42 // is finished.
43 virtual int GetData(std::string* mime_type,
44 std::string* charset,
45 std::string* data,
46 const CompletionCallback& callback) const = 0;
47
48 protected:
49 void StartAsync();
50
51 private:
52 void OnGetDataCompleted(int result);
53
Torne (Richard Coles)5d1f7b12014-02-21 12:16:55 +000054 HttpByteRange byte_range_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000055 std::string mime_type_;
56 std::string charset_;
57 std::string data_;
58 int data_offset_;
59 base::WeakPtrFactory<URLRequestSimpleJob> weak_factory_;
60};
61
62} // namespace net
63
64#endif // NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_