tree: 2bf2619834dfeb2e1d8b44ec753133a22a8d257e [path history] [tgz]
  1. OWNERS
  2. README.md
  3. async_file_util.h
  4. async_file_util_adapter.cc
  5. async_file_util_adapter.h
  6. copy_or_move_file_validator.h
  7. copy_or_move_file_validator_unittest.cc
  8. copy_or_move_operation_delegate.cc
  9. copy_or_move_operation_delegate.h
  10. copy_or_move_operation_delegate_unittest.cc
  11. dragged_file_util.cc
  12. dragged_file_util.h
  13. dragged_file_util_unittest.cc
  14. dump_file_system.cc
  15. external_mount_points.cc
  16. external_mount_points.h
  17. external_mount_points_unittest.cc
  18. file_observers.h
  19. file_permission_policy.h
  20. file_stream_reader.cc
  21. file_stream_reader.h
  22. file_stream_test_utils.cc
  23. file_stream_test_utils.h
  24. file_stream_writer.h
  25. file_system_backend.h
  26. file_system_context.cc
  27. file_system_context.h
  28. file_system_context_unittest.cc
  29. file_system_dir_url_request_job.cc
  30. file_system_dir_url_request_job.h
  31. file_system_dir_url_request_job_unittest.cc
  32. file_system_features.cc
  33. file_system_features.h
  34. file_system_file_stream_reader.cc
  35. file_system_file_stream_reader.h
  36. file_system_file_stream_reader_unittest.cc
  37. file_system_file_util.cc
  38. file_system_file_util.h
  39. file_system_operation.h
  40. file_system_operation_context.cc
  41. file_system_operation_context.h
  42. file_system_operation_impl.cc
  43. file_system_operation_impl.h
  44. file_system_operation_impl_unittest.cc
  45. file_system_operation_impl_write_unittest.cc
  46. file_system_operation_runner.cc
  47. file_system_operation_runner.h
  48. file_system_options.cc
  49. file_system_options.h
  50. file_system_quota_client.cc
  51. file_system_quota_client.h
  52. file_system_quota_client_unittest.cc
  53. file_system_quota_util.h
  54. file_system_url.cc
  55. file_system_url.h
  56. file_system_url_request_job.cc
  57. file_system_url_request_job.h
  58. file_system_url_request_job_factory.cc
  59. file_system_url_request_job_factory.h
  60. file_system_url_request_job_unittest.cc
  61. file_system_url_unittest.cc
  62. file_system_usage_cache.cc
  63. file_system_usage_cache.h
  64. file_system_usage_cache_unittest.cc
  65. file_writer_delegate.cc
  66. file_writer_delegate.h
  67. file_writer_delegate_unittest.cc
  68. isolated_context.cc
  69. isolated_context.h
  70. isolated_context_unittest.cc
  71. isolated_file_system_backend.cc
  72. isolated_file_system_backend.h
  73. local_file_stream_reader.cc
  74. local_file_stream_reader.h
  75. local_file_stream_reader_unittest.cc
  76. local_file_stream_writer.cc
  77. local_file_stream_writer.h
  78. local_file_stream_writer_unittest.cc
  79. local_file_util.cc
  80. local_file_util.h
  81. local_file_util_unittest.cc
  82. memory_file_stream_reader.cc
  83. memory_file_stream_reader.h
  84. memory_file_stream_reader_unittest.cc
  85. memory_file_stream_writer.cc
  86. memory_file_stream_writer.h
  87. memory_file_stream_writer_unittest.cc
  88. mount_points.cc
  89. mount_points.h
  90. native_file_util.cc
  91. native_file_util.h
  92. native_file_util_unittest.cc
  93. obfuscated_file_util.cc
  94. obfuscated_file_util.h
  95. obfuscated_file_util_delegate.h
  96. obfuscated_file_util_disk_delegate.cc
  97. obfuscated_file_util_disk_delegate.h
  98. obfuscated_file_util_memory_delegate.cc
  99. obfuscated_file_util_memory_delegate.h
  100. obfuscated_file_util_memory_delegate_unittest.cc
  101. obfuscated_file_util_unittest.cc
  102. open_file_system_mode.h
  103. plugin_private_file_system_backend.cc
  104. plugin_private_file_system_backend.h
  105. plugin_private_file_system_backend_unittest.cc
  106. quota/
  107. recursive_operation_delegate.cc
  108. recursive_operation_delegate.h
  109. recursive_operation_delegate_unittest.cc
  110. remove_operation_delegate.cc
  111. remove_operation_delegate.h
  112. sandbox_directory_database.cc
  113. sandbox_directory_database.h
  114. sandbox_directory_database_unittest.cc
  115. sandbox_file_stream_writer.cc
  116. sandbox_file_stream_writer.h
  117. sandbox_file_system_backend.cc
  118. sandbox_file_system_backend.h
  119. sandbox_file_system_backend_delegate.cc
  120. sandbox_file_system_backend_delegate.h
  121. sandbox_file_system_backend_delegate_unittest.cc
  122. sandbox_file_system_backend_unittest.cc
  123. sandbox_isolated_origin_database.cc
  124. sandbox_isolated_origin_database.h
  125. sandbox_isolated_origin_database_unittest.cc
  126. sandbox_origin_database.cc
  127. sandbox_origin_database.h
  128. sandbox_origin_database_interface.cc
  129. sandbox_origin_database_interface.h
  130. sandbox_origin_database_unittest.cc
  131. sandbox_prioritized_origin_database.cc
  132. sandbox_prioritized_origin_database.h
  133. sandbox_prioritized_origin_database_unittest.cc
  134. sandbox_quota_observer.cc
  135. sandbox_quota_observer.h
  136. task_runner_bound_observer_list.h
  137. transient_file_util.cc
  138. transient_file_util.h
  139. transient_file_util_unittest.cc
  140. watcher_manager.h
