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

Side by Side Diff: sdk/lib/io/directory_impl.dart

Issue 14070010: Refactor Future constructors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Added co19 issue number. Created 7 years, 8 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
« no previous file with comments | « sdk/lib/indexed_db/dartium/indexed_db_dartium.dart ('k') | sdk/lib/io/file_impl.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 part of dart.io; 5 part of dart.io;
6 6
7 class _Directory implements Directory { 7 class _Directory implements Directory {
8 static const CREATE_REQUEST = 0; 8 static const CREATE_REQUEST = 0;
9 static const DELETE_REQUEST = 1; 9 static const DELETE_REQUEST = 1;
10 static const EXISTS_REQUEST = 2; 10 static const EXISTS_REQUEST = 2;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 // none of the directories exist dirsToCreate.length is returned. 57 // none of the directories exist dirsToCreate.length is returned.
58 Future<int> _computeExistingIndex(List dirsToCreate) { 58 Future<int> _computeExistingIndex(List dirsToCreate) {
59 var future; 59 var future;
60 var notFound = dirsToCreate.length; 60 var notFound = dirsToCreate.length;
61 for (var i = 0; i < dirsToCreate.length; i++) { 61 for (var i = 0; i < dirsToCreate.length; i++) {
62 if (future == null) { 62 if (future == null) {
63 future = dirsToCreate[i].exists().then((e) => e ? i : notFound); 63 future = dirsToCreate[i].exists().then((e) => e ? i : notFound);
64 } else { 64 } else {
65 future = future.then((index) { 65 future = future.then((index) {
66 if (index != notFound) { 66 if (index != notFound) {
67 return new Future.immediate(index); 67 return new Future.value(index);
68 } 68 }
69 return dirsToCreate[i].exists().then((e) => e ? i : notFound); 69 return dirsToCreate[i].exists().then((e) => e ? i : notFound);
70 }); 70 });
71 } 71 }
72 } 72 }
73 if (future == null) { 73 if (future == null) {
74 return new Future.immediate(notFound); 74 return new Future.value(notFound);
75 } else { 75 } else {
76 return future; 76 return future;
77 } 77 }
78 } 78 }
79 79
80 Future<Directory> createRecursively() { 80 Future<Directory> createRecursively() {
81 if (_path is !String) { 81 if (_path is !String) {
82 throw new ArgumentError(); 82 throw new ArgumentError();
83 } 83 }
84 var path = new Path(_path); 84 var path = new Path(_path);
85 var dirsToCreate = []; 85 var dirsToCreate = [];
86 var terminator = path.isAbsolute ? '/' : ''; 86 var terminator = path.isAbsolute ? '/' : '';
87 while (path.toString() != terminator) { 87 while (path.toString() != terminator) {
88 dirsToCreate.add(new Directory.fromPath(path)); 88 dirsToCreate.add(new Directory.fromPath(path));
89 path = path.directoryPath; 89 path = path.directoryPath;
90 } 90 }
91 return _computeExistingIndex(dirsToCreate).then((index) { 91 return _computeExistingIndex(dirsToCreate).then((index) {
92 var future; 92 var future;
93 for (var i = index - 1; i >= 0 ; i--) { 93 for (var i = index - 1; i >= 0 ; i--) {
94 if (future == null) { 94 if (future == null) {
95 future = dirsToCreate[i].create(); 95 future = dirsToCreate[i].create();
96 } else { 96 } else {
97 future = future.then((_) { 97 future = future.then((_) {
98 return dirsToCreate[i].create(); 98 return dirsToCreate[i].create();
99 }); 99 });
100 } 100 }
101 } 101 }
102 if (future == null) { 102 if (future == null) {
103 return new Future.immediate(this); 103 return new Future.value(this);
104 } else { 104 } else {
105 return future.then((_) => this); 105 return future.then((_) => this);
106 } 106 }
107 }); 107 });
108 } 108 }
109 109
110 Future<Directory> create({recursive: false}) { 110 Future<Directory> create({recursive: false}) {
111 if (recursive) return createRecursively(); 111 if (recursive) return createRecursively();
112 _ensureDirectoryService(); 112 _ensureDirectoryService();
113 List request = new List(2); 113 List request = new List(2);
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 323
324 void _ensureDirectoryService() { 324 void _ensureDirectoryService() {
325 if (_directoryService == null) { 325 if (_directoryService == null) {
326 _directoryService = _newServicePort(); 326 _directoryService = _newServicePort();
327 } 327 }
328 } 328 }
329 329
330 final String _path; 330 final String _path;
331 SendPort _directoryService; 331 SendPort _directoryService;
332 } 332 }
OLDNEW
« no previous file with comments | « sdk/lib/indexed_db/dartium/indexed_db_dartium.dart ('k') | sdk/lib/io/file_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698