blob: 1b5938456e77123726c7c8eca08c31a6d251109e [file] [log] [blame]
[email protected]36ffc7342012-07-23 17:15:101// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit586acc5fe2008-07-26 22:42:524
[email protected]319d9e6f2009-02-18 19:47:215#ifndef NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_
6#define NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_
initial.commit586acc5fe2008-07-26 22:42:527
Avi Drissman13fc8932015-12-20 04:40:468#include <stdint.h>
9
[email protected]60c413c92009-03-09 16:53:3110#include <string>
11
jyasskin3edf2fe2014-11-17 18:44:0712#include "base/memory/ref_counted.h"
[email protected]098b29112011-12-20 21:12:3413#include "base/memory/weak_ptr.h"
jyasskin3edf2fe2014-11-17 18:44:0714#include "base/strings/string_piece.h"
[email protected]36ffc7342012-07-23 17:15:1015#include "net/base/completion_callback.h"
[email protected]172da1b2011-08-12 15:52:2616#include "net/base/net_export.h"
[email protected]6a09a5a2014-01-14 11:16:1817#include "net/url_request/url_range_request_job.h"
initial.commit586acc5fe2008-07-26 22:42:5218
jyasskin3edf2fe2014-11-17 18:44:0719namespace base {
20class RefCountedMemory;
21}
22
[email protected]edfe7fab2010-11-28 13:11:5223namespace net {
[email protected]319d9e6f2009-02-18 19:47:2124
[email protected]86977552010-12-15 01:56:0325class URLRequest;
26
[email protected]6a09a5a2014-01-14 11:16:1827class NET_EXPORT URLRequestSimpleJob : public URLRangeRequestJob {
initial.commit586acc5fe2008-07-26 22:42:5228 public:
[email protected]9f170462012-08-24 01:06:5829 URLRequestSimpleJob(URLRequest* request, NetworkDelegate* network_delegate);
initial.commit586acc5fe2008-07-26 22:42:5230
dchengb03027d2014-10-21 12:00:2031 void Start() override;
mmenkefe5b5362015-08-07 18:34:5132 void Kill() override;
xunjieli26ede962015-11-23 19:39:1333 int ReadRawData(IOBuffer* buf, int buf_size) override;
dchengb03027d2014-10-21 12:00:2034 bool GetMimeType(std::string* mime_type) const override;
35 bool GetCharset(std::string* charset) override;
initial.commit586acc5fe2008-07-26 22:42:5236
37 protected:
dchengb03027d2014-10-21 12:00:2038 ~URLRequestSimpleJob() override;
[email protected]5389bc72009-11-05 23:34:2439
jyasskin3edf2fe2014-11-17 18:44:0740 // Subclasses must override either GetData or GetRefCountedData to define the
41 // way response data is determined.
[email protected]36ffc7342012-07-23 17:15:1042 // The return value should be:
43 // - OK if data is obtained;
44 // - ERR_IO_PENDING if async processing is needed to finish obtaining data.
45 // This is the only case when |callback| should be called after
46 // completion of the operation. In other situations |callback| should
47 // never be called;
48 // - any other ERR_* code to indicate an error. This code will be used
49 // as the error code in the URLRequestStatus when the URLRequest
50 // is finished.
51 virtual int GetData(std::string* mime_type,
52 std::string* charset,
53 std::string* data,
jyasskin3edf2fe2014-11-17 18:44:0754 const CompletionCallback& callback) const;
initial.commit586acc5fe2008-07-26 22:42:5255
jyasskin3edf2fe2014-11-17 18:44:0756 // Similar to GetData(), except |*data| can share ownership of the bytes
57 // instead of copying them into a std::string.
58 virtual int GetRefCountedData(std::string* mime_type,
59 std::string* charset,
60 scoped_refptr<base::RefCountedMemory>* data,
61 const CompletionCallback& callback) const;
62
initial.commit586acc5fe2008-07-26 22:42:5263 void StartAsync();
64
[email protected]042ecea2010-03-27 01:36:4365 private:
[email protected]36ffc7342012-07-23 17:15:1066 void OnGetDataCompleted(int result);
67
[email protected]6a09a5a2014-01-14 11:16:1868 HttpByteRange byte_range_;
initial.commit586acc5fe2008-07-26 22:42:5269 std::string mime_type_;
70 std::string charset_;
jyasskin3edf2fe2014-11-17 18:44:0771 scoped_refptr<base::RefCountedMemory> data_;
Avi Drissman13fc8932015-12-20 04:40:4672 int64_t next_data_offset_;
[email protected]098b29112011-12-20 21:12:3473 base::WeakPtrFactory<URLRequestSimpleJob> weak_factory_;
initial.commit586acc5fe2008-07-26 22:42:5274};
75
[email protected]86977552010-12-15 01:56:0376} // namespace net
77
[email protected]e2a23092009-03-17 15:35:1878#endif // NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_