summaryrefslogtreecommitdiffstats
path: root/webkit/tools/test_shell/simple_file_system.h
blob: 464c59121cf78757301673f6b03b7add024d17be (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Copyright (c) 2012 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_TOOLS_TEST_SHELL_SIMPLE_FILE_SYSTEM_H_
#define WEBKIT_TOOLS_TEST_SHELL_SIMPLE_FILE_SYSTEM_H_

#include <vector>

#include "base/files/scoped_temp_dir.h"
#include "base/id_map.h"
#include "base/memory/weak_ptr.h"
#include "third_party/WebKit/public/platform/WebFileSystem.h"
#include "third_party/WebKit/public/platform/WebFileSystemType.h"
#include "webkit/browser/fileapi/file_system_context.h"
#include "webkit/browser/fileapi/file_system_operation.h"
#include "webkit/common/fileapi/file_system_types.h"

namespace WebKit {
class WebFileSystemCallbacks;
class WebFrame;
class WebURL;
}

namespace fileapi {
class FileSystemContext;
class FileSystemURL;
}

namespace webkit_blob {
class BlobStorageController;
}

class SimpleFileSystem
    : public WebKit::WebFileSystem,
      public base::SupportsWeakPtr<SimpleFileSystem> {
 public:
  SimpleFileSystem();
  virtual ~SimpleFileSystem();

  void OpenFileSystem(WebKit::WebFrame* frame,
                      WebKit::WebFileSystemType type,
                      long long size,
                      bool create,
                      WebKit::WebFileSystemCallbacks* callbacks);
  void DeleteFileSystem(WebKit::WebFrame* frame,
                        WebKit::WebFileSystemType type,
                        WebKit::WebFileSystemCallbacks* callbacks);

  fileapi::FileSystemContext* file_system_context() {
    return file_system_context_.get();
  }

  // WebKit::WebFileSystem implementation.
  virtual void move(
      const WebKit::WebURL& src_path,
      const WebKit::WebURL& dest_path,
      WebKit::WebFileSystemCallbacks*) OVERRIDE;
  virtual void copy(
      const WebKit::WebURL& src_path,
      const WebKit::WebURL& dest_path,
      WebKit::WebFileSystemCallbacks*) OVERRIDE;
  virtual void remove(
      const WebKit::WebURL& path,
      WebKit::WebFileSystemCallbacks*) OVERRIDE;
  virtual void removeRecursively(
      const WebKit::WebURL& path,
      WebKit::WebFileSystemCallbacks*) OVERRIDE;
  virtual void readMetadata(
      const WebKit::WebURL& path,
      WebKit::WebFileSystemCallbacks*) OVERRIDE;
  virtual void createFile(
      const WebKit::WebURL& path,
      bool exclusive,
      WebKit::WebFileSystemCallbacks*) OVERRIDE;
  virtual void createDirectory(
      const WebKit::WebURL& path,
      bool exclusive,
      WebKit::WebFileSystemCallbacks*) OVERRIDE;
  virtual void fileExists(
      const WebKit::WebURL& path,
      WebKit::WebFileSystemCallbacks*) OVERRIDE;
  virtual void directoryExists(
      const WebKit::WebURL& path,
      WebKit::WebFileSystemCallbacks*) OVERRIDE;
  virtual void readDirectory(
      const WebKit::WebURL& path,
      WebKit::WebFileSystemCallbacks*) OVERRIDE;
  virtual WebKit::WebFileWriter* createFileWriter(
      const WebKit::WebURL& path, WebKit::WebFileWriterClient*) OVERRIDE;
  virtual void createSnapshotFileAndReadMetadata(
      const WebKit::WebURL& path,
      WebKit::WebFileSystemCallbacks* callbacks);

  static void InitializeOnIOThread(
      webkit_blob::BlobStorageController* blob_storage_controller);
  static void CleanupOnIOThread();

 private:
  // Helpers.
  bool HasFilePermission(const fileapi::FileSystemURL& url, int permissions);
  fileapi::FileSystemOperation* GetNewOperation(
      const fileapi::FileSystemURL& url);

  // Callback Handlers
  fileapi::FileSystemOperation::StatusCallback FinishHandler(
      WebKit::WebFileSystemCallbacks* callbacks);
  fileapi::FileSystemOperation::GetMetadataCallback GetMetadataHandler(
      WebKit::WebFileSystemCallbacks* callbacks);
  fileapi::FileSystemOperation::ReadDirectoryCallback
      ReadDirectoryHandler(WebKit::WebFileSystemCallbacks* callbacks);
  fileapi::FileSystemContext::OpenFileSystemCallback OpenFileSystemHandler(
      WebKit::WebFileSystemCallbacks* callbacks);
  fileapi::FileSystemContext::DeleteFileSystemCallback DeleteFileSystemHandler(
      WebKit::WebFileSystemCallbacks* callbacks);
  fileapi::FileSystemOperation::SnapshotFileCallback
      SnapshotFileHandler(WebKit::WebFileSystemCallbacks* callbacks);
  fileapi::FileSystemOperation::SnapshotFileCallback
      SnapshotFileHandler_Deprecated(
          const GURL& blob_url,
          WebKit::WebFileSystemCallbacks* callbacks);
  void DidFinish(WebKit::WebFileSystemCallbacks* callbacks,
                 base::PlatformFileError result);
  void DidGetMetadata(WebKit::WebFileSystemCallbacks* callbacks,
                      base::PlatformFileError result,
                      const base::PlatformFileInfo& info,
                      const base::FilePath& platform_path);
  void DidReadDirectory(
      WebKit::WebFileSystemCallbacks* callbacks,
      base::PlatformFileError result,
      const std::vector<fileapi::DirectoryEntry>& entries,
      bool has_more);
  void DidOpenFileSystem(WebKit::WebFileSystemCallbacks* callbacks,
                         base::PlatformFileError result,
                         const std::string& name, const GURL& root);
  void DidDeleteFileSystem(WebKit::WebFileSystemCallbacks* callbacks,
                           base::PlatformFileError result);
  void DidCreateSnapshotFile(
      WebKit::WebFileSystemCallbacks* callbacks,
      base::PlatformFileError result,
      const base::PlatformFileInfo& info,
      const base::FilePath& platform_path,
      const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref);
  void DidCreateSnapshotFile_Deprecated(
      const GURL& blob_url,
      WebKit::WebFileSystemCallbacks* callbacks,
      base::PlatformFileError result,
      const base::PlatformFileInfo& info,
      const base::FilePath& platform_path,
      const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref);

  // A temporary directory for FileSystem API.
  base::ScopedTempDir file_system_dir_;

  scoped_refptr<fileapi::FileSystemContext> file_system_context_;

  DISALLOW_COPY_AND_ASSIGN(SimpleFileSystem);
};

#endif  // WEBKIT_TOOLS_TEST_SHELL_SIMPLE_FILE_SYSTEM_H_