OLD | NEW |
| (Empty) |
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 | |
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/ref_counted.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "base/strings/string_piece.h" | |
13 #include "net/base/completion_callback.h" | |
14 #include "net/base/net_export.h" | |
15 #include "net/url_request/url_range_request_job.h" | |
16 | |
17 namespace base { | |
18 class RefCountedMemory; | |
19 } | |
20 | |
21 namespace net { | |
22 | |
23 class URLRequest; | |
24 | |
25 class NET_EXPORT URLRequestSimpleJob : public URLRangeRequestJob { | |
26 public: | |
27 URLRequestSimpleJob(URLRequest* request, NetworkDelegate* network_delegate); | |
28 | |
29 void Start() override; | |
30 bool ReadRawData(IOBuffer* buf, int buf_size, int* bytes_read) override; | |
31 bool GetMimeType(std::string* mime_type) const override; | |
32 bool GetCharset(std::string* charset) override; | |
33 | |
34 protected: | |
35 ~URLRequestSimpleJob() override; | |
36 | |
37 // Subclasses must override either GetData or GetRefCountedData to define the | |
38 // way response data is determined. | |
39 // The return value should be: | |
40 // - OK if data is obtained; | |
41 // - ERR_IO_PENDING if async processing is needed to finish obtaining data. | |
42 // This is the only case when |callback| should be called after | |
43 // completion of the operation. In other situations |callback| should | |
44 // never be called; | |
45 // - any other ERR_* code to indicate an error. This code will be used | |
46 // as the error code in the URLRequestStatus when the URLRequest | |
47 // is finished. | |
48 virtual int GetData(std::string* mime_type, | |
49 std::string* charset, | |
50 std::string* data, | |
51 const CompletionCallback& callback) const; | |
52 | |
53 // Similar to GetData(), except |*data| can share ownership of the bytes | |
54 // instead of copying them into a std::string. | |
55 virtual int GetRefCountedData(std::string* mime_type, | |
56 std::string* charset, | |
57 scoped_refptr<base::RefCountedMemory>* data, | |
58 const CompletionCallback& callback) const; | |
59 | |
60 // Returns the task runner used by ReadRawData. This method is virtual so | |
61 // that it can be overridden in tests. | |
62 virtual base::TaskRunner* GetTaskRunner() const; | |
63 | |
64 void StartAsync(); | |
65 | |
66 private: | |
67 void OnGetDataCompleted(int result); | |
68 void OnReadCompleted(int bytes_read); | |
69 | |
70 HttpByteRange byte_range_; | |
71 std::string mime_type_; | |
72 std::string charset_; | |
73 scoped_refptr<base::RefCountedMemory> data_; | |
74 int64 next_data_offset_; | |
75 scoped_refptr<base::TaskRunner> task_runner_; | |
76 base::WeakPtrFactory<URLRequestSimpleJob> weak_factory_; | |
77 }; | |
78 | |
79 } // namespace net | |
80 | |
81 #endif // NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_ | |
OLD | NEW |