Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Side by Side Diff: webkit/fileapi/file_system_util.h

Issue 15658004: Split FileAPI code for common|common_child|renderer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 WEBKIT_FILEAPI_FILE_SYSTEM_UTIL_H_
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_UTIL_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/files/file_path.h"
12 #include "base/platform_file.h"
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebFileSystemType.h "
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileError.h"
15 #include "webkit/fileapi/file_system_types.h"
16 #include "webkit/quota/quota_types.h"
17 #include "webkit/storage/webkit_storage_export.h"
18
19 class GURL;
20
21 namespace fileapi {
22
23 class FileSystemURL;
24
25 extern const char kPersistentDir[];
26 extern const char kTemporaryDir[];
27 extern const char kExternalDir[];
28 extern const char kIsolatedDir[];
29 extern const char kTestDir[];
30
31 class WEBKIT_STORAGE_EXPORT VirtualPath {
32 public:
33 static const base::FilePath::CharType kRoot[];
34 static const base::FilePath::CharType kSeparator;
35
36 // Use this instead of base::FilePath::BaseName when operating on virtual
37 // paths. FilePath::BaseName will get confused by ':' on Windows when it
38 // looks like a drive letter separator; this will treat it as just another
39 // character.
40 static base::FilePath BaseName(const base::FilePath& virtual_path);
41
42 // Use this instead of base::FilePath::DirName when operating on virtual
43 // paths.
44 static base::FilePath DirName(const base::FilePath& virtual_path);
45
46 // Likewise, use this instead of base::FilePath::GetComponents when
47 // operating on virtual paths.
48 // Note that this assumes very clean input, with no leading slash, and
49 // it will not evaluate '..' components.
50 static void GetComponents(
51 const base::FilePath& path,
52 std::vector<base::FilePath::StringType>* components);
53
54 // Returns a path name ensuring that it begins with kRoot and all path
55 // separators are forward slashes /.
56 static base::FilePath::StringType GetNormalizedFilePath(
57 const base::FilePath& path);
58
59 // Returns true if the given path begins with kRoot.
60 static bool IsAbsolute(const base::FilePath::StringType& path);
61 };
62
63 // Returns the root URI of the filesystem that can be specified by a pair of
64 // |origin_url| and |type|. The returned URI can be used as a root path
65 // of the filesystem (e.g. <returned_URI> + "/relative/path" will compose
66 // a path pointing to the entry "/relative/path" in the filesystem).
67 //
68 // For Isolated filesystem this returns the 'common' root part, e.g.
69 // returns URL without the filesystem ID.
70 //
71 // |type| needs to be public type as the returned URI is given to the renderer.
72 WEBKIT_STORAGE_EXPORT GURL GetFileSystemRootURI(const GURL& origin_url,
73 FileSystemType type);
74
75 // Returns the name for the filesystem that is specified by a pair of
76 // |origin_url| and |type|.
77 // (The name itself is neither really significant nor a formal identifier
78 // but can be read as the .name field of the returned FileSystem object
79 // as a user-friendly name in the javascript layer).
80 //
81 // |type| needs to be public type as the returned name is given to the renderer.
82 //
83 // Example:
84 // The name for a TEMPORARY filesystem of "http://www.example.com:80/"
85 // should look like: "http_www.example.host_80:temporary"
86 WEBKIT_STORAGE_EXPORT std::string GetFileSystemName(const GURL& origin_url,
87 FileSystemType type);
88
89 // Converts FileSystemType |type| to/from the StorageType |storage_type| that
90 // is used for the unified quota system.
91 // (Basically this naively maps TEMPORARY storage type to TEMPORARY filesystem
92 // type, PERSISTENT storage type to PERSISTENT filesystem type and vice versa.)
93 WEBKIT_STORAGE_EXPORT FileSystemType QuotaStorageTypeToFileSystemType(
94 quota::StorageType storage_type);
95 WEBKIT_STORAGE_EXPORT quota::StorageType FileSystemTypeToQuotaStorageType(
96 FileSystemType type);
97
98 // Returns the string representation of the given filesystem |type|.
99 // Returns an empty string if the |type| is invalid.
100 WEBKIT_STORAGE_EXPORT std::string GetFileSystemTypeString(FileSystemType type);
101
102 // Sets type to FileSystemType enum that corresponds to the string name.
103 // Returns false if the |type_string| is invalid.
104 WEBKIT_STORAGE_EXPORT bool GetFileSystemPublicType(
105 std::string type_string,
106 WebKit::WebFileSystemType* type);
107
108 // Encodes |file_path| to a string.
109 // Following conditions should be held:
110 // - StringToFilePath(FilePathToString(path)) == path
111 // - StringToFilePath(FilePathToString(path) + "/" + "SubDirectory") ==
112 // path.AppendASCII("SubDirectory");
113 //
114 // TODO(tzik): Replace CreateFilePath and FilePathToString in
115 // third_party/leveldatabase/env_chromium.cc with them.
116 WEBKIT_STORAGE_EXPORT std::string FilePathToString(const base::FilePath& file_pa th);
117
118 // Decode a file path from |file_path_string|.
119 WEBKIT_STORAGE_EXPORT base::FilePath StringToFilePath(
120 const std::string& file_path_string);
121
122 // File error conversion
123 WEBKIT_STORAGE_EXPORT WebKit::WebFileError PlatformFileErrorToWebFileError(
124 base::PlatformFileError error_code);
125
126 // Generate a file system name for the given arguments. Should only be used by
127 // platform apps.
128 WEBKIT_STORAGE_EXPORT std::string GetIsolatedFileSystemName(
129 const GURL& origin_url,
130 const std::string& filesystem_id);
131
132 // Find the file system id from |filesystem_name|. Should only be used by
133 // platform apps. This function will return false if the file system name is
134 // not of the form {origin}:Isolated_{id}, and will also check that there is an
135 // origin and id present. It will not check that the origin or id are valid.
136 WEBKIT_STORAGE_EXPORT bool CrackIsolatedFileSystemName(
137 const std::string& filesystem_name,
138 std::string* filesystem_id);
139
140 // Returns the root URI for an isolated filesystem for origin |origin_url|
141 // and |filesystem_id|. If the |optional_root_name| is given the resulting
142 // root URI will point to the subfolder within the isolated filesystem.
143 WEBKIT_STORAGE_EXPORT std::string GetIsolatedFileSystemRootURIString(
144 const GURL& origin_url,
145 const std::string& filesystem_id,
146 const std::string& optional_root_name);
147
148 // Returns true if |url1| and |url2| belong to the same filesystem
149 // (i.e. url1.origin() == url2.origin() && url1.type() == url2.type())
150 WEBKIT_STORAGE_EXPORT bool AreSameFileSystem(
151 const FileSystemURL& url1,
152 const FileSystemURL& url2);
153
154 } // namespace fileapi
155
156 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698