OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "net/base/completion_callback.h" | |
12 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
13 #include "net/url_request/url_request_job.h" | 14 #include "net/url_request/url_request_job.h" |
14 | 15 |
15 namespace net { | 16 namespace net { |
16 | 17 |
17 class URLRequest; | 18 class URLRequest; |
18 | 19 |
19 class NET_EXPORT URLRequestSimpleJob : public URLRequestJob { | 20 class NET_EXPORT URLRequestSimpleJob : public URLRequestJob { |
20 public: | 21 public: |
21 explicit URLRequestSimpleJob(URLRequest* request); | 22 explicit URLRequestSimpleJob(URLRequest* request); |
22 | 23 |
23 virtual void Start() OVERRIDE; | 24 virtual void Start() OVERRIDE; |
24 virtual bool ReadRawData(IOBuffer* buf, | 25 virtual bool ReadRawData(IOBuffer* buf, |
25 int buf_size, | 26 int buf_size, |
26 int *bytes_read) OVERRIDE; | 27 int *bytes_read) OVERRIDE; |
27 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | 28 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; |
28 virtual bool GetCharset(std::string* charset) OVERRIDE; | 29 virtual bool GetCharset(std::string* charset) OVERRIDE; |
29 | 30 |
30 protected: | 31 protected: |
31 virtual ~URLRequestSimpleJob(); | 32 virtual ~URLRequestSimpleJob(); |
32 | 33 |
33 // subclasses must override the way response data is determined. | 34 // Subclasses must override the way response data is determined. |
34 virtual bool GetData(std::string* mime_type, | 35 // The return value should be: |
35 std::string* charset, | 36 // - OK if data is obtained; |
36 std::string* data) const = 0; | 37 // - ERR_IO_PENDING if async processing is needed to finish obtaining data. |
38 // This is the only case when |callback| should be called after | |
39 // completion of the operation. In other situations |callback| should | |
40 // never be called; | |
41 // - any other ERR_* code to indicate an error. This code will be used as | |
42 // error code while finishing request. | |
wtc
2012/07/13 22:55:14
Remove "This code will be used as error code while
wtc
2012/07/14 00:08:55
Thank you for the clarification. I didn't realize
| |
43 virtual int GetData(std::string* mime_type, | |
44 std::string* charset, | |
45 std::string* data, | |
46 const CompletionCallback& callback) const = 0; | |
37 | 47 |
38 protected: | 48 protected: |
39 void StartAsync(); | 49 void StartAsync(); |
40 | 50 |
41 private: | 51 private: |
52 void OnGetDataCompleted(int result); | |
53 | |
42 std::string mime_type_; | 54 std::string mime_type_; |
43 std::string charset_; | 55 std::string charset_; |
44 std::string data_; | 56 std::string data_; |
45 int data_offset_; | 57 int data_offset_; |
46 base::WeakPtrFactory<URLRequestSimpleJob> weak_factory_; | 58 base::WeakPtrFactory<URLRequestSimpleJob> weak_factory_; |
47 }; | 59 }; |
48 | 60 |
49 } // namespace net | 61 } // namespace net |
50 | 62 |
51 #endif // NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_ | 63 #endif // NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_ |
OLD | NEW |