File: file_system_util.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (164 lines) | stat: -rw-r--r-- 7,045 bytes parent folder | download | duplicates (6)
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
161
162
163
164
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef STORAGE_COMMON_FILE_SYSTEM_FILE_SYSTEM_UTIL_H_
#define STORAGE_COMMON_FILE_SYSTEM_FILE_SYSTEM_UTIL_H_

#include <string>
#include <vector>

#include "base/component_export.h"
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "storage/common/file_system/file_system_info.h"
#include "storage/common/file_system/file_system_types.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
#include "third_party/blink/public/platform/web_file_system_type.h"

class GURL;

namespace storage {

COMPONENT_EXPORT(STORAGE_COMMON) extern const char kPersistentDir[];
COMPONENT_EXPORT(STORAGE_COMMON) extern const char kTemporaryDir[];
COMPONENT_EXPORT(STORAGE_COMMON) extern const char kExternalDir[];
COMPONENT_EXPORT(STORAGE_COMMON) extern const char kIsolatedDir[];
COMPONENT_EXPORT(STORAGE_COMMON) extern const char kTestDir[];

class COMPONENT_EXPORT(STORAGE_COMMON) VirtualPath {
 public:
  static const base::FilePath::CharType kRoot[];
  static const base::FilePath::CharType kSeparator;

  // Use this instead of base::FilePath::BaseName when operating on virtual
  // paths. FilePath::BaseName will get confused by ':' on Windows when it
  // looks like a drive letter separator; this will treat it as just another
  // character.
  static base::FilePath BaseName(const base::FilePath& virtual_path);

  // Use this instead of base::FilePath::DirName when operating on virtual
  // paths.
  static base::FilePath DirName(const base::FilePath& virtual_path);

  // Likewise, use this instead of base::FilePath::GetComponents when
  // operating on virtual paths.
  // Note that this assumes very clean input, with no leading slash, and
  // it will not evaluate '..' components.
  static std::vector<base::FilePath::StringType> GetComponents(
      const base::FilePath& path);

  static std::vector<std::string> GetComponentsUTF8Unsafe(
      const base::FilePath& path);

  // Returns a path name ensuring that it begins with kRoot and all path
  // separators are forward slashes /.
  static base::FilePath::StringType GetNormalizedFilePath(
      const base::FilePath& path);

  // Returns true if the given path begins with kRoot.
  static bool IsAbsolute(const base::FilePath::StringType& path);

  // Returns true if the given path points to the root.
  static bool IsRootPath(const base::FilePath& path);
};

// Parses filesystem scheme |url| into uncracked file system URL components.
// Example: For a URL 'filesystem:http://foo.com/temporary/foo/bar',
// |origin_url| is set to 'http://foo.com', |type| is set to
// kFileSystemTypeTemporary, and |virtual_path| is set to 'foo/bar'.
COMPONENT_EXPORT(STORAGE_COMMON)
bool ParseFileSystemSchemeURL(const GURL& url,
                              GURL* origin_url,
                              FileSystemType* type,
                              base::FilePath* virtual_path);

// Returns the root URI of the filesystem that can be specified by a pair of
// |origin_url| and |type|.  The returned URI can be used as a root path
// of the filesystem (e.g. <returned_URI> + "/relative/path" will compose
// a path pointing to the entry "/relative/path" in the filesystem).
//
// For Isolated filesystem this returns the 'common' root part, e.g.
// returns URL without the filesystem ID.
//
// |type| needs to be public type as the returned URI is given to the renderer.
COMPONENT_EXPORT(STORAGE_COMMON)
GURL GetFileSystemRootURI(const GURL& origin_url, FileSystemType type);

// Returns the name for the filesystem that is specified by a pair of
// |origin_url| and |type|.
// (The name itself is neither really significant nor a formal identifier
// but can be read as the .name field of the returned FileSystem object
// as a user-friendly name in the javascript layer).
//
// |type| needs to be public type as the returned name is given to the renderer.
//
// Example:
//   The name for a TEMPORARY filesystem of "http://www.example.com:80/"
//   should look like: "http_www.example.host_80:temporary"
COMPONENT_EXPORT(STORAGE_COMMON)
std::string GetFileSystemName(const GURL& origin_url, FileSystemType type);

// Returns the string representation of the given filesystem |type|.
// Returns an empty string if the |type| is invalid.
COMPONENT_EXPORT(STORAGE_COMMON)
std::string GetFileSystemTypeString(FileSystemType type);

// Sets type to FileSystemType enum that corresponds to the string name.
// Returns false if the |type_string| is invalid.
COMPONENT_EXPORT(STORAGE_COMMON)
bool GetFileSystemPublicType(const std::string& type_string,
                             blink::WebFileSystemType* type);

// Encodes |file_path| to a string.
// Following conditions should be held:
//  - StringToFilePath(FilePathToString(path)) == path
//  - StringToFilePath(FilePathToString(path) + "/" + "SubDirectory") ==
//    path.AppendASCII("SubDirectory");
COMPONENT_EXPORT(STORAGE_COMMON)
std::string FilePathToString(const base::FilePath& file_path);

// Decode a file path from |file_path_string|.
COMPONENT_EXPORT(STORAGE_COMMON)
base::FilePath StringToFilePath(const std::string& file_path_string);

// Generate a file system name for the given arguments. Should only be used by
// platform apps.
COMPONENT_EXPORT(STORAGE_COMMON)
std::string GetIsolatedFileSystemName(const GURL& origin_url,
                                      const std::string& filesystem_id);

// Find the file system id from |filesystem_name|. Should only be used by
// platform apps. This function will return false if the file system name is
// not of the form {origin}:Isolated_{id}, and will also check that there is an
// origin and id present. It will not check that the origin or id are valid.
COMPONENT_EXPORT(STORAGE_COMMON)
bool CrackIsolatedFileSystemName(const std::string& filesystem_name,
                                 std::string* filesystem_id);

// Validates the given isolated file system id.
COMPONENT_EXPORT(STORAGE_COMMON)
bool ValidateIsolatedFileSystemId(const std::string& filesystem_id);

// Returns the root URI for an isolated filesystem for origin |origin_url|
// and |filesystem_id|. If the |optional_root_name| is given the resulting
// root URI will point to the subfolder within the isolated filesystem.
COMPONENT_EXPORT(STORAGE_COMMON)
std::string GetIsolatedFileSystemRootURIString(
    const GURL& origin_url,
    const std::string& filesystem_id,
    const std::string& optional_root_name);

// Returns the root URI for an external filesystem for origin |origin_url|
// and |mount_name|.
COMPONENT_EXPORT(STORAGE_COMMON)
std::string GetExternalFileSystemRootURIString(const GURL& origin_url,
                                               const std::string& mount_name);

// Translates the net::Error to base::File::Error.
COMPONENT_EXPORT(STORAGE_COMMON)
base::File::Error NetErrorToFileError(int error);

}  // namespace storage

#endif  // STORAGE_COMMON_FILE_SYSTEM_FILE_SYSTEM_UTIL_H_