storage/browser/fileapi/README.md

FileSystem API

This directory contains part of the browser side implementation of various filesystem related APIs, as well as interfaces to treat various types of native and non-native filesystems mostly the same without having to worry about the underlying implementation.

Related directories

//content/browser/fileapi/ contains the rest of the browser side implementation, while blink/renderer/modules/filesystem contains the renderer side implementation and blink/public/mojom/filesystem contains the mojom interfaces for these APIs.

File System Types

There are two kinds of file system types supported by the file system implementation: Internal types and public types. //storage/common/fileapi/file_system_types.h has an enum of all the various types that exist. Many of these are Chrome OS specific or only make sense in the context of extensions.

Public Types

The three public file system types are:

  • Sandboxed file systems (with both a temporary and a persistent variant), implemented by storage::SandboxFileSystemBackend;
  • “Isolated” file systems, which wrap one of the internal types, managed by storage::IsolatedContext and implemented by storage::IsolatedFileSystemBackend; and
  • “External” file systems, which also wrap one of the internal types, managed by storage::ExternalMountPoints.

External File Systems

External File Systems are only used by Chrome OS. A lot of the code for this (besides storage::ExternalMountPoints itself) lives in //chrome/browser/chromeos/fileapi/.

TODO(mek): Document this more.

Sandboxed File Systems

The sandbox file system backend provides for per-origin, quota-managed file systems, as specified in the (deprecated) File API: Directories and System specification. There are two flavors of this, “temporary” and “persistent”.

This same file system (or at least the “temporary” version) is also exposed via the new Native File System API.

Isolated File Systems

Isolated file systems generally are used to expose files from other file system types to the web for the Files and Directory Entries API, either via Drag&Drop or <input type=file>. They are also used for the (deprecated) Chrome Apps chrome.fileSystem API, and the new Native File System API.

Interesting Classes

storage::FileSystemContext

This is the main entry point for any interaction with the file system subsystem. It is created (via content::CreateFileSystemContext) and owned by each Storage Partition.

It owns:

  • Via scoped_refptr a optional storage::ExternalMountPoints instance to deal with BrowserContext specific external file systems. Currently always nullptr, except on Chrome OS.

  • A storage::SandboxFileSystemBackendDelegate. This is used by both the backend for the regular sandboxed file system, and for the chrome extensions specific “sync” file system.

  • Via scoped_refptr a bunch of storage::FileSystemBackend instances. These are either created by the FileSystemContext itself (for sandbox, plugin private, and isolated file systems) or passed in to constructor after requesting the additional backends from the content embedder via ContentBrowserClient::GetAdditionalFileSystemBackends.

And further more it references:

  • An ordered set of URL crackers (storage::MountPoints instances). This consists of the optional browser context specific ExternalMountPoints, a global singleton ExternalMountPoints and finally a global singleton IsolatedContext.

storage::SandboxFileSystemBackend

The main entry point of support for sandboxed file systems. This class forwards all operations to the FileSystemContext owned SandboxFileSystemBackendDelegate instance, which does the actual work.

storage::SandboxFileSystemBackendDelegate

The actual main entry point for sandboxed file systems, but as mentioned also used for the Chrome Extensions specific sync file system.

This class delegates operating on files to a storage::ObfuscatedFileUtil instance it owns (wrapped in a AsyncFileUtilAdapter).

It is however responsible for interacting with the quota system. In order to do that it maintains a separate cache of how much disk is being used by various origins/file system types using a FileSystemUsageCache instance. This basically adds a flat file in every directory for a origin/file system type containing the total disk usage of that directory, and some extra meta data.

storage::ObfuscatedFileUtil

This class uses several leveldb databases to translate virtual file paths given by arbitrary untrusted apps to obfuscated file paths that are supported by the underlying file system. First of all it uses SandboxPrioritizedOriginDatabase to map origins to paths, and then owns one SandboxDirectoryDatabase per origin per file system type (each with their own leveldb database) to map files within that origin to obfuscated file names.

See class comments for ObfuscatedFileUtil for more detail on how this works as well.

Important to note that this class doesn't actually deal with any operations on the files themselves. It merely keeps track of metadata. For actual operations on the files this class merely translates the virtual file paths to “real” file paths and then passes those on to a ObfuscatedFileUtilDelegate instance for the actual file operations. There are two possible implementations of this delegate, one that stores all the files in memory (for incognito mode) and one that stores the files on disk inside the profile directory.

storage::IsolatedContext

This class keeps track of all currently registered Isolate File Systems. Isolated file systems are identified by the hex encoding of 16 random bytes of data.

Life time of individual isolated file systems is reference counted, using AddReference and RemoveReference methods. For certain paths it is however also possible to entirely reokve the file system without waiting for its reference count to go to zero.

Today reference counts are increased/decreased implicitly by granting access to certain file systems to certain renderer processes (i.e. content::ChildProcessSecurityPolicyImpl calls AddReference when permission is granted, and call RemoveReference when the process is destroyed on all the file systems that renderer has access to). The Native File System API will introduce its own way of adding and removing references to these file systems.