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

Side by Side Diff: runtime/bin/file_patch.dart

Issue 23483030: Make file system watcher compile on Mac OS 106, and add a runtime-call to test if the system suppor… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 3 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 patch class _FileUtils { 5 patch class _FileUtils {
6 /* patch */ static SendPort _newServicePort() native "File_NewServicePort"; 6 /* patch */ static SendPort _newServicePort() native "File_NewServicePort";
7 } 7 }
8 8
9 patch class _File { 9 patch class _File {
10 /* patch */ static _exists(String path) native "File_Exists"; 10 /* patch */ static _exists(String path) native "File_Exists";
(...skipping 28 matching lines...) Expand all
39 native "File_SetPosition"; 39 native "File_SetPosition";
40 /* patch */ static _truncate(int id, int length) native "File_Truncate"; 40 /* patch */ static _truncate(int id, int length) native "File_Truncate";
41 /* patch */ static _length(int id) native "File_Length"; 41 /* patch */ static _length(int id) native "File_Length";
42 /* patch */ static _flush(int id) native "File_Flush"; 42 /* patch */ static _flush(int id) native "File_Flush";
43 } 43 }
44 44
45 patch class _FileSystemWatcher { 45 patch class _FileSystemWatcher {
46 /* patch */ factory _FileSystemWatcher( 46 /* patch */ factory _FileSystemWatcher(
47 String path, int events, bool recursive) 47 String path, int events, bool recursive)
48 => new _FileSystemWatcherImpl(path, events, recursive); 48 => new _FileSystemWatcherImpl(path, events, recursive);
49
50 /* patch */ static bool get isSupported => _FileSystemWatcherImpl.isSupported;
kustermann 2013/09/03 15:18:58 Wouldn't it make sense to cache the 'isSupported'
Anders Johnsen 2013/09/03 15:32:56 As this is not performance critical, I'll not cach
49 } 51 }
50 52
51 class _FileSystemWatcherImpl 53 class _FileSystemWatcherImpl
52 extends NativeFieldWrapperClass1 54 extends NativeFieldWrapperClass1
53 implements _FileSystemWatcher { 55 implements _FileSystemWatcher {
54 final String _path; 56 final String _path;
55 final int _events; 57 final int _events;
56 final bool _recursive; 58 final bool _recursive;
57 59
58 StreamController _controller; 60 StreamController _controller;
59 StreamSubscription _subscription; 61 StreamSubscription _subscription;
60 62
61 _FileSystemWatcherImpl(this._path, this._events, this._recursive) { 63 _FileSystemWatcherImpl(this._path, this._events, this._recursive) {
64 if (!isSupported) {
65 throw new FileException(
66 "File system watching is not supported on this system",
67 _path);
68 }
62 _controller = new StreamController(onListen: _listen, onCancel: _cancel); 69 _controller = new StreamController(onListen: _listen, onCancel: _cancel);
63 } 70 }
64 71
65 void _listen() { 72 void _listen() {
66 int socketId; 73 int socketId;
67 try { 74 try {
68 socketId = _watchPath(_path, _events, identical(true, _recursive)); 75 socketId = _watchPath(_path, _events, identical(true, _recursive));
69 } catch (e) { 76 } catch (e) {
70 throw new FileException( 77 throw new FileException(
71 "Failed to watch path", 78 "Failed to watch path",
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 140
134 void _cancel() { 141 void _cancel() {
135 _unwatchPath(); 142 _unwatchPath();
136 if (_subscription != null) { 143 if (_subscription != null) {
137 _subscription.cancel(); 144 _subscription.cancel();
138 } 145 }
139 } 146 }
140 147
141 Stream<FileSystemEvent> get stream => _controller.stream; 148 Stream<FileSystemEvent> get stream => _controller.stream;
142 149
150 static bool get isSupported native "FileSystemWatcher_IsSupported";
151
143 int _watchPath(String path, int events, bool recursive) 152 int _watchPath(String path, int events, bool recursive)
144 native "FileSystemWatcher_WatchPath"; 153 native "FileSystemWatcher_WatchPath";
145 void _unwatchPath() native "FileSystemWatcher_UnwatchPath"; 154 void _unwatchPath() native "FileSystemWatcher_UnwatchPath";
146 List _readEvents() native "FileSystemWatcher_ReadEvents"; 155 List _readEvents() native "FileSystemWatcher_ReadEvents";
147 } 156 }
148 157
149 Uint8List _makeUint8ListView(Uint8List source, int offsetInBytes, int length) { 158 Uint8List _makeUint8ListView(Uint8List source, int offsetInBytes, int length) {
150 return new Uint8List.view(source.buffer, offsetInBytes, length); 159 return new Uint8List.view(source.buffer, offsetInBytes, length);
151 } 160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698