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