OLD | NEW |
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 "storage/browser/fileapi/file_system_dir_url_request_job.h" | 5 #include "storage/browser/fileapi/file_system_dir_url_request_job.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 if (data_.empty()) { | 135 if (data_.empty()) { |
136 base::FilePath relative_path = url_.path(); | 136 base::FilePath relative_path = url_.path(); |
137 #if defined(OS_POSIX) | 137 #if defined(OS_POSIX) |
138 relative_path = | 138 relative_path = |
139 base::FilePath(FILE_PATH_LITERAL("/") + relative_path.value()); | 139 base::FilePath(FILE_PATH_LITERAL("/") + relative_path.value()); |
140 #endif | 140 #endif |
141 const base::string16& title = relative_path.LossyDisplayName(); | 141 const base::string16& title = relative_path.LossyDisplayName(); |
142 data_.append(net::GetDirectoryListingHeader(title)); | 142 data_.append(net::GetDirectoryListingHeader(title)); |
143 } | 143 } |
144 | 144 |
145 typedef std::vector<DirectoryEntry>::const_iterator EntryIterator; | 145 entries_.insert(entries_.end(), entries.begin(), entries.end()); |
146 for (EntryIterator it = entries.begin(); it != entries.end(); ++it) { | 146 |
147 const base::string16& name = base::FilePath(it->name).LossyDisplayName(); | 147 if (!has_more) { |
148 data_.append(net::GetDirectoryListingEntry( | 148 if (entries_.size()) { |
149 name, std::string(), it->is_directory, it->size, | 149 GetMetadata(0); |
150 it->last_modified_time)); | 150 } else { |
| 151 set_expected_content_size(data_.size()); |
| 152 NotifyHeadersComplete(); |
| 153 } |
| 154 } |
| 155 } |
| 156 |
| 157 void FileSystemDirURLRequestJob::GetMetadata(size_t index) { |
| 158 const DirectoryEntry& entry = entries_[index]; |
| 159 const FileSystemURL url = file_system_context_->CreateCrackedFileSystemURL( |
| 160 url_.origin(), url_.type(), |
| 161 url_.path().Append(base::FilePath(entry.name))); |
| 162 DCHECK(url.is_valid()); |
| 163 file_system_context_->operation_runner()->GetMetadata( |
| 164 url, |
| 165 base::Bind(&FileSystemDirURLRequestJob::DidGetMetadata, this, index)); |
| 166 } |
| 167 |
| 168 void FileSystemDirURLRequestJob::DidGetMetadata( |
| 169 size_t index, |
| 170 base::File::Error result, |
| 171 const base::File::Info& file_info) { |
| 172 if (result != base::File::FILE_OK) { |
| 173 int rv = net::ERR_FILE_NOT_FOUND; |
| 174 if (result == base::File::FILE_ERROR_INVALID_URL) |
| 175 rv = net::ERR_INVALID_URL; |
| 176 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
151 } | 177 } |
152 | 178 |
153 if (!has_more) { | 179 if (!request_) |
| 180 return; |
| 181 |
| 182 const DirectoryEntry& entry = entries_[index]; |
| 183 const base::string16& name = base::FilePath(entry.name).LossyDisplayName(); |
| 184 data_.append(net::GetDirectoryListingEntry(name, std::string(), |
| 185 entry.is_directory, file_info.size, |
| 186 file_info.last_modified)); |
| 187 |
| 188 if (index < entries_.size() - 1) { |
| 189 GetMetadata(index + 1); |
| 190 } else { |
154 set_expected_content_size(data_.size()); | 191 set_expected_content_size(data_.size()); |
155 NotifyHeadersComplete(); | 192 NotifyHeadersComplete(); |
156 } | 193 } |
157 } | 194 } |
158 | 195 |
159 } // namespace storage | 196 } // namespace storage |
OLD | NEW |