| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:nativewrappers'; | 5 import 'dart:nativewrappers'; |
| 6 | 6 |
| 7 import 'dart:_mojo/application.dart'; | 7 import 'dart:_mojo/application.dart'; |
| 8 import 'dart:_mojo/bindings.dart'; | 8 import 'dart:_mojo/bindings.dart'; |
| 9 import 'dart:_mojo/core.dart'; | 9 import 'dart:_mojo/core.dart'; |
| 10 import 'dart:_mojo/mojo/network_error.mojom.dart'; | 10 import 'dart:_mojo/mojo/network_error.mojom.dart'; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 /// Get the singleton HostResolverProxy. | 107 /// Get the singleton HostResolverProxy. |
| 108 HostResolverProxy _getHostResolver() { | 108 HostResolverProxy _getHostResolver() { |
| 109 if (_hostResolver != null) { | 109 if (_hostResolver != null) { |
| 110 return _hostResolver; | 110 return _hostResolver; |
| 111 } | 111 } |
| 112 var networkService = _getNetworkService(); | 112 var networkService = _getNetworkService(); |
| 113 if (networkService == null) { | 113 if (networkService == null) { |
| 114 return null; | 114 return null; |
| 115 } | 115 } |
| 116 _hostResolver = new HostResolverProxy.unbound(); | 116 _hostResolver = new HostResolverProxy.unbound(); |
| 117 networkService.ptr.createHostResolver(_hostResolver); | 117 networkService.createHostResolver(_hostResolver); |
| 118 // Remove the host resolver's handle from the open set because it is not | 118 // Remove the host resolver's handle from the open set because it is not |
| 119 // under application control and does not affect isolate shutdown. | 119 // under application control and does not affect isolate shutdown. |
| 120 _hostResolver.impl.endpoint.handle.pass(); | 120 _hostResolver.ctrl.endpoint.handle.pass(); |
| 121 return _hostResolver; | 121 return _hostResolver; |
| 122 } | 122 } |
| 123 | 123 |
| 124 /// Get the singleton FilesProxy. | 124 /// Get the singleton FilesProxy. |
| 125 FilesProxy _getFiles() { | 125 FilesProxy _getFiles() { |
| 126 if (_files != null) { | 126 if (_files != null) { |
| 127 return _files; | 127 return _files; |
| 128 } | 128 } |
| 129 _files = new FilesProxy.fromHandle( | 129 _files = new FilesProxy.fromHandle( |
| 130 new MojoHandle(_filesServiceHandle).pass()); | 130 new MojoHandle(_filesServiceHandle).pass()); |
| 131 _filesServiceHandle = null; | 131 _filesServiceHandle = null; |
| 132 return _files; | 132 return _files; |
| 133 } | 133 } |
| 134 | 134 |
| 135 /// Get the singleton DirectoryProxy for the root directory. | 135 /// Get the singleton DirectoryProxy for the root directory. |
| 136 Future<DirectoryProxy> _getRootDirectory() async { | 136 Future<DirectoryProxy> _getRootDirectory() async { |
| 137 if (_rootDirectory != null) { | 137 if (_rootDirectory != null) { |
| 138 return _rootDirectory; | 138 return _rootDirectory; |
| 139 } | 139 } |
| 140 FilesProxy files = _getFiles(); | 140 FilesProxy files = _getFiles(); |
| 141 assert(files != null); | 141 assert(files != null); |
| 142 _rootDirectory = new DirectoryProxy.unbound(); | 142 _rootDirectory = new DirectoryProxy.unbound(); |
| 143 var response = | 143 var response = |
| 144 await files.ptr.openFileSystem(fileSystemName, _rootDirectory); | 144 await files.openFileSystem(fileSystemName, _rootDirectory); |
| 145 // Remove the root directory's handle from the open set because it is not | 145 // Remove the root directory's handle from the open set because it is not |
| 146 // under application control and does not affect isolate shutdown. | 146 // under application control and does not affect isolate shutdown. |
| 147 _rootDirectory.impl.endpoint.handle.pass(); | 147 _rootDirectory.ctrl.endpoint.handle.pass(); |
| 148 | 148 |
| 149 // Ensure system temporary directory exists before returning the root | 149 // Ensure system temporary directory exists before returning the root |
| 150 // directory. | 150 // directory. |
| 151 await _getSystemTempDirectory(); | 151 await _getSystemTempDirectory(); |
| 152 return _rootDirectory; | 152 return _rootDirectory; |
| 153 } | 153 } |
| 154 | 154 |
| 155 /// Get the singleton DirectoryProxy for the system temp directory. | 155 /// Get the singleton DirectoryProxy for the system temp directory. |
| 156 Future<DirectoryProxy> _getSystemTempDirectory() async { | 156 Future<DirectoryProxy> _getSystemTempDirectory() async { |
| 157 if (_systemTempDirectory != null) { | 157 if (_systemTempDirectory != null) { |
| 158 return _systempTempDirectory; | 158 return _systempTempDirectory; |
| 159 } | 159 } |
| 160 DirectoryProxy rootDirectory = await _getRootDirectory(); | 160 DirectoryProxy rootDirectory = await _getRootDirectory(); |
| 161 int flags = types.kOpenFlagRead | | 161 int flags = types.kOpenFlagRead | |
| 162 types.kOpenFlagWrite | | 162 types.kOpenFlagWrite | |
| 163 types.kOpenFlagCreate; | 163 types.kOpenFlagCreate; |
| 164 _systemTempDirectory = new DirectoryProxy.unbound(); | 164 _systemTempDirectory = new DirectoryProxy.unbound(); |
| 165 var response = | 165 var response = |
| 166 await rootDirectory.ptr.openDirectory(systemTempPath, | 166 await rootDirectory.openDirectory(systemTempPath, |
| 167 _systemTempDirectory, | 167 _systemTempDirectory, |
| 168 flags); | 168 flags); |
| 169 assert(response.error == types.Error.ok); | 169 assert(response.error == types.Error.ok); |
| 170 // Remove the system temp directory's handle from the open set because it | 170 // Remove the system temp directory's handle from the open set because it |
| 171 // is not under application control and does not affect isolate shutdown. | 171 // is not under application control and does not affect isolate shutdown. |
| 172 _systemTempDirectory.impl.endpoint.handle.pass(); | 172 _systemTempDirectory.ctrl.endpoint.handle.pass(); |
| 173 return _systemTempDirectory; | 173 return _systemTempDirectory; |
| 174 } | 174 } |
| 175 | 175 |
| 176 /// Static utility methods for converting between 'dart:io' and | 176 /// Static utility methods for converting between 'dart:io' and |
| 177 /// 'mojo:network_service' structs. | 177 /// 'mojo:network_service' structs. |
| 178 class _NetworkServiceCodec { | 178 class _NetworkServiceCodec { |
| 179 /// Returns a string representation of an ip address encoded in [address]. | 179 /// Returns a string representation of an ip address encoded in [address]. |
| 180 /// Supports both IPv4 and IPv6. | 180 /// Supports both IPv4 and IPv6. |
| 181 static String _addressToString(List<int> address) { | 181 static String _addressToString(List<int> address) { |
| 182 String r = ''; | 182 String r = ''; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 } | 294 } |
| 295 | 295 |
| 296 static _throwOnError(NetworkError error) { | 296 static _throwOnError(NetworkError error) { |
| 297 if (_okay(error)) { | 297 if (_okay(error)) { |
| 298 return; | 298 return; |
| 299 } | 299 } |
| 300 throw new OSError(error.description, error.code); | 300 throw new OSError(error.description, error.code); |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 | 303 |
| OLD | NEW |