| 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 "webkit/fileapi/file_system_dir_url_request_job.h" | 5 #include "webkit/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" |
| 11 #include "base/files/file_util_proxy.h" | |
| 12 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 13 #include "base/platform_file.h" | 12 #include "base/platform_file.h" |
| 14 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 15 #include "base/time.h" | 14 #include "base/time.h" |
| 16 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 17 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 18 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 19 #include "net/base/io_buffer.h" | 18 #include "net/base/io_buffer.h" |
| 20 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 21 #include "net/base/net_util.h" | 20 #include "net/base/net_util.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 net::PlatformFileErrorToNetError(error_code))); | 86 net::PlatformFileErrorToNetError(error_code))); |
| 88 return; | 87 return; |
| 89 } | 88 } |
| 90 operation->ReadDirectory( | 89 operation->ReadDirectory( |
| 91 url_, | 90 url_, |
| 92 base::Bind(&FileSystemDirURLRequestJob::DidReadDirectory, this)); | 91 base::Bind(&FileSystemDirURLRequestJob::DidReadDirectory, this)); |
| 93 } | 92 } |
| 94 | 93 |
| 95 void FileSystemDirURLRequestJob::DidReadDirectory( | 94 void FileSystemDirURLRequestJob::DidReadDirectory( |
| 96 base::PlatformFileError result, | 95 base::PlatformFileError result, |
| 97 const std::vector<base::FileUtilProxy::Entry>& entries, | 96 const std::vector<FileSystemOperation::Entry>& entries, |
| 98 bool has_more) { | 97 bool has_more) { |
| 99 if (result != base::PLATFORM_FILE_OK) { | 98 if (result != base::PLATFORM_FILE_OK) { |
| 100 int rv = net::ERR_FILE_NOT_FOUND; | 99 int rv = net::ERR_FILE_NOT_FOUND; |
| 101 if (result == base::PLATFORM_FILE_ERROR_INVALID_URL) | 100 if (result == base::PLATFORM_FILE_ERROR_INVALID_URL) |
| 102 rv = net::ERR_INVALID_URL; | 101 rv = net::ERR_INVALID_URL; |
| 103 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 102 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
| 104 return; | 103 return; |
| 105 } | 104 } |
| 106 | 105 |
| 107 if (!request_) | 106 if (!request_) |
| 108 return; | 107 return; |
| 109 | 108 |
| 110 if (data_.empty()) { | 109 if (data_.empty()) { |
| 111 base::FilePath relative_path = url_.path(); | 110 base::FilePath relative_path = url_.path(); |
| 112 #if defined(OS_POSIX) | 111 #if defined(OS_POSIX) |
| 113 relative_path = base::FilePath(FILE_PATH_LITERAL("/") + relative_path.value(
)); | 112 relative_path = base::FilePath(FILE_PATH_LITERAL("/") + relative_path.value(
)); |
| 114 #endif | 113 #endif |
| 115 const base::string16& title = relative_path.LossyDisplayName(); | 114 const base::string16& title = relative_path.LossyDisplayName(); |
| 116 data_.append(net::GetDirectoryListingHeader(title)); | 115 data_.append(net::GetDirectoryListingHeader(title)); |
| 117 } | 116 } |
| 118 | 117 |
| 119 typedef std::vector<base::FileUtilProxy::Entry>::const_iterator EntryIterator; | 118 typedef std::vector<FileSystemOperation::Entry>::const_iterator EntryIterator; |
| 120 for (EntryIterator it = entries.begin(); it != entries.end(); ++it) { | 119 for (EntryIterator it = entries.begin(); it != entries.end(); ++it) { |
| 121 const base::string16& name = base::FilePath(it->name).LossyDisplayName(); | 120 const base::string16& name = base::FilePath(it->name).LossyDisplayName(); |
| 122 data_.append(net::GetDirectoryListingEntry( | 121 data_.append(net::GetDirectoryListingEntry( |
| 123 name, std::string(), it->is_directory, it->size, | 122 name, std::string(), it->is_directory, it->size, |
| 124 it->last_modified_time)); | 123 it->last_modified_time)); |
| 125 } | 124 } |
| 126 | 125 |
| 127 if (has_more) { | 126 if (has_more) { |
| 128 base::PlatformFileError error_code; | 127 base::PlatformFileError error_code; |
| 129 FileSystemOperation* operation = GetNewOperation(&error_code); | 128 FileSystemOperation* operation = GetNewOperation(&error_code); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 142 NotifyHeadersComplete(); | 141 NotifyHeadersComplete(); |
| 143 } | 142 } |
| 144 } | 143 } |
| 145 | 144 |
| 146 FileSystemOperation* FileSystemDirURLRequestJob::GetNewOperation( | 145 FileSystemOperation* FileSystemDirURLRequestJob::GetNewOperation( |
| 147 base::PlatformFileError* error_code) { | 146 base::PlatformFileError* error_code) { |
| 148 return file_system_context_->CreateFileSystemOperation(url_, error_code); | 147 return file_system_context_->CreateFileSystemOperation(url_, error_code); |
| 149 } | 148 } |
| 150 | 149 |
| 151 } // namespace fileapi | 150 } // namespace fileapi |
| OLD | NEW |