summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi/file_system_url_request_job.h
blob: ffef027f2ca6340b5ac2b7c6972c1d3585f73648 (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
77
78
79
80
81
82
83
84
// 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 WEBKIT_FILEAPI_FILE_SYSTEM_URL_REQUEST_JOB_H_
#define WEBKIT_FILEAPI_FILE_SYSTEM_URL_REQUEST_JOB_H_
#pragma once

#include <string>

#include "base/file_path.h"
#include "base/memory/scoped_callback_factory.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop_proxy.h"
#include "base/platform_file.h"
#include "base/task.h"
#include "net/base/completion_callback.h"
#include "net/http/http_byte_range.h"
#include "net/url_request/url_request_job.h"

class GURL;

namespace net {
class FileStream;
}

namespace fileapi {
class FileSystemPathManager;

// A request job that handles reading filesystem: URLs
class FileSystemURLRequestJob : public net::URLRequestJob {
 public:
  FileSystemURLRequestJob(
      net::URLRequest* request, FileSystemPathManager* path_manager,
      scoped_refptr<base::MessageLoopProxy> file_thread_proxy);

  // URLRequestJob methods:
  virtual void Start();
  virtual void Kill();
  virtual bool ReadRawData(net::IOBuffer* buf, int buf_size, int* bytes_read);
  virtual bool IsRedirectResponse(GURL* location, int* http_status_code);
  virtual void SetExtraRequestHeaders(const net::HttpRequestHeaders& headers);

  // FilterContext methods (via URLRequestJob):
  virtual bool GetMimeType(std::string* mime_type) const;

  // TODO(adamk): Implement GetResponseInfo and GetResponseCode to simulate
  // an HTTP response.

 private:
  virtual ~FileSystemURLRequestJob();

  void StartAsync();
  void DidGetRootPath(bool success, const FilePath& root_path,
                      const std::string& name);
  void DidResolve(base::PlatformFileError error_code,
                  const base::PlatformFileInfo& file_info);
  void DidOpen(base::PlatformFileError error_code,
               base::PassPlatformFile file, bool created);
  void DidRead(int result);

  void NotifyFailed(int rv);

  FilePath relative_file_path_;
  FilePath absolute_file_path_;
  FileSystemPathManager* const path_manager_;

  net::CompletionCallbackImpl<FileSystemURLRequestJob> io_callback_;
  scoped_ptr<net::FileStream> stream_;
  bool is_directory_;

  net::HttpByteRange byte_range_;
  int64 remaining_bytes_;

  ScopedRunnableMethodFactory<FileSystemURLRequestJob> method_factory_;
  base::ScopedCallbackFactory<FileSystemURLRequestJob> callback_factory_;
  scoped_refptr<base::MessageLoopProxy> file_thread_proxy_;

  DISALLOW_COPY_AND_ASSIGN(FileSystemURLRequestJob);
};

}  // namespace fileapi

#endif  // WEBKIT_FILEAPI_FILE_SYSTEM_URL_REQUEST_JOB_H_