[email protected] | 36ffc734 | 2012-07-23 17:15:10 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 319d9e6f | 2009-02-18 19:47:21 | [diff] [blame] | 5 | #ifndef NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_ |
6 | #define NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_ | ||||
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 7 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 8 | #include <stdint.h> |
9 | |||||
[email protected] | 60c413c9 | 2009-03-09 16:53:31 | [diff] [blame] | 10 | #include <string> |
11 | |||||
jyasskin | 3edf2fe | 2014-11-17 18:44:07 | [diff] [blame] | 12 | #include "base/memory/ref_counted.h" |
[email protected] | 098b2911 | 2011-12-20 21:12:34 | [diff] [blame] | 13 | #include "base/memory/weak_ptr.h" |
jyasskin | 3edf2fe | 2014-11-17 18:44:07 | [diff] [blame] | 14 | #include "base/strings/string_piece.h" |
[email protected] | 36ffc734 | 2012-07-23 17:15:10 | [diff] [blame] | 15 | #include "net/base/completion_callback.h" |
[email protected] | 172da1b | 2011-08-12 15:52:26 | [diff] [blame] | 16 | #include "net/base/net_export.h" |
[email protected] | 6a09a5a | 2014-01-14 11:16:18 | [diff] [blame] | 17 | #include "net/url_request/url_range_request_job.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 18 | |
jyasskin | 3edf2fe | 2014-11-17 18:44:07 | [diff] [blame] | 19 | namespace base { |
20 | class RefCountedMemory; | ||||
21 | } | ||||
22 | |||||
[email protected] | edfe7fab | 2010-11-28 13:11:52 | [diff] [blame] | 23 | namespace net { |
[email protected] | 319d9e6f | 2009-02-18 19:47:21 | [diff] [blame] | 24 | |
[email protected] | 8697755 | 2010-12-15 01:56:03 | [diff] [blame] | 25 | class URLRequest; |
26 | |||||
[email protected] | 6a09a5a | 2014-01-14 11:16:18 | [diff] [blame] | 27 | class NET_EXPORT URLRequestSimpleJob : public URLRangeRequestJob { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 28 | public: |
[email protected] | 9f17046 | 2012-08-24 01:06:58 | [diff] [blame] | 29 | URLRequestSimpleJob(URLRequest* request, NetworkDelegate* network_delegate); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 30 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 31 | void Start() override; |
mmenke | fe5b536 | 2015-08-07 18:34:51 | [diff] [blame] | 32 | void Kill() override; |
xunjieli | 26ede96 | 2015-11-23 19:39:13 | [diff] [blame] | 33 | int ReadRawData(IOBuffer* buf, int buf_size) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 34 | bool GetMimeType(std::string* mime_type) const override; |
35 | bool GetCharset(std::string* charset) override; | ||||
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 36 | |
37 | protected: | ||||
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 38 | ~URLRequestSimpleJob() override; |
[email protected] | 5389bc7 | 2009-11-05 23:34:24 | [diff] [blame] | 39 | |
jyasskin | 3edf2fe | 2014-11-17 18:44:07 | [diff] [blame] | 40 | // Subclasses must override either GetData or GetRefCountedData to define the |
41 | // way response data is determined. | ||||
[email protected] | 36ffc734 | 2012-07-23 17:15:10 | [diff] [blame] | 42 | // 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, | ||||
jyasskin | 3edf2fe | 2014-11-17 18:44:07 | [diff] [blame] | 54 | const CompletionCallback& callback) const; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 55 | |
jyasskin | 3edf2fe | 2014-11-17 18:44:07 | [diff] [blame] | 56 | // 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.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 63 | void StartAsync(); |
64 | |||||
[email protected] | 042ecea | 2010-03-27 01:36:43 | [diff] [blame] | 65 | private: |
[email protected] | 36ffc734 | 2012-07-23 17:15:10 | [diff] [blame] | 66 | void OnGetDataCompleted(int result); |
67 | |||||
[email protected] | 6a09a5a | 2014-01-14 11:16:18 | [diff] [blame] | 68 | HttpByteRange byte_range_; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 69 | std::string mime_type_; |
70 | std::string charset_; | ||||
jyasskin | 3edf2fe | 2014-11-17 18:44:07 | [diff] [blame] | 71 | scoped_refptr<base::RefCountedMemory> data_; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 72 | int64_t next_data_offset_; |
[email protected] | 098b2911 | 2011-12-20 21:12:34 | [diff] [blame] | 73 | base::WeakPtrFactory<URLRequestSimpleJob> weak_factory_; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 74 | }; |
75 | |||||
[email protected] | 8697755 | 2010-12-15 01:56:03 | [diff] [blame] | 76 | } // namespace net |
77 | |||||
[email protected] | e2a2309 | 2009-03-17 15:35:18 | [diff] [blame] | 78 | #endif // NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_ |