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

Unified Diff: services/file_manager/util.cc

Issue 875643004: Prototype of Files service. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: wipwipwip Created 5 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 side-by-side diff with in-line comments
Download patch
« services/file_manager/file.mojom ('K') | « services/file_manager/util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/file_manager/util.cc
diff --git a/services/file_manager/util.cc b/services/file_manager/util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c4192145e8a21a506a1eb26e5b082bf13b47be3e
--- /dev/null
+++ b/services/file_manager/util.cc
@@ -0,0 +1,59 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "services/file_manager/util.h"
+
+#include <errno.h>
+
+#include "base/logging.h"
+#include "base/strings/string_util.h"
+#include "mojo/public/cpp/bindings/string.h"
+
+namespace mojo {
+namespace files {
+
+Error IsPathValid(const String& path) {
+ DCHECK(!path.is_null());
+ if (!base::IsStringUTF8(path.get()))
+ return ERROR_INVALID_ARGUMENT;
+ if (path.size() > 0 && path[0] == '/')
+ return ERROR_PERMISSION_DENIED;
+ return ERROR_OK;
+}
+
+Error IsWhenceValid(Whence whence) {
+ return (whence == WHENCE_FROM_CURRENT || whence == WHENCE_FROM_START ||
+ whence == WHENCE_FROM_END)
+ ? ERROR_OK
+ : ERROR_UNIMPLEMENTED;
+}
+
+Error IsOffsetValid(int64_t offset) {
+ return (offset >= std::numeric_limits<off_t>::min() &&
+ offset <= std::numeric_limits<off_t>::max())
+ ? ERROR_OK
+ : ERROR_OUT_OF_RANGE;
+}
+
+Error ErrnoToError(int errno_value) {
+ // TODO(vtl)
+ return ERROR_UNKNOWN;
+}
+
+int WhenceToStandardWhence(Whence whence) {
+ DCHECK_EQ(IsWhenceValid(whence), ERROR_OK);
+ switch (whence) {
+ case WHENCE_FROM_CURRENT:
+ return SEEK_CUR;
+ case WHENCE_FROM_START:
+ return SEEK_SET;
+ case WHENCE_FROM_END:
+ return SEEK_END;
+ }
+ NOTREACHED();
+ return 0;
+}
+
+} // namespace files
+} // namespace mojo
« services/file_manager/file.mojom ('K') | « services/file_manager/util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698