OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_ |
6 #define NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | |
10 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/strings/string_piece.h" | |
11 #include "net/base/completion_callback.h" | 13 #include "net/base/completion_callback.h" |
12 #include "net/base/net_export.h" | 14 #include "net/base/net_export.h" |
13 #include "net/url_request/url_range_request_job.h" | 15 #include "net/url_request/url_range_request_job.h" |
14 | 16 |
17 namespace base { | |
18 class RefCountedMemory; | |
19 } | |
20 | |
15 namespace net { | 21 namespace net { |
16 | 22 |
17 class URLRequest; | 23 class URLRequest; |
18 | 24 |
19 class NET_EXPORT URLRequestSimpleJob : public URLRangeRequestJob { | 25 class NET_EXPORT URLRequestSimpleJob : public URLRangeRequestJob { |
20 public: | 26 public: |
21 URLRequestSimpleJob(URLRequest* request, NetworkDelegate* network_delegate); | 27 URLRequestSimpleJob(URLRequest* request, NetworkDelegate* network_delegate); |
22 | 28 |
23 void Start() override; | 29 void Start() override; |
24 bool ReadRawData(IOBuffer* buf, int buf_size, int* bytes_read) override; | 30 bool ReadRawData(IOBuffer* buf, int buf_size, int* bytes_read) override; |
25 bool GetMimeType(std::string* mime_type) const override; | 31 bool GetMimeType(std::string* mime_type) const override; |
26 bool GetCharset(std::string* charset) override; | 32 bool GetCharset(std::string* charset) override; |
27 | 33 |
28 protected: | 34 protected: |
29 ~URLRequestSimpleJob() override; | 35 ~URLRequestSimpleJob() override; |
30 | 36 |
31 // Subclasses must override the way response data is determined. | 37 // Subclasses must override the way response data is determined. |
mmenke
2014/11/17 15:54:10
Should mention subclasses must override only one o
Jeffrey Yasskin
2014/11/17 17:16:23
Done.
| |
32 // The return value should be: | 38 // The return value should be: |
33 // - OK if data is obtained; | 39 // - OK if data is obtained; |
34 // - ERR_IO_PENDING if async processing is needed to finish obtaining data. | 40 // - ERR_IO_PENDING if async processing is needed to finish obtaining data. |
35 // This is the only case when |callback| should be called after | 41 // This is the only case when |callback| should be called after |
36 // completion of the operation. In other situations |callback| should | 42 // completion of the operation. In other situations |callback| should |
37 // never be called; | 43 // never be called; |
38 // - any other ERR_* code to indicate an error. This code will be used | 44 // - any other ERR_* code to indicate an error. This code will be used |
39 // as the error code in the URLRequestStatus when the URLRequest | 45 // as the error code in the URLRequestStatus when the URLRequest |
40 // is finished. | 46 // is finished. |
41 virtual int GetData(std::string* mime_type, | 47 virtual int GetData(std::string* mime_type, |
42 std::string* charset, | 48 std::string* charset, |
43 std::string* data, | 49 std::string* data, |
44 const CompletionCallback& callback) const = 0; | 50 const CompletionCallback& callback) const; |
51 // Similar to GetData(), except *data can share ownership of the bytes instead | |
mmenke
2014/11/17 15:54:10
nit: |*data| or *|data|.
Jeffrey Yasskin
2014/11/17 17:16:23
Done.
| |
52 // of copying them into a std::string. | |
53 virtual int GetRefCountedData(std::string* mime_type, | |
54 std::string* charset, | |
55 scoped_refptr<base::RefCountedMemory>* data, | |
56 const CompletionCallback& callback) const; | |
45 | 57 |
46 protected: | 58 protected: |
47 void StartAsync(); | 59 void StartAsync(); |
48 | 60 |
49 private: | 61 private: |
50 void OnGetDataCompleted(int result); | 62 void OnGetDataCompleted(int result); |
51 | 63 |
52 HttpByteRange byte_range_; | 64 HttpByteRange byte_range_; |
53 std::string mime_type_; | 65 std::string mime_type_; |
54 std::string charset_; | 66 std::string charset_; |
55 std::string data_; | 67 scoped_refptr<base::RefCountedMemory> data_; |
56 int data_offset_; | 68 int data_offset_; |
57 base::WeakPtrFactory<URLRequestSimpleJob> weak_factory_; | 69 base::WeakPtrFactory<URLRequestSimpleJob> weak_factory_; |
58 }; | 70 }; |
59 | 71 |
60 } // namespace net | 72 } // namespace net |
61 | 73 |
62 #endif // NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_ | 74 #endif // NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_ |
OLD | NEW |