• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef WebFileSystem_h
32 #define WebFileSystem_h
33 
34 #include "WebCommon.h"
35 #include "WebFileSystemCallbacks.h"
36 #include "WebFileSystemType.h"
37 #include "WebURL.h"
38 
39 namespace blink {
40 
41 class WebFileWriter;
42 class WebFileWriterClient;
43 
44 class WebFileSystem {
45 public:
46     enum Type {
47         TypeTemporary,
48         TypePersistent,
49 
50         // Indicates an isolated filesystem which only exposes a set of files.
51         TypeIsolated,
52 
53         // Indicates a non-sandboxed filesystem.
54         TypeExternal,
55     };
56 
57     // Opens a FileSystem.
58     // WebFileSystemCallbacks::didOpenFileSystem() must be called with
59     // a name and root path for the requested FileSystem when the operation
60     // is completed successfully. WebFileSystemCallbacks::didFail() must be
61     // called otherwise.
openFileSystem(const WebURL & storagePartition,const WebFileSystemType,WebFileSystemCallbacks)62     virtual void openFileSystem(const WebURL& storagePartition, const WebFileSystemType, WebFileSystemCallbacks) { BLINK_ASSERT_NOT_REACHED(); }
63 
64     // Resolves a filesystem URL.
65     // WebFileSystemCallbacks::didSucceed() must be called with filesystem
66     // information (name, root path and type) and file metadata (file path and
67     // file type) when the operation is completed successfully.
68     // WebFileSystemCallbacks::didFail() must be called otherwise.
resolveURL(const WebURL & fileSystemURL,WebFileSystemCallbacks)69     virtual void resolveURL(const WebURL& fileSystemURL, WebFileSystemCallbacks) { BLINK_ASSERT_NOT_REACHED(); }
70 
71     // Deletes FileSystem.
72     // WebFileSystemCallbacks::didSucceed() must be called when the operation
73     // is completed successfully. WebFileSystemCallbacks::didFail() must be
74     // called otherwise.
75     // All in-flight operations and following operations may fail after the
76     // FileSystem is deleted.
deleteFileSystem(const WebURL & storagePartition,const WebFileSystemType,WebFileSystemCallbacks)77     virtual void deleteFileSystem(const WebURL& storagePartition, const WebFileSystemType, WebFileSystemCallbacks) { }
78 
79     // Moves a file or directory at |srcPath| to |destPath|.
80     // WebFileSystemCallbacks::didSucceed() must be called when the operation is completed successfully.
81     // WebFileSystemCallbacks::didFail() must be called otherwise.
move(const WebURL & srcPath,const WebURL & destPath,WebFileSystemCallbacks)82     virtual void move(const WebURL& srcPath, const WebURL& destPath, WebFileSystemCallbacks) { BLINK_ASSERT_NOT_REACHED(); }
83 
84     // Copies a file or directory at |srcPath| to |destPath|.
85     // WebFileSystemCallbacks::didSucceed() must be called when the operation is completed successfully.
86     // WebFileSystemCallbacks::didFail() must be called otherwise.
copy(const WebURL & srcPath,const WebURL & destPath,WebFileSystemCallbacks)87     virtual void copy(const WebURL& srcPath, const WebURL& destPath, WebFileSystemCallbacks) { BLINK_ASSERT_NOT_REACHED(); }
88 
89     // Deletes a file or directory at a given |path|.
90     // It is an error to try to remove a directory that is not empty.
91     // WebFileSystemCallbacks::didSucceed() must be called when the operation is completed successfully.
92     // WebFileSystemCallbacks::didFail() must be called otherwise.
remove(const WebURL & path,WebFileSystemCallbacks)93     virtual void remove(const WebURL& path, WebFileSystemCallbacks) { BLINK_ASSERT_NOT_REACHED(); }
94 
95     // Deletes a file or directory recursively at a given |path|.
96     // WebFileSystemCallbacks::didSucceed() must be called when the operation is completed successfully.
97     // WebFileSystemCallbacks::didFail() must be called otherwise.
removeRecursively(const WebURL & path,WebFileSystemCallbacks)98     virtual void removeRecursively(const WebURL& path, WebFileSystemCallbacks) { BLINK_ASSERT_NOT_REACHED(); }
99 
100     // Retrieves the metadata information of the file or directory at the given |path|.
101     // This may not always return the local platform path in remote filesystem cases.
102     // WebFileSystemCallbacks::didReadMetadata() must be called with a valid metadata when the retrieval is completed successfully.
103     // WebFileSystemCallbacks::didFail() must be called otherwise.
readMetadata(const WebURL & path,WebFileSystemCallbacks)104     virtual void readMetadata(const WebURL& path, WebFileSystemCallbacks) { BLINK_ASSERT_NOT_REACHED(); }
105 
106     // Creates a file at given |path|.
107     // If the |path| doesn't exist, it creates a new file at |path|.
108     // If |exclusive| is true, it fails if the |path| already exists.
109     // If |exclusive| is false, it succeeds if the |path| already exists or
110     // it has successfully created a new file at |path|.
111     //
112     // WebFileSystemCallbacks::didSucceed() must be called when the operation is completed successfully.
113     // WebFileSystemCallbacks::didFail() must be called otherwise.
createFile(const WebURL & path,bool exclusive,WebFileSystemCallbacks)114     virtual void createFile(const WebURL& path, bool exclusive, WebFileSystemCallbacks) { BLINK_ASSERT_NOT_REACHED(); }
115 
116     // Creates a directory at a given |path|.
117     // If the |path| doesn't exist, it creates a new directory at |path|.
118     // If |exclusive| is true, it fails if the |path| already exists.
119     // If |exclusive| is false, it succeeds if the |path| already exists or it has successfully created a new directory at |path|.
120     //
121     // WebFileSystemCallbacks::didSucceed() must be called when
122     // the operation is completed successfully.
123     // WebFileSystemCallbacks::didFail() must be called otherwise.
createDirectory(const WebURL & path,bool exclusive,WebFileSystemCallbacks)124     virtual void createDirectory(const WebURL& path, bool exclusive, WebFileSystemCallbacks) { BLINK_ASSERT_NOT_REACHED(); }
125 
126     // Checks if a file exists at a given |path|.
127     // WebFileSystemCallbacks::didSucceed() must be called when the operation is completed successfully.
128     // WebFileSystemCallbacks::didFail() must be called otherwise.
fileExists(const WebURL & path,WebFileSystemCallbacks)129     virtual void fileExists(const WebURL& path, WebFileSystemCallbacks) { BLINK_ASSERT_NOT_REACHED(); }
130 
131     // Checks if a directory exists at a given |path|.
132     // WebFileSystemCallbacks::didSucceed() must be called when the operation is completed successfully.
133     // WebFileSystemCallbacks::didFail() must be called otherwise.
directoryExists(const WebURL & path,WebFileSystemCallbacks)134     virtual void directoryExists(const WebURL& path, WebFileSystemCallbacks) { BLINK_ASSERT_NOT_REACHED(); }
135 
136     // Reads directory entries of a given directory at |path| and returns a callbacks ID which can be used to wait for additional results.
137     // WebFileSystemCallbacks::didReadDirectory() must be called when the operation is completed successfully.
138     // WebFileSystemCallbacks::didFail() must be called otherwise.
readDirectory(const WebURL & path,WebFileSystemCallbacks)139     virtual int readDirectory(const WebURL& path, WebFileSystemCallbacks) { BLINK_ASSERT_NOT_REACHED(); return 0; }
140 
141     // Creates a WebFileWriter that can be used to write to the given file.
142     // WebFileSystemCallbacks::didCreateFileWriter() must be called with the created WebFileWriter when the operation is completed successfully.
143     // WebFileSystemCallbacks::didFail() must be called otherwise.
createFileWriter(const WebURL & path,WebFileWriterClient *,WebFileSystemCallbacks)144     virtual void createFileWriter(const WebURL& path, WebFileWriterClient*, WebFileSystemCallbacks) { BLINK_ASSERT_NOT_REACHED(); }
145 
146     // Creates a snapshot file for a given file specified by |path|. It returns the metadata of the created snapshot file.
147     // The returned metadata should include a local platform path to the snapshot image.
148     // In local filesystem cases the backend may simply return the metadata of the file itself (as well as readMetadata does), while in
149     // remote filesystem case the backend may download the file into a temporary snapshot file and return the metadata of the temporary file.
150     // The returned metadata is used to create a File object for the |path|.
151     // The snapshot file is supposed to be deleted when the last reference to a blink::File referring to it's path is dropped.
152     // WebFileSystemCallbacks::didCreateSnapshotFile() with the metadata of the snapshot file must be called when the operation is completed successfully.
153     // WebFileSystemCallbacks::didFail() must be called otherwise.
createSnapshotFileAndReadMetadata(const WebURL & path,WebFileSystemCallbacks)154     virtual void createSnapshotFileAndReadMetadata(const WebURL& path, WebFileSystemCallbacks) { BLINK_ASSERT_NOT_REACHED(); }
155 
156     // Waits for additional results returned for the method call and returns true if possible.
157     // Returns false if there is no running method call corresponding for the given ID.
158     // |callbacksId| must be the value returned by the original method call.
waitForAdditionalResult(int callbacksId)159     virtual bool waitForAdditionalResult(int callbacksId) { BLINK_ASSERT_NOT_REACHED(); return false; }
160 
161 protected:
~WebFileSystem()162     virtual ~WebFileSystem() { }
163 };
164 
165 } // namespace blink
166 
167 #endif
168