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

Side by Side Diff: webkit/fileapi/isolated_file_util.cc

Issue 13850004: Ignore symlinks in Drag-and-drop'ed folder (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: indent fix 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 | « no previous file | webkit/fileapi/isolated_file_util_unittest.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 Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/fileapi/isolated_file_util.h" 5 #include "webkit/fileapi/isolated_file_util.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "webkit/blob/shareable_file_reference.h" 10 #include "webkit/blob/shareable_file_reference.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 virtual base::Time LastModifiedTime() OVERRIDE { 46 virtual base::Time LastModifiedTime() OVERRIDE {
47 return file_info_.last_modified; 47 return file_info_.last_modified;
48 } 48 }
49 49
50 private: 50 private:
51 std::vector<FileInfo> files_; 51 std::vector<FileInfo> files_;
52 std::vector<FileInfo>::const_iterator file_iter_; 52 std::vector<FileInfo>::const_iterator file_iter_;
53 base::PlatformFileInfo file_info_; 53 base::PlatformFileInfo file_info_;
54 }; 54 };
55 55
56 // Recursively enumerate each path from a given paths set.
57 class RecursiveSetFileEnumerator
58 : public FileSystemFileUtil::AbstractFileEnumerator {
59 public:
60 explicit RecursiveSetFileEnumerator(const std::vector<FileInfo>& files)
61 : files_(files) {
62 file_iter_ = files_.begin();
63 current_enumerator_.reset(new SetFileEnumerator(files));
64 }
65 virtual ~RecursiveSetFileEnumerator() {}
66
67 // AbstractFileEnumerator overrides.
68 virtual base::FilePath Next() OVERRIDE;
69 virtual int64 Size() OVERRIDE {
70 DCHECK(current_enumerator_.get());
71 return current_enumerator_->Size();
72 }
73 virtual bool IsDirectory() OVERRIDE {
74 DCHECK(current_enumerator_.get());
75 return current_enumerator_->IsDirectory();
76 }
77 virtual base::Time LastModifiedTime() OVERRIDE {
78 DCHECK(current_enumerator_.get());
79 return current_enumerator_->LastModifiedTime();
80 }
81
82 private:
83 std::vector<FileInfo> files_;
84 std::vector<FileInfo>::iterator file_iter_;
85 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> current_enumerator_;
86 };
87
88 base::FilePath RecursiveSetFileEnumerator::Next() {
89 if (current_enumerator_.get()) {
90 base::FilePath path = current_enumerator_->Next();
91 if (!path.empty())
92 return path;
93 }
94
95 // We reached the end.
96 if (file_iter_ == files_.end())
97 return base::FilePath();
98
99 // Enumerates subdirectories of the next path.
100 FileInfo& next_file = *file_iter_++;
101 current_enumerator_ = NativeFileUtil::CreateFileEnumerator(
102 next_file.path, true /* recursive */);
103 DCHECK(current_enumerator_.get());
104 return current_enumerator_->Next();
105 }
106
107 } // namespace 56 } // namespace
108 57
109 //------------------------------------------------------------------------- 58 //-------------------------------------------------------------------------
110 59
111 IsolatedFileUtil::IsolatedFileUtil() {} 60 IsolatedFileUtil::IsolatedFileUtil() {}
112 61
113 PlatformFileError IsolatedFileUtil::GetLocalFilePath( 62 PlatformFileError IsolatedFileUtil::GetLocalFilePath(
114 FileSystemOperationContext* context, 63 FileSystemOperationContext* context,
115 const FileSystemURL& url, 64 const FileSystemURL& url,
116 base::FilePath* local_file_path) { 65 base::FilePath* local_file_path) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 if (error == base::PLATFORM_FILE_OK) 105 if (error == base::PLATFORM_FILE_OK)
157 *platform_path = url.path(); 106 *platform_path = url.path();
158 return error; 107 return error;
159 } 108 }
160 109
161 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> 110 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator>
162 DraggedFileUtil::CreateFileEnumerator( 111 DraggedFileUtil::CreateFileEnumerator(
163 FileSystemOperationContext* context, 112 FileSystemOperationContext* context,
164 const FileSystemURL& root, 113 const FileSystemURL& root,
165 bool recursive) { 114 bool recursive) {
115 if (recursive) {
116 NOTREACHED() << "Recursive enumeration not supported.";
117 return scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator>(
118 new EmptyFileEnumerator);
119 }
166 DCHECK(root.is_valid()); 120 DCHECK(root.is_valid());
167 if (!root.path().empty()) 121 if (!root.path().empty())
168 return NativeFileUtil::CreateFileEnumerator(root.path(), recursive); 122 return LocalFileUtil::CreateFileEnumerator(context, root, recursive);
169 123
170 // Root path case. 124 // Root path case.
171 std::vector<FileInfo> toplevels; 125 std::vector<FileInfo> toplevels;
172 IsolatedContext::GetInstance()->GetDraggedFileInfo( 126 IsolatedContext::GetInstance()->GetDraggedFileInfo(
173 root.filesystem_id(), &toplevels); 127 root.filesystem_id(), &toplevels);
174 if (!recursive) { 128 return scoped_ptr<AbstractFileEnumerator>(new SetFileEnumerator(toplevels));
175 return make_scoped_ptr(new SetFileEnumerator(toplevels))
176 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>();
177 }
178 return make_scoped_ptr(new RecursiveSetFileEnumerator(toplevels))
179 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>();
180 } 129 }
181 130
182 } // namespace fileapi 131 } // namespace fileapi
OLDNEW
« no previous file with comments | « no previous file | webkit/fileapi/isolated_file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698