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 <stdint.h> |
| 9 |
8 #include <string> | 10 #include <string> |
9 #include <vector> | 11 #include <vector> |
10 | 12 |
11 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
14 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
15 #include "net/base/net_export.h" | 18 #include "net/base/net_export.h" |
16 #include "net/http/http_byte_range.h" | 19 #include "net/http/http_byte_range.h" |
17 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
18 #include "net/url_request/url_request_job.h" | 21 #include "net/url_request/url_request_job.h" |
19 | 22 |
20 namespace base { | 23 namespace base { |
21 class TaskRunner; | 24 class TaskRunner; |
(...skipping 17 matching lines...) Expand all Loading... |
39 // URLRequestJob: | 42 // URLRequestJob: |
40 void Start() override; | 43 void Start() override; |
41 void Kill() override; | 44 void Kill() override; |
42 int ReadRawData(IOBuffer* buf, int buf_size) override; | 45 int ReadRawData(IOBuffer* buf, int buf_size) override; |
43 bool IsRedirectResponse(GURL* location, int* http_status_code) override; | 46 bool IsRedirectResponse(GURL* location, int* http_status_code) override; |
44 Filter* SetupFilter() const override; | 47 Filter* SetupFilter() const override; |
45 bool GetMimeType(std::string* mime_type) const override; | 48 bool GetMimeType(std::string* mime_type) const override; |
46 void SetExtraRequestHeaders(const HttpRequestHeaders& headers) override; | 49 void SetExtraRequestHeaders(const HttpRequestHeaders& headers) override; |
47 | 50 |
48 // An interface for subclasses who wish to monitor read operations. | 51 // An interface for subclasses who wish to monitor read operations. |
49 virtual void OnSeekComplete(int64 result); | 52 virtual void OnSeekComplete(int64_t result); |
50 virtual void OnReadComplete(IOBuffer* buf, int result); | 53 virtual void OnReadComplete(IOBuffer* buf, int result); |
51 | 54 |
52 protected: | 55 protected: |
53 ~URLRequestFileJob() override; | 56 ~URLRequestFileJob() override; |
54 | 57 |
55 int64 remaining_bytes() const { return remaining_bytes_; } | 58 int64_t remaining_bytes() const { return remaining_bytes_; } |
56 | 59 |
57 // The OS-specific full path name of the file | 60 // The OS-specific full path name of the file |
58 base::FilePath file_path_; | 61 base::FilePath file_path_; |
59 | 62 |
60 private: | 63 private: |
61 // Meta information about the file. It's used as a member in the | 64 // Meta information about the file. It's used as a member in the |
62 // URLRequestFileJob and also passed between threads because disk access is | 65 // URLRequestFileJob and also passed between threads because disk access is |
63 // necessary to obtain it. | 66 // necessary to obtain it. |
64 struct FileMetaInfo { | 67 struct FileMetaInfo { |
65 FileMetaInfo(); | 68 FileMetaInfo(); |
66 | 69 |
67 // Size of the file. | 70 // Size of the file. |
68 int64 file_size; | 71 int64_t file_size; |
69 // Mime type associated with the file. | 72 // Mime type associated with the file. |
70 std::string mime_type; | 73 std::string mime_type; |
71 // Result returned from GetMimeTypeFromFile(), i.e. flag showing whether | 74 // Result returned from GetMimeTypeFromFile(), i.e. flag showing whether |
72 // obtaining of the mime type was successful. | 75 // obtaining of the mime type was successful. |
73 bool mime_type_result; | 76 bool mime_type_result; |
74 // Flag showing whether the file exists. | 77 // Flag showing whether the file exists. |
75 bool file_exists; | 78 bool file_exists; |
76 // Flag showing whether the file name actually refers to a directory. | 79 // Flag showing whether the file name actually refers to a directory. |
77 bool is_directory; | 80 bool is_directory; |
78 }; | 81 }; |
79 | 82 |
80 // Fetches file info on a background thread. | 83 // Fetches file info on a background thread. |
81 static void FetchMetaInfo(const base::FilePath& file_path, | 84 static void FetchMetaInfo(const base::FilePath& file_path, |
82 FileMetaInfo* meta_info); | 85 FileMetaInfo* meta_info); |
83 | 86 |
84 // Callback after fetching file info on a background thread. | 87 // Callback after fetching file info on a background thread. |
85 void DidFetchMetaInfo(const FileMetaInfo* meta_info); | 88 void DidFetchMetaInfo(const FileMetaInfo* meta_info); |
86 | 89 |
87 // Callback after opening file on a background thread. | 90 // Callback after opening file on a background thread. |
88 void DidOpen(int result); | 91 void DidOpen(int result); |
89 | 92 |
90 // Callback after seeking to the beginning of |byte_range_| in the file | 93 // Callback after seeking to the beginning of |byte_range_| in the file |
91 // on a background thread. | 94 // on a background thread. |
92 void DidSeek(int64 result); | 95 void DidSeek(int64_t result); |
93 | 96 |
94 // Callback after data is asynchronously read from the file into |buf|. | 97 // Callback after data is asynchronously read from the file into |buf|. |
95 void DidRead(scoped_refptr<IOBuffer> buf, int result); | 98 void DidRead(scoped_refptr<IOBuffer> buf, int result); |
96 | 99 |
97 scoped_ptr<FileStream> stream_; | 100 scoped_ptr<FileStream> stream_; |
98 FileMetaInfo meta_info_; | 101 FileMetaInfo meta_info_; |
99 const scoped_refptr<base::TaskRunner> file_task_runner_; | 102 const scoped_refptr<base::TaskRunner> file_task_runner_; |
100 | 103 |
101 std::vector<HttpByteRange> byte_ranges_; | 104 std::vector<HttpByteRange> byte_ranges_; |
102 HttpByteRange byte_range_; | 105 HttpByteRange byte_range_; |
103 int64 remaining_bytes_; | 106 int64_t remaining_bytes_; |
104 | 107 |
105 Error range_parse_result_; | 108 Error range_parse_result_; |
106 | 109 |
107 base::WeakPtrFactory<URLRequestFileJob> weak_ptr_factory_; | 110 base::WeakPtrFactory<URLRequestFileJob> weak_ptr_factory_; |
108 | 111 |
109 DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob); | 112 DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob); |
110 }; | 113 }; |
111 | 114 |
112 } // namespace net | 115 } // namespace net |
113 | 116 |
114 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_ | 117 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_ |
OLD | NEW |