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 net::OK if data is obtained; |
35 std::string* charset, | 36 // net::ERR_IO_PENDING if processing in another thread is needed to finish |
36 std::string* data) const = 0; | 37 // obtaining data; and net::ERR_FAILED to indicate an error. If method |
38 // returns net::ERR_IO_PENDING then |callback| should be called when | |
39 // operation is completed. In other situations |callback| should never be | |
40 // called. | |
wtc
2012/07/11 01:08:46
Nit: remove net:: in this comment block because th
wtc
2012/07/11 18:48:50
I see. Then the use of "should" is appropriate in
| |
41 virtual int GetData(std::string* mime_type, | |
42 std::string* charset, | |
43 std::string* data, | |
44 const CompletionCallback& callback) const = 0; | |
37 | 45 |
38 protected: | 46 protected: |
39 void StartAsync(); | 47 void StartAsync(); |
40 | 48 |
41 private: | 49 private: |
50 void OnGetDataCompleted(int result); | |
51 | |
42 std::string mime_type_; | 52 std::string mime_type_; |
43 std::string charset_; | 53 std::string charset_; |
44 std::string data_; | 54 std::string data_; |
45 int data_offset_; | 55 int data_offset_; |
46 base::WeakPtrFactory<URLRequestSimpleJob> weak_factory_; | 56 base::WeakPtrFactory<URLRequestSimpleJob> weak_factory_; |
47 }; | 57 }; |
48 | 58 |
49 } // namespace net | 59 } // namespace net |
50 | 60 |
51 #endif // NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_ | 61 #endif // NET_URL_REQUEST_URL_REQUEST_SIMPLE_JOB_H_ |
OLD | NEW |