File: mount_points.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 (114 lines) | stat: -rw-r--r-- 4,413 bytes parent folder | download | duplicates (9)
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
// Copyright 2013 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_BROWSER_FILE_SYSTEM_MOUNT_POINTS_H_
#define STORAGE_BROWSER_FILE_SYSTEM_MOUNT_POINTS_H_

#include <string>
#include <vector>

#include "base/component_export.h"
#include "base/files/file_path.h"
#include "storage/common/file_system/file_system_util.h"

class GURL;

namespace blink {
class StorageKey;
}  // namespace blink

namespace storage {
class FileSystemMountOption;
class FileSystemURL;

// Represents a set of mount points for File API.
class COMPONENT_EXPORT(STORAGE_BROWSER) MountPoints {
 public:
  struct COMPONENT_EXPORT(STORAGE_BROWSER) MountPointInfo {
    MountPointInfo();
    MountPointInfo(const std::string& name, const base::FilePath& path);

    // The name to be used to register the path. The registered file can
    // be referred by a virtual path /<filesystem_id>/<name>.
    // The name should NOT contain a path separator '/'.
    std::string name;

    // The path of the file.
    base::FilePath path;

    // For STL operation.
    bool operator<(const MountPointInfo& that) const {
      return name < that.name;
    }
  };

  MountPoints() = default;
  MountPoints(const MountPoints&) = delete;
  MountPoints& operator=(const MountPoints&) = delete;
  virtual ~MountPoints() = default;

  // Revokes a mount point identified by |mount_name|.
  // Returns false if the |mount_name| is not (no longer) registered.
  // TODO(kinuko): Probably this should be rather named RevokeMountPoint.
  virtual bool RevokeFileSystem(const std::string& mount_name) = 0;

  // Returns true if the MountPoints implementation handles filesystems with
  // the given mount type.
  virtual bool HandlesFileSystemMountType(FileSystemType type) const = 0;

  // TODO(crbug.com/40194313): Determine if MountPoints::CrackURL()
  // and its overrides in child classes should be removed and replaced with
  // FileSystemContext::CrackURL().
  //
  // Same as CreateCrackedFileSystemURL, but cracks a FileSystemURL created
  // from `url` and `storage_key`.
  virtual FileSystemURL CrackURL(
      const GURL& url,
      const blink::StorageKey& storage_key) const = 0;

  // Creates a FileSystemURL with the given `storage_key`, `type`, and
  // `virtual_path` and tries to crack it as a part of one of the registered
  // mount points. If the the URL is not valid or does not belong to any of the
  // mount points registered in this context, returns empty, invalid
  // FileSystemURL.
  virtual FileSystemURL CreateCrackedFileSystemURL(
      const blink::StorageKey& storage_key,
      FileSystemType type,
      const base::FilePath& virtual_path) const = 0;

  // Returns the mount point root path registered for a given |mount_name|.
  // Returns false if the given |mount_name| is not valid.
  virtual bool GetRegisteredPath(const std::string& mount_name,
                                 base::FilePath* path) const = 0;

  // Cracks the given |virtual_path| (which is the path part of a filesystem URL
  // without '/external' or '/isolated' prefix part) and populates the
  // |mount_name|, |type|, and |path| if the <mount_name> part embedded in
  // the |virtual_path| (i.e. the first component of the |virtual_path|) is a
  // valid registered filesystem ID or mount name for an existing mount point.
  //
  // Returns false if the given virtual_path cannot be cracked.
  //
  // Note that |path| is set to empty paths if the filesystem type is isolated
  // and |virtual_path| has no <relative_path> part (i.e. pointing to the
  // virtual root).
  virtual bool CrackVirtualPath(const base::FilePath& virtual_path,
                                std::string* mount_name,
                                FileSystemType* type,
                                std::string* cracked_id,
                                base::FilePath* path,
                                FileSystemMountOption* mount_option) const = 0;

 protected:
  friend class FileSystemContext;

  // Same as CrackURL and CreateCrackedFileSystemURL, but cracks the url already
  // instantiated as the FileSystemURL class. This is internally used for nested
  // URL cracking in FileSystemContext.
  virtual FileSystemURL CrackFileSystemURL(const FileSystemURL& url) const = 0;
};

}  // namespace storage

#endif  // STORAGE_BROWSER_FILE_SYSTEM_MOUNT_POINTS_H_