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_FILE_JOB_H_ | 5 #ifndef NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_ |
6 #define NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_ | 6 #define NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "net/base/net_errors.h" | |
15 #include "net/base/net_export.h" | 14 #include "net/base/net_export.h" |
16 #include "net/http/http_byte_range.h" | 15 #include "net/http/http_byte_range.h" |
17 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
18 #include "net/url_request/url_request_job.h" | 17 #include "net/url_request/url_request_job.h" |
19 | 18 |
20 namespace base { | 19 namespace base { |
21 class TaskRunner; | 20 class TaskRunner; |
22 } | 21 } |
23 namespace file_util { | 22 namespace file_util { |
24 struct FileInfo; | 23 struct FileInfo; |
25 } | 24 } |
26 | 25 |
27 namespace net { | 26 namespace net { |
28 | 27 |
29 class FileStream; | 28 class FileStream; |
30 | 29 |
31 // A request job that handles reading file URLs | 30 // A request job that handles reading file URLs |
32 class NET_EXPORT URLRequestFileJob : public URLRequestJob { | 31 class NET_EXPORT URLRequestFileJob : public URLRequestJob { |
33 public: | 32 public: |
34 URLRequestFileJob(URLRequest* request, | 33 URLRequestFileJob(URLRequest* request, |
35 NetworkDelegate* network_delegate, | 34 NetworkDelegate* network_delegate, |
36 const base::FilePath& file_path, | 35 const base::FilePath& file_path, |
37 const scoped_refptr<base::TaskRunner>& file_task_runner); | 36 const scoped_refptr<base::TaskRunner>& file_task_runner); |
38 | 37 |
39 // URLRequestJob: | 38 // URLRequestJob: |
40 void Start() override; | 39 void Start() override; |
41 void Kill() override; | 40 void Kill() override; |
42 int ReadRawData(IOBuffer* buf, int buf_size) override; | 41 bool ReadRawData(IOBuffer* buf, int buf_size, int* bytes_read) override; |
43 bool IsRedirectResponse(GURL* location, int* http_status_code) override; | 42 bool IsRedirectResponse(GURL* location, int* http_status_code) override; |
44 Filter* SetupFilter() const override; | 43 Filter* SetupFilter() const override; |
45 bool GetMimeType(std::string* mime_type) const override; | 44 bool GetMimeType(std::string* mime_type) const override; |
46 void SetExtraRequestHeaders(const HttpRequestHeaders& headers) override; | 45 void SetExtraRequestHeaders(const HttpRequestHeaders& headers) override; |
47 | 46 |
48 // An interface for subclasses who wish to monitor read operations. | 47 // An interface for subclasses who wish to monitor read operations. |
49 virtual void OnSeekComplete(int64 result); | 48 virtual void OnSeekComplete(int64 result); |
50 virtual void OnReadComplete(IOBuffer* buf, int result); | 49 virtual void OnReadComplete(IOBuffer* buf, int result); |
51 | 50 |
52 protected: | 51 protected: |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // on a background thread. | 90 // on a background thread. |
92 void DidSeek(int64 result); | 91 void DidSeek(int64 result); |
93 | 92 |
94 // Callback after data is asynchronously read from the file into |buf|. | 93 // Callback after data is asynchronously read from the file into |buf|. |
95 void DidRead(scoped_refptr<IOBuffer> buf, int result); | 94 void DidRead(scoped_refptr<IOBuffer> buf, int result); |
96 | 95 |
97 scoped_ptr<FileStream> stream_; | 96 scoped_ptr<FileStream> stream_; |
98 FileMetaInfo meta_info_; | 97 FileMetaInfo meta_info_; |
99 const scoped_refptr<base::TaskRunner> file_task_runner_; | 98 const scoped_refptr<base::TaskRunner> file_task_runner_; |
100 | 99 |
101 std::vector<HttpByteRange> byte_ranges_; | |
102 HttpByteRange byte_range_; | 100 HttpByteRange byte_range_; |
103 int64 remaining_bytes_; | 101 int64 remaining_bytes_; |
104 | 102 |
105 Error range_parse_result_; | |
106 | |
107 base::WeakPtrFactory<URLRequestFileJob> weak_ptr_factory_; | 103 base::WeakPtrFactory<URLRequestFileJob> weak_ptr_factory_; |
108 | 104 |
109 DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob); | 105 DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob); |
110 }; | 106 }; |
111 | 107 |
112 } // namespace net | 108 } // namespace net |
113 | 109 |
114 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_ | 110 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_ |
OLD | NEW |