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

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

Issue 992733002: Remove //net (except for Android test stuff) and sdch (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « net/url_request/url_request_file_dir_job.cc ('k') | net/url_request/url_request_file_job.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_
6 #define NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "net/base/net_export.h"
15 #include "net/http/http_byte_range.h"
16 #include "net/url_request/url_request.h"
17 #include "net/url_request/url_request_job.h"
18
19 namespace base {
20 class TaskRunner;
21 }
22 namespace file_util {
23 struct FileInfo;
24 }
25
26 namespace net {
27
28 class FileStream;
29
30 // A request job that handles reading file URLs
31 class NET_EXPORT URLRequestFileJob : public URLRequestJob {
32 public:
33 URLRequestFileJob(URLRequest* request,
34 NetworkDelegate* network_delegate,
35 const base::FilePath& file_path,
36 const scoped_refptr<base::TaskRunner>& file_task_runner);
37
38 // URLRequestJob:
39 void Start() override;
40 void Kill() override;
41 bool ReadRawData(IOBuffer* buf, int buf_size, int* bytes_read) override;
42 bool IsRedirectResponse(GURL* location, int* http_status_code) override;
43 Filter* SetupFilter() const override;
44 bool GetMimeType(std::string* mime_type) const override;
45 void SetExtraRequestHeaders(const HttpRequestHeaders& headers) override;
46
47 // An interface for subclasses who wish to monitor read operations.
48 virtual void OnSeekComplete(int64 result);
49 virtual void OnReadComplete(net::IOBuffer* buf, int result);
50
51 protected:
52 ~URLRequestFileJob() override;
53
54 int64 remaining_bytes() const { return remaining_bytes_; }
55
56 // The OS-specific full path name of the file
57 base::FilePath file_path_;
58
59 private:
60 // Meta information about the file. It's used as a member in the
61 // URLRequestFileJob and also passed between threads because disk access is
62 // necessary to obtain it.
63 struct FileMetaInfo {
64 FileMetaInfo();
65
66 // Size of the file.
67 int64 file_size;
68 // Mime type associated with the file.
69 std::string mime_type;
70 // Result returned from GetMimeTypeFromFile(), i.e. flag showing whether
71 // obtaining of the mime type was successful.
72 bool mime_type_result;
73 // Flag showing whether the file exists.
74 bool file_exists;
75 // Flag showing whether the file name actually refers to a directory.
76 bool is_directory;
77 };
78
79 // Fetches file info on a background thread.
80 static void FetchMetaInfo(const base::FilePath& file_path,
81 FileMetaInfo* meta_info);
82
83 // Callback after fetching file info on a background thread.
84 void DidFetchMetaInfo(const FileMetaInfo* meta_info);
85
86 // Callback after opening file on a background thread.
87 void DidOpen(int result);
88
89 // Callback after seeking to the beginning of |byte_range_| in the file
90 // on a background thread.
91 void DidSeek(int64 result);
92
93 // Callback after data is asynchronously read from the file into |buf|.
94 void DidRead(scoped_refptr<net::IOBuffer> buf, int result);
95
96 scoped_ptr<FileStream> stream_;
97 FileMetaInfo meta_info_;
98 const scoped_refptr<base::TaskRunner> file_task_runner_;
99
100 HttpByteRange byte_range_;
101 int64 remaining_bytes_;
102
103 base::WeakPtrFactory<URLRequestFileJob> weak_ptr_factory_;
104
105 DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob);
106 };
107
108 } // namespace net
109
110 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_
OLDNEW
« no previous file with comments | « net/url_request/url_request_file_dir_job.cc ('k') | net/url_request/url_request_file_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698