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

Side by Side Diff: runtime/bin/directory.h

Issue 11748017: Add synchronous directory listing to dart:io Directory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments, move tests that fail on Windows due to VM bug 7157 to a separate test file. Created 7 years, 11 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 | « runtime/bin/builtin_natives.cc ('k') | runtime/bin/directory.cc » ('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 #ifndef BIN_DIRECTORY_H_ 5 #ifndef BIN_DIRECTORY_H_
6 #define BIN_DIRECTORY_H_ 6 #define BIN_DIRECTORY_H_
7 7
8 #include "bin/builtin.h" 8 #include "bin/builtin.h"
9 #include "bin/dartutils.h" 9 #include "bin/dartutils.h"
10 #include "platform/globals.h" 10 #include "platform/globals.h"
11 #include "platform/thread.h" 11 #include "platform/thread.h"
12 12
13 class DirectoryListing { 13 class DirectoryListing {
14 public: 14 public:
15 virtual ~DirectoryListing() {}
16 virtual bool HandleDirectory(char* dir_name) = 0;
17 virtual bool HandleFile(char* file_name) = 0;
18 virtual bool HandleError(const char* dir_name) = 0;
19 };
20
21
22 class AsyncDirectoryListing : public DirectoryListing {
23 public:
15 enum Response { 24 enum Response {
16 kListDirectory = 0, 25 kListDirectory = 0,
17 kListFile = 1, 26 kListFile = 1,
18 kListError = 2, 27 kListError = 2,
19 kListDone = 3 28 kListDone = 3
20 }; 29 };
21 30
22 explicit DirectoryListing(Dart_Port response_port) 31 explicit AsyncDirectoryListing(Dart_Port response_port)
23 : response_port_(response_port) {} 32 : response_port_(response_port) {}
24 bool HandleDirectory(char* dir_name); 33 virtual ~AsyncDirectoryListing() {}
25 bool HandleFile(char* file_name); 34 virtual bool HandleDirectory(char* dir_name);
26 bool HandleError(const char* dir_name); 35 virtual bool HandleFile(char* file_name);
36 virtual bool HandleError(const char* dir_name);
27 37
28 private: 38 private:
29 CObjectArray* NewResponse(Response response, char* arg); 39 CObjectArray* NewResponse(Response response, char* arg);
30 Dart_Port response_port_; 40 Dart_Port response_port_;
31 41
32 DISALLOW_IMPLICIT_CONSTRUCTORS(DirectoryListing); 42 DISALLOW_IMPLICIT_CONSTRUCTORS(AsyncDirectoryListing);
33 }; 43 };
34 44
35 45
46 class SyncDirectoryListing: public DirectoryListing {
47 public:
48 explicit SyncDirectoryListing(Dart_Handle results)
49 : results_(results) {
50 add_string_ = DartUtils::NewString("add");
51 directory_class_ =
52 DartUtils::GetDartClass(DartUtils::kIOLibURL, "Directory");
53 file_class_ =
54 DartUtils::GetDartClass(DartUtils::kIOLibURL, "File");
55 }
56 virtual ~SyncDirectoryListing() {}
57 virtual bool HandleDirectory(char* dir_name);
58 virtual bool HandleFile(char* file_name);
59 virtual bool HandleError(const char* dir_name);
60
61 private:
62 Dart_Handle results_;
63 Dart_Handle add_string_;
64 Dart_Handle directory_class_;
65 Dart_Handle file_class_;
66
67 DISALLOW_IMPLICIT_CONSTRUCTORS(SyncDirectoryListing);
68 };
69
70
36 class Directory { 71 class Directory {
37 public: 72 public:
38 enum ExistsResult { 73 enum ExistsResult {
39 UNKNOWN, 74 UNKNOWN,
40 EXISTS, 75 EXISTS,
41 DOES_NOT_EXIST 76 DOES_NOT_EXIST
42 }; 77 };
43 78
44 // This enum must be kept in sync with the request values in 79 // This enum must be kept in sync with the request values in
45 // directory_impl.dart. 80 // directory_impl.dart.
(...skipping 22 matching lines...) Expand all
68 static int service_ports_size_; 103 static int service_ports_size_;
69 static Dart_Port* service_ports_; 104 static Dart_Port* service_ports_;
70 static int service_ports_index_; 105 static int service_ports_index_;
71 106
72 DISALLOW_ALLOCATION(); 107 DISALLOW_ALLOCATION();
73 DISALLOW_IMPLICIT_CONSTRUCTORS(Directory); 108 DISALLOW_IMPLICIT_CONSTRUCTORS(Directory);
74 }; 109 };
75 110
76 111
77 #endif // BIN_DIRECTORY_H_ 112 #endif // BIN_DIRECTORY_H_
OLDNEW
« no previous file with comments | « runtime/bin/builtin_natives.cc ('k') | runtime/bin/directory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698