1 // Copyright (c) 2006-2009 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 10 #include "base/file_path.h" 11 #include "net/base/completion_callback.h" 12 #include "net/base/file_stream.h" 13 #include "net/http/http_byte_range.h" 14 #include "net/url_request/url_request.h" 15 #include "net/url_request/url_request_job.h" 16 17 namespace file_util { 18 struct FileInfo; 19 } 20 21 // A request job that handles reading file URLs 22 class URLRequestFileJob : public URLRequestJob { 23 public: 24 URLRequestFileJob(URLRequest* request, const FilePath& file_path); 25 26 virtual void Start(); 27 virtual void Kill(); 28 virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read); 29 virtual bool IsRedirectResponse(GURL* location, int* http_status_code); 30 virtual bool GetContentEncodings( 31 std::vector<Filter::FilterType>* encoding_type); 32 virtual bool GetMimeType(std::string* mime_type) const; 33 virtual void SetExtraRequestHeaders(const std::string& headers); 34 35 static URLRequest::ProtocolFactory Factory; 36 37 protected: 38 virtual ~URLRequestFileJob(); 39 40 // The OS-specific full path name of the file 41 FilePath file_path_; 42 43 private: 44 void DidResolve(bool exists, const file_util::FileInfo& file_info); 45 void DidRead(int result); 46 47 net::CompletionCallbackImpl<URLRequestFileJob> io_callback_; 48 net::FileStream stream_; 49 bool is_directory_; 50 51 net::HttpByteRange byte_range_; 52 int64 remaining_bytes_; 53 54 #if defined(OS_WIN) 55 class AsyncResolver; 56 friend class AsyncResolver; 57 scoped_refptr<AsyncResolver> async_resolver_; 58 #endif 59 60 DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob); 61 }; 62 63 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_ 64