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

Unified Diff: mojo/dart/embedder/io/mojo_patch.dart

Issue 1539843004: Support some file operations in dart:io under mojo (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/dart/embedder/io/file_patch.dart ('k') | services/dart/dart_apptests/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/dart/embedder/io/mojo_patch.dart
diff --git a/mojo/dart/embedder/io/mojo_patch.dart b/mojo/dart/embedder/io/mojo_patch.dart
index 99da0cec06038eaf32e2c82e4aab3aaae50abb89..1a48f01565834e724c7f2e017198088e75d5d1ac 100644
--- a/mojo/dart/embedder/io/mojo_patch.dart
+++ b/mojo/dart/embedder/io/mojo_patch.dart
@@ -16,7 +16,16 @@ import 'dart:_mojo_services/mojo/files/file.mojom.dart';
import 'dart:_mojo_services/mojo/files/files.mojom.dart';
import 'dart:_mojo_services/mojo/files/directory.mojom.dart';
import 'dart:_mojo_services/mojo/files/ioctl.mojom.dart';
-import 'dart:_mojo_services/mojo/files/types.mojom.dart';
+import 'dart:_mojo_services/mojo/files/types.mojom.dart' as types;
+
+// When developing, set fileSystemDeveloper to true and the file system will
+// persist under ~/MojoAppPersistentCaches/.
+const bool fileSystemDeveloper = false;
+const String fileSystemName =
+ fileSystemDeveloper ? 'app_persistent_cache' : null;
+
+// System temp path relative to the root directory.
+const String systemTempPath = 'tmp';
//
// Mojo objects and helper functions used by the 'dart:io' library.
@@ -26,6 +35,8 @@ int _filesServiceHandle;
NetworkServiceProxy _networkService;
HostResolverProxy _hostResolver;
FilesProxy _files;
+DirectoryProxy _rootDirectory;
+DirectoryProxy _systemTempDirectory;
void _initialize(int networkServiceHandle, int filesServiceHandle) {
if (networkServiceHandle != MojoHandle.INVALID) {
@@ -67,6 +78,14 @@ _closeProxies() {
_files.close(immediate: true);
_files = null;
}
+ if (_rootDirectory != null) {
+ _rootDirectory.close(immediate: true);
+ _rootDirectory = null;
+ }
+ if (_systemTempDirectory != null) {
+ _systemTempDirectory.close(immediate: true);
+ _systemTempDirectory = null;
+ }
}
/// Get the singleton NetworkServiceProxy.
@@ -108,6 +127,47 @@ FilesProxy _getFiles() {
return _files;
}
+/// Get the singleton DirectoryProxy for the root directory.
+Future<DirectoryProxy> _getRootDirectory() async {
+ if (_rootDirectory != null) {
+ return _rootDirectory;
+ }
+ FilesProxy files = _getFiles();
+ assert(files != null);
+ _rootDirectory = new DirectoryProxy.unbound();
+ var response =
+ await files.ptr.openFileSystem(fileSystemName, _rootDirectory);
+ // Remove the root directory's handle from the open set because it is not
+ // under application control and does not affect isolate shutdown.
+ _rootDirectory.impl.endpoint.handle.pass();
+
+ // Ensure system temporary directory exists before returning the root
+ // directory.
+ await _getSystemTempDirectory();
+ return _rootDirectory;
+}
+
+/// Get the singleton DirectoryProxy for the system temp directory.
+Future<DirectoryProxy> _getSystemTempDirectory() async {
+ if (_systemTempDirectory != null) {
+ return _systempTempDirectory;
+ }
+ DirectoryProxy rootDirectory = await _getRootDirectory();
+ int flags = types.kOpenFlagRead |
+ types.kOpenFlagWrite |
+ types.kOpenFlagCreate;
+ _systemTempDirectory = new DirectoryProxy.unbound();
+ var response =
+ await rootDirectory.ptr.openDirectory(systemTempPath,
+ _systemTempDirectory,
+ flags);
+ assert(response.error == types.Error.ok);
+ // Remove the system temp directory's handle from the open set because it
+ // is not under application control and does not affect isolate shutdown.
+ _systemTempDirectory.impl.endpoint.handle.pass();
+ return _systemTempDirectory;
+}
+
/// Static utility methods for converting between 'dart:io' and
/// 'mojo:network_service' structs.
class _NetworkServiceCodec {
« no previous file with comments | « mojo/dart/embedder/io/file_patch.dart ('k') | services/dart/dart_apptests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698