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

Unified Diff: runtime/bin/directory_impl.dart

Issue 9500002: Rename blahHandler to onBlah throughout dart:io. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Renaming Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: runtime/bin/directory_impl.dart
diff --git a/runtime/bin/directory_impl.dart b/runtime/bin/directory_impl.dart
index d5a9953b38fb08b9cf9bb3633e1c41d30cfcdd5a..b0937e0e31449b1f0bd4aa4fab18fac01f67ac64 100644
--- a/runtime/bin/directory_impl.dart
+++ b/runtime/bin/directory_impl.dart
@@ -26,7 +26,7 @@ class _Directory implements Directory {
static bool _delete(String path, bool recursive) native "Directory_Delete";
static SendPort _newServicePort() native "Directory_NewServicePort";
- void exists() {
+ void exists(void callback(bool exists)) {
if (_directoryService == null) {
_directoryService = _newServicePort();
}
@@ -34,14 +34,12 @@ class _Directory implements Directory {
request[0] = kExistsRequest;
request[1] = _path;
_directoryService.call(request).receive((result, replyTo) {
- var handler =
- (_existsHandler != null) ? _existsHandler : (result) => null;
if (result < 0) {
- if (_errorHandler != null) {
- _errorHandler("Diretory exists test failed: $_path");
+ if (_onError != null) {
+ _onError("Diretory exists test failed: $_path");
}
} else {
- handler(result == 1);
+ callback(result == 1);
}
});
}
@@ -54,7 +52,7 @@ class _Directory implements Directory {
return (exists == 1);
}
- void create() {
+ void create(void callback()) {
if (_directoryService == null) {
_directoryService = _newServicePort();
}
@@ -63,9 +61,9 @@ class _Directory implements Directory {
request[1] = _path;
_directoryService.call(request).receive((result, replyTo) {
if (result) {
- if (_createHandler != null) _createHandler();
- } else if (_errorHandler != null) {
- _errorHandler("Directory creation failed: $_path");
+ callback();
+ } else if (_onError != null) {
+ _onError("Directory creation failed: $_path");
}
});
}
@@ -76,7 +74,7 @@ class _Directory implements Directory {
}
}
- void createTemp() {
+ void createTemp(void callback()) {
if (_directoryService == null) {
_directoryService = _newServicePort();
}
@@ -86,9 +84,9 @@ class _Directory implements Directory {
_directoryService.call(request).receive((result, replyTo) {
if (result is !List) {
_path = result;
- if (_createTempHandler != null) _createTempHandler();
- } else if (_errorHandler != null) {
- _errorHandler("Could not create temporary directory [$_path]: " +
+ callback();
+ } else if (_onError != null) {
+ _onError("Could not create temporary directory [$_path]: " +
Søren Gjesse 2012/02/29 15:42:20 Indentation.
Mads Ager (google) 2012/03/06 07:05:13 Done.
"${result[1]}");
}
});
@@ -107,7 +105,7 @@ class _Directory implements Directory {
}
}
- void delete([bool recursive = false]) {
+ void delete(bool recursive, void callback()) {
Søren Gjesse 2012/02/29 15:42:20 We should consider revising this to not take a boo
Mads Ager (google) 2012/03/06 07:05:13 I have gone for two separate methods here. delete
if (_directoryService == null) {
_directoryService = _newServicePort();
}
@@ -117,12 +115,12 @@ class _Directory implements Directory {
request[2] = recursive;
_directoryService.call(request).receive((result, replyTo) {
if (result) {
- if (_deleteHandler != null) _deleteHandler();
- } else if (_errorHandler != null) {
+ callback();
+ } else if (_onError != null) {
if (recursive) {
- _errorHandler("Recursive directory deletion failed: $_path");
+ _onError("Recursive directory deletion failed: $_path");
} else {
- _errorHandler("Non-recursive directory deletion failed: $_path");
+ _onError("Non-recursive directory deletion failed: $_path");
}
}
});
@@ -151,57 +149,41 @@ class _Directory implements Directory {
responsePort.receive((message, replyTo) {
if (message is !List || message[0] is !int) {
responsePort.close();
- if (_errorHandler != null) _errorHandler("Internal error");
+ if (_onError != null) _onError("Internal error");
return;
}
switch (message[0]) {
case kListDirectory:
- if (_dirHandler != null) _dirHandler(message[1]);
+ if (_onDir != null) _onDir(message[1]);
break;
case kListFile:
- if (_fileHandler != null) _fileHandler(message[1]);
+ if (_onFile != null) _onFile(message[1]);
break;
case kListError:
- if (_errorHandler != null) _errorHandler(message[1]);
+ if (_onError != null) _onError(message[1]);
break;
case kListDone:
responsePort.close();
- if (_doneHandler != null) _doneHandler(message[1]);
+ if (_onDone != null) _onDone(message[1]);
break;
}
});
}
- void set dirHandler(void dirHandler(String dir)) {
- _dirHandler = dirHandler;
+ void set onDir(void onDir(String dir)) {
+ _onDir = onDir;
}
- void set fileHandler(void fileHandler(String file)) {
- _fileHandler = fileHandler;
+ void set onFile(void onFile(String file)) {
+ _onFile = onFile;
}
- void set doneHandler(void doneHandler(bool completed)) {
- _doneHandler = doneHandler;
+ void set onDone(void onDone(bool completed)) {
+ _onDone = onDone;
}
- void set existsHandler(void existsHandler(bool exists)) {
- _existsHandler = existsHandler;
- }
-
- void set createHandler(void createHandler()) {
- _createHandler = createHandler;
- }
-
- void set createTempHandler(void createTempHandler()) {
- _createTempHandler = createTempHandler;
- }
-
- void set deleteHandler(void deleteHandler()) {
- _deleteHandler = deleteHandler;
- }
-
- void set errorHandler(void errorHandler(String error)) {
- _errorHandler = errorHandler;
+ void set onError(void onError(String error)) {
+ _onError = onError;
}
void _closePort(ReceivePort port) {
@@ -212,14 +194,10 @@ class _Directory implements Directory {
String get path() { return _path; }
- var _dirHandler;
- var _fileHandler;
- var _doneHandler;
- var _existsHandler;
- var _createHandler;
- var _createTempHandler;
- var _deleteHandler;
- var _errorHandler;
+ var _onDir;
+ var _onFile;
+ var _onDone;
+ var _onError;
String _path;
SendPort _directoryService;

Powered by Google App Engine
This is Rietveld 408576698