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

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

Issue 3001963002: [dart:io] Namespaces for file IO (Closed)
Patch Set: Fuchsia fix Created 3 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
« no previous file with comments | « runtime/bin/main.cc ('k') | runtime/bin/namespace.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4
5 #ifndef RUNTIME_BIN_NAMESPACE_H_
6 #define RUNTIME_BIN_NAMESPACE_H_
7
8 #include "bin/builtin.h"
9 #include "bin/dartutils.h"
10 #include "bin/log.h"
11 #include "bin/reference_counting.h"
12
13 namespace dart {
14 namespace bin {
15
16 class Namespace : public ReferenceCounted<Namespace> {
17 public:
18 // Assumes napespc is a value that can be directly used as namespc_.
19 static Namespace* Create(intptr_t namespc) {
20 return new Namespace(namespc);
21 }
22
23 // Uses path to compute a value that can be used as namespc_.
24 static Namespace* Create(const char* path);
25
26 // Gives a safe defautl value for namespc_ for the standalone Dart VM.
27 static intptr_t Default();
28
29 // Tells whether the given namespace is the default namespace.
30 static bool IsDefault(Namespace* namespc);
31
32 // Returns the native namespace wrapper if the argument at the supplied index
33 // is a _NamespaceImpl object. If it is not, calls Dart_PropagateError().
34 static Namespace* GetNamespace(Dart_NativeArguments args, intptr_t index);
35
36 // Get and set the current working directory through the namespace if there
37 // is one.
38 static const char* GetCurrent(Namespace* namespc);
39 static bool SetCurrent(Namespace* namespc, const char* path);
40
41 intptr_t namespc() const { return namespc_; }
42
43 private:
44 // When namespc_ has this value, it indicates that there is currently
45 // no namespace for resolving absolute paths.
46 static const intptr_t kNone = 0;
47
48 explicit Namespace(intptr_t namespc)
49 : ReferenceCounted(), namespc_(namespc) {}
50
51 ~Namespace();
52
53 // When the native argument at |index| is a _NamespaceImpl object,
54 // write the valueof its native field into |namespc|.
55 static Dart_Handle GetNativeNamespaceArgument(Dart_NativeArguments args,
56 intptr_t index,
57 Namespace** namespc);
58
59 // Given a namespace and a path, computes the information needed to access the
60 // path relative to the namespace. This can include massaging the path and
61 // returning a platform specific value in dirfd that together are used to
62 // access the path. Returns true if the caller should take ownership of
63 // dirfd, and false if the namespace retains ownership of dirfd.
64 static bool ResolvePath(Namespace* namespc,
65 const char* path,
66 intptr_t* dirfd,
67 const char** resolved_path);
68
69 intptr_t namespc_;
70 // TODO(zra): When Isolate-specific cwds are added, we'll need some more
71 // fields here to track them.
72
73 friend class NamespaceScope;
74 friend class ReferenceCounted<Namespace>;
75 DISALLOW_COPY_AND_ASSIGN(Namespace);
76 };
77
78 class NamespaceScope {
79 public:
80 explicit NamespaceScope(Namespace* namespc, const char* path);
81 ~NamespaceScope();
82
83 intptr_t fd() const { return fd_; }
84 const char* path() const { return path_; }
85
86 private:
87 intptr_t fd_;
88 const char* path_;
89 bool owns_fd_;
90
91 DISALLOW_ALLOCATION();
92 DISALLOW_COPY_AND_ASSIGN(NamespaceScope);
93 };
94
95 } // namespace bin
96 } // namespace dart
97
98 #endif // RUNTIME_BIN_NAMESPACE_H_
OLDNEW
« no previous file with comments | « runtime/bin/main.cc ('k') | runtime/bin/namespace.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698