| 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 <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "net/base/file_stream.h" | 12 #include "net/base/file_stream.h" |
| 13 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
| 14 #include "net/http/http_byte_range.h" | 14 #include "net/http/http_byte_range.h" |
| 15 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
| 16 #include "net/url_request/url_request_job.h" | 16 #include "net/url_request/url_request_job.h" |
| 17 | 17 |
| 18 namespace file_util { | 18 namespace file_util { |
| 19 struct FileInfo; | 19 struct FileInfo; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace net { | 22 namespace net { |
| 23 | 23 |
| 24 // A request job that handles reading file URLs | 24 // A request job that handles reading file URLs |
| 25 class NET_EXPORT URLRequestFileJob : public URLRequestJob { | 25 class NET_EXPORT URLRequestFileJob : public URLRequestJob { |
| 26 public: | 26 public: |
| 27 URLRequestFileJob(URLRequest* request, const FilePath& file_path); | 27 URLRequestFileJob(URLRequest* request, |
| 28 const FilePath& file_path, |
| 29 NetworkDelegate* network_delegate); |
| 28 | 30 |
| 29 static URLRequest::ProtocolFactory Factory; | 31 static URLRequest::ProtocolFactory Factory; |
| 30 | 32 |
| 31 #if defined(OS_CHROMEOS) | 33 #if defined(OS_CHROMEOS) |
| 32 static bool AccessDisabled(const FilePath& file_path); | 34 static bool AccessDisabled(const FilePath& file_path); |
| 33 #endif | 35 #endif |
| 34 | 36 |
| 35 // URLRequestJob: | 37 // URLRequestJob: |
| 36 virtual void Start() OVERRIDE; | 38 virtual void Start() OVERRIDE; |
| 37 virtual void Kill() OVERRIDE; | 39 virtual void Kill() OVERRIDE; |
| 38 virtual bool ReadRawData(IOBuffer* buf, | 40 virtual bool ReadRawData(IOBuffer* buf, |
| 39 int buf_size, | 41 int buf_size, |
| 40 int* bytes_read) OVERRIDE; | 42 int* bytes_read) OVERRIDE; |
| 41 virtual bool IsRedirectResponse(GURL* location, | 43 virtual bool IsRedirectResponse(GURL* location, |
| 42 int* http_status_code) OVERRIDE; | 44 int* http_status_code) OVERRIDE; |
| 43 virtual Filter* SetupFilter() const OVERRIDE; | 45 virtual Filter* SetupFilter() const OVERRIDE; |
| 44 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; | 46 virtual bool GetMimeType(std::string* mime_type) const OVERRIDE; |
| 45 virtual void SetExtraRequestHeaders( | 47 virtual void SetExtraRequestHeaders( |
| 46 const HttpRequestHeaders& headers) OVERRIDE; | 48 const HttpRequestHeaders& headers) OVERRIDE; |
| 47 | 49 |
| 48 protected: | 50 protected: |
| 49 virtual ~URLRequestFileJob(); | 51 virtual ~URLRequestFileJob(); |
| 50 | 52 |
| 51 // The OS-specific full path name of the file | 53 // The OS-specific full path name of the file |
| 52 FilePath file_path_; | 54 FilePath file_path_; |
| 53 | 55 |
| 54 private: | 56 private: |
| 55 // Tests to see if access to |path| is allowed. If g_allow_file_access_ is | |
| 56 // true, then this will return true. If the NetworkDelegate associated with | |
| 57 // the |request| says it's OK, then this will also return true. | |
| 58 static bool IsFileAccessAllowed(const URLRequest& request, | |
| 59 const FilePath& path); | |
| 60 | |
| 61 // Callback after fetching file info on a background thread. | 57 // Callback after fetching file info on a background thread. |
| 62 void DidResolve(bool exists, const base::PlatformFileInfo& file_info); | 58 void DidResolve(bool exists, const base::PlatformFileInfo& file_info); |
| 63 | 59 |
| 64 // Callback after data is asynchronously read from the file. | 60 // Callback after data is asynchronously read from the file. |
| 65 void DidRead(int result); | 61 void DidRead(int result); |
| 66 | 62 |
| 67 FileStream stream_; | 63 FileStream stream_; |
| 68 bool is_directory_; | 64 bool is_directory_; |
| 69 | 65 |
| 70 HttpByteRange byte_range_; | 66 HttpByteRange byte_range_; |
| 71 int64 remaining_bytes_; | 67 int64 remaining_bytes_; |
| 72 | 68 |
| 73 // The initial file metadata is fetched on a background thread. | 69 // The initial file metadata is fetched on a background thread. |
| 74 // AsyncResolver runs that task. | 70 // AsyncResolver runs that task. |
| 75 class AsyncResolver; | 71 class AsyncResolver; |
| 76 friend class AsyncResolver; | 72 friend class AsyncResolver; |
| 77 scoped_refptr<AsyncResolver> async_resolver_; | 73 scoped_refptr<AsyncResolver> async_resolver_; |
| 78 | 74 |
| 79 DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob); | 75 DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob); |
| 80 }; | 76 }; |
| 81 | 77 |
| 82 } // namespace net | 78 } // namespace net |
| 83 | 79 |
| 84 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_ | 80 #endif // NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_ |
| OLD | NEW |