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.
5 #ifndef NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_
6 #define NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_
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"
30 // A request job that handles reading file URLs
31 class NET_EXPORT URLRequestFileJob
: public URLRequestJob
{
33 URLRequestFileJob(URLRequest
* request
,
34 NetworkDelegate
* network_delegate
,
35 const base::FilePath
& file_path
,
36 const scoped_refptr
<base::TaskRunner
>& file_task_runner
);
39 virtual void Start() OVERRIDE
;
40 virtual void Kill() OVERRIDE
;
41 virtual bool ReadRawData(IOBuffer
* buf
,
43 int* bytes_read
) OVERRIDE
;
44 virtual bool IsRedirectResponse(GURL
* location
,
45 int* http_status_code
) OVERRIDE
;
46 virtual Filter
* SetupFilter() const OVERRIDE
;
47 virtual bool GetMimeType(std::string
* mime_type
) const OVERRIDE
;
48 virtual void SetExtraRequestHeaders(
49 const HttpRequestHeaders
& headers
) OVERRIDE
;
52 virtual ~URLRequestFileJob();
54 // The OS-specific full path name of the file
55 base::FilePath file_path_
;
58 // Meta information about the file. It's used as a member in the
59 // URLRequestFileJob and also passed between threads because disk access is
60 // necessary to obtain it.
66 // Mime type associated with the file.
67 std::string mime_type
;
68 // Result returned from GetMimeTypeFromFile(), i.e. flag showing whether
69 // obtaining of the mime type was successful.
70 bool mime_type_result
;
71 // Flag showing whether the file exists.
73 // Flag showing whether the file name actually refers to a directory.
77 // Fetches file info on a background thread.
78 static void FetchMetaInfo(const base::FilePath
& file_path
,
79 FileMetaInfo
* meta_info
);
81 // Callback after fetching file info on a background thread.
82 void DidFetchMetaInfo(const FileMetaInfo
* meta_info
);
84 // Callback after opening file on a background thread.
85 void DidOpen(int result
);
87 // Callback after seeking to the beginning of |byte_range_| in the file
88 // on a background thread.
89 void DidSeek(int64 result
);
91 // Callback after data is asynchronously read from the file.
92 void DidRead(int result
);
94 scoped_ptr
<FileStream
> stream_
;
95 FileMetaInfo meta_info_
;
96 const scoped_refptr
<base::TaskRunner
> file_task_runner_
;
98 HttpByteRange byte_range_
;
99 int64 remaining_bytes_
;
101 base::WeakPtrFactory
<URLRequestFileJob
> weak_ptr_factory_
;
103 DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob
);
108 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_