summaryrefslogtreecommitdiffstats
path: root/webkit/browser/fileapi/dragged_file_util.cc
diff options
context:
space:
mode:
authorkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-13 10:40:44 +0000
committerkinuko@chromium.org <kinuko@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-13 10:40:44 +0000
commita322475db1b481a20f00e5a035330727047579aa (patch)
tree2a241b055e2a5b8ceb91dad7f953e0fc9259f5fa /webkit/browser/fileapi/dragged_file_util.cc
parent72ce213c4563a170db0f479246865e62d9718da8 (diff)
downloadchromium_src-a322475db1b481a20f00e5a035330727047579aa.zip
chromium_src-a322475db1b481a20f00e5a035330727047579aa.tar.gz
chromium_src-a322475db1b481a20f00e5a035330727047579aa.tar.bz2
AsyncFileUtil::CreateForLocalFileSystem() and deprecate IsolatedFileUtil
- Add static method AsyncFileUtil::CreateForLocalFileSystem() that creates a new instance to operate on LocalFileSystem using url.path() - Remove dependency to async_file_util_adapter.h and isolated_file_util.h from chrome/ - Rename isolated_file_util* to dragged_file_util* as it now only contains implementation for DraggedFileUtil BUG=265770 TBR=avi Review URL: https://chromiumcodereview.appspot.com/24044004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223022 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/browser/fileapi/dragged_file_util.cc')
-rw-r--r--webkit/browser/fileapi/dragged_file_util.cc108
1 files changed, 108 insertions, 0 deletions
diff --git a/webkit/browser/fileapi/dragged_file_util.cc b/webkit/browser/fileapi/dragged_file_util.cc
new file mode 100644
index 0000000..b4536a7
--- /dev/null
+++ b/webkit/browser/fileapi/dragged_file_util.cc
@@ -0,0 +1,108 @@
+// Copyright 2013 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 "webkit/browser/fileapi/dragged_file_util.h"
+
+#include <string>
+#include <vector>
+
+#include "base/file_util.h"
+#include "webkit/browser/fileapi/file_system_context.h"
+#include "webkit/browser/fileapi/file_system_operation_context.h"
+#include "webkit/browser/fileapi/file_system_url.h"
+#include "webkit/browser/fileapi/isolated_context.h"
+#include "webkit/browser/fileapi/native_file_util.h"
+#include "webkit/common/blob/shareable_file_reference.h"
+
+using base::PlatformFileError;
+using base::PlatformFileInfo;
+
+namespace fileapi {
+
+typedef IsolatedContext::MountPointInfo FileInfo;
+
+namespace {
+
+// Simply enumerate each path from a given fileinfo set.
+// Used to enumerate top-level paths of an isolated filesystem.
+class SetFileEnumerator : public FileSystemFileUtil::AbstractFileEnumerator {
+ public:
+ explicit SetFileEnumerator(const std::vector<FileInfo>& files)
+ : files_(files) {
+ file_iter_ = files_.begin();
+ }
+ virtual ~SetFileEnumerator() {}
+
+ // AbstractFileEnumerator overrides.
+ virtual base::FilePath Next() OVERRIDE {
+ if (file_iter_ == files_.end())
+ return base::FilePath();
+ base::FilePath platform_file = (file_iter_++)->path;
+ NativeFileUtil::GetFileInfo(platform_file, &file_info_);
+ return platform_file;
+ }
+ virtual int64 Size() OVERRIDE { return file_info_.size; }
+ virtual bool IsDirectory() OVERRIDE { return file_info_.is_directory; }
+ virtual base::Time LastModifiedTime() OVERRIDE {
+ return file_info_.last_modified;
+ }
+
+ private:
+ std::vector<FileInfo> files_;
+ std::vector<FileInfo>::const_iterator file_iter_;
+ base::PlatformFileInfo file_info_;
+};
+
+} // namespace
+
+//-------------------------------------------------------------------------
+
+DraggedFileUtil::DraggedFileUtil() {}
+
+PlatformFileError DraggedFileUtil::GetFileInfo(
+ FileSystemOperationContext* context,
+ const FileSystemURL& url,
+ PlatformFileInfo* file_info,
+ base::FilePath* platform_path) {
+ DCHECK(file_info);
+ std::string filesystem_id;
+ DCHECK(url.is_valid());
+ if (url.path().empty()) {
+ // The root directory case.
+ // For now we leave three time fields (modified/accessed/creation time)
+ // NULL as it is not really clear what to be set for this virtual directory.
+ // TODO(kinuko): Maybe we want to set the time when this filesystem is
+ // created (i.e. when the files/directories are dropped).
+ file_info->is_directory = true;
+ file_info->is_symbolic_link = false;
+ file_info->size = 0;
+ return base::PLATFORM_FILE_OK;
+ }
+ base::PlatformFileError error =
+ NativeFileUtil::GetFileInfo(url.path(), file_info);
+ if (file_util::IsLink(url.path()) && !base::FilePath().IsParent(url.path())) {
+ // Don't follow symlinks unless it's the one that are selected by the user.
+ return base::PLATFORM_FILE_ERROR_NOT_FOUND;
+ }
+ if (error == base::PLATFORM_FILE_OK)
+ *platform_path = url.path();
+ return error;
+}
+
+scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator>
+ DraggedFileUtil::CreateFileEnumerator(
+ FileSystemOperationContext* context,
+ const FileSystemURL& root) {
+ DCHECK(root.is_valid());
+ if (!root.path().empty())
+ return LocalFileUtil::CreateFileEnumerator(context, root);
+
+ // Root path case.
+ std::vector<FileInfo> toplevels;
+ IsolatedContext::GetInstance()->GetDraggedFileInfo(
+ root.filesystem_id(), &toplevels);
+ return scoped_ptr<AbstractFileEnumerator>(new SetFileEnumerator(toplevels));
+}
+
+} // namespace fileapi