summaryrefslogtreecommitdiffstats
path: root/net/url_request/url_request_file_job.h
blob: 1baac7ad4af96f3d5778bf5a9ef1c962988640a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_
#define NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_
#pragma once

#include <string>
#include <vector>

#include "base/file_path.h"
#include "base/task.h"
#include "net/base/completion_callback.h"
#include "net/base/file_stream.h"
#include "net/http/http_byte_range.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_job.h"

namespace file_util {
struct FileInfo;
}

namespace net {

// A request job that handles reading file URLs
class URLRequestFileJob : public URLRequestJob {
 public:
  URLRequestFileJob(URLRequest* request, const FilePath& file_path);

  static URLRequest::ProtocolFactory Factory;

#if defined(OS_CHROMEOS)
  static bool AccessDisabled(const FilePath& file_path);
#endif

  // URLRequestJob:
  virtual void Start();
  virtual void Kill();
  virtual bool ReadRawData(IOBuffer* buf, int buf_size, int* bytes_read);
  virtual bool IsRedirectResponse(GURL* location, int* http_status_code);
  virtual Filter* SetupFilter() const;
  virtual bool GetMimeType(std::string* mime_type) const;
  virtual void SetExtraRequestHeaders(const HttpRequestHeaders& headers);

 protected:
  virtual ~URLRequestFileJob();

  // The OS-specific full path name of the file
  FilePath file_path_;

 private:
  void DidResolve(bool exists, const base::PlatformFileInfo& file_info);
  void DidRead(int result);

  CompletionCallbackImpl<URLRequestFileJob> io_callback_;
  FileStream stream_;
  bool is_directory_;

  HttpByteRange byte_range_;
  int64 remaining_bytes_;

#if defined(OS_WIN)
  class AsyncResolver;
  friend class AsyncResolver;
  scoped_refptr<AsyncResolver> async_resolver_;
#endif

  ScopedRunnableMethodFactory<URLRequestFileJob> method_factory_;

  DISALLOW_COPY_AND_ASSIGN(URLRequestFileJob);
};

}  // namespace net

#endif  // NET_URL_REQUEST_URL_REQUEST_FILE_JOB_H_