Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: net/url_request/url_request_file_job.h

Issue 2790073002: wip (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 27 matching lines...) Expand all
38 const scoped_refptr<base::TaskRunner>& file_task_runner); 38 const scoped_refptr<base::TaskRunner>& file_task_runner);
39 39
40 // URLRequestJob: 40 // URLRequestJob:
41 void Start() override; 41 void Start() override;
42 void Kill() override; 42 void Kill() override;
43 int ReadRawData(IOBuffer* buf, int buf_size) override; 43 int ReadRawData(IOBuffer* buf, int buf_size) override;
44 bool IsRedirectResponse(GURL* location, int* http_status_code) override; 44 bool IsRedirectResponse(GURL* location, int* http_status_code) override;
45 bool GetMimeType(std::string* mime_type) const override; 45 bool GetMimeType(std::string* mime_type) const override;
46 void SetExtraRequestHeaders(const HttpRequestHeaders& headers) override; 46 void SetExtraRequestHeaders(const HttpRequestHeaders& headers) override;
47 47
48 protected:
49 // Meta information about the file. It's used as a member in the
50 // URLRequestFileJob and also passed between threads because disk access is
51 // necessary to obtain it.
52 struct FileMetaInfo {
53 FileMetaInfo();
54
55 // Size of the file.
56 int64_t file_size;
57 // Mime type associated with the file.
58 std::string mime_type;
59 // Result returned from GetMimeTypeFromFile(), i.e. flag showing whether
60 // obtaining of the mime type was successful.
61 bool mime_type_result;
62 // Flag showing whether the file exists.
63 bool file_exists;
64 // Flag showing whether the file name actually refers to a directory.
65 bool is_directory;
66 // Absolute path of the file (i.e. symbolic link is resolved).
67 base::FilePath absolute_path;
68 };
69
48 // An interface for subclasses who wish to monitor read operations. 70 // An interface for subclasses who wish to monitor read operations.
49 // 71 //
72 // ...
73 virtual bool OnFetchMetaInfo(const FileMetaInfo& meta_info);
50 // |result| is the net::Error code resulting from attempting to open the file. 74 // |result| is the net::Error code resulting from attempting to open the file.
51 // Called before OnSeekComplete, only called if the request advanced to the 75 // Called before OnSeekComplete, only called if the request advanced to the
52 // point the file was opened, without being canceled. 76 // point the file was opened, without being canceled.
53 virtual void OnOpenComplete(int result); 77 virtual void OnOpenComplete(int result);
54 // Called at most once. On success, |result| is the non-negative offset into 78 // Called at most once. On success, |result| is the non-negative offset into
55 // the file that the request will read from. On seek failure, it's a negative 79 // the file that the request will read from. On seek failure, it's a negative
56 // net:Error code. 80 // net:Error code.
57 virtual void OnSeekComplete(int64_t result); 81 virtual void OnSeekComplete(int64_t result);
58 // Called once per read attempt. |buf| contains the read data, if any. 82 // Called once per read attempt. |buf| contains the read data, if any.
59 // |result| is the number of read bytes. 0 (net::OK) indicates EOF, negative 83 // |result| is the number of read bytes. 0 (net::OK) indicates EOF, negative
60 // numbers indicate it's a net::Error code. 84 // numbers indicate it's a net::Error code.
61 virtual void OnReadComplete(IOBuffer* buf, int result); 85 virtual void OnReadComplete(IOBuffer* buf, int result);
62 86
63 protected:
64 ~URLRequestFileJob() override; 87 ~URLRequestFileJob() override;
65 88
66 // URLRequestJob implementation. 89 // URLRequestJob implementation.
67 std::unique_ptr<SourceStream> SetUpSourceStream() override; 90 std::unique_ptr<SourceStream> SetUpSourceStream() override;
68 91
69 int64_t remaining_bytes() const { return remaining_bytes_; } 92 int64_t remaining_bytes() const { return remaining_bytes_; }
70 93
71 // The OS-specific full path name of the file 94 // The OS-specific full path name of the file
72 base::FilePath file_path_; 95 base::FilePath file_path_;
73 96
74 private: 97 private:
75 // Meta information about the file. It's used as a member in the
76 // URLRequestFileJob and also passed between threads because disk access is
77 // necessary to obtain it.
78 struct FileMetaInfo {
79 FileMetaInfo();
80
81 // Size of the file.
82 int64_t file_size;
83 // Mime type associated with the file.
84 std::string mime_type;
85 // Result returned from GetMimeTypeFromFile(), i.e. flag showing whether
86 // obtaining of the mime type was successful.
87 bool mime_type_result;
88 // Flag showing whether the file exists.
89 bool file_exists;
90 // Flag showing whether the file name actually refers to a directory.
91 bool is_directory;
92 };
93
94 // Fetches file info on a background thread. 98 // Fetches file info on a background thread.
95 static void FetchMetaInfo(const base::FilePath& file_path, 99 static void FetchMetaInfo(const base::FilePath& file_path,
96 FileMetaInfo* meta_info); 100 FileMetaInfo* meta_info);
97 101
98 // Callback after fetching file info on a background thread. 102 // Callback after fetching file info on a background thread.
99 void DidFetchMetaInfo(const FileMetaInfo* meta_info); 103 void DidFetchMetaInfo(const FileMetaInfo* meta_info);
100 104
101 // Callback after opening file on a background thread. 105 // Callback after opening file on a background thread.
102 void DidOpen(int result); 106 void DidOpen(int result);
103 107
(...skipping 15 matching lines...) Expand all
119 Error range_parse_result_; 123 Error range_parse_result_;
120 124
121 base::WeakPtrFactory<URLRequestFileJob> weak_ptr_factory_; 125 base::WeakPtrFactory<URLRequestFileJob> weak_ptr_factory_;
122 126
123 DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob); 127 DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob);
124 }; 128 };
125 129
126 } // namespace net 130 } // namespace net
127 131
128 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_ 132 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698