| 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/file_util_proxy.h" | 11 #include "base/file_util_proxy.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/platform_file.h" | 13 #include "base/platform_file.h" |
| 14 #include "base/sys_string_conversions.h" | 14 #include "base/sys_string_conversions.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 19 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
| 20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 21 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
| 22 #include "net/url_request/url_request.h" | 22 #include "net/url_request/url_request.h" |
| 23 #include "webkit/fileapi/file_system_callback_dispatcher.h" | 23 #include "webkit/fileapi/file_system_callback_dispatcher.h" |
| 24 #include "webkit/fileapi/file_system_context.h" |
| 24 #include "webkit/fileapi/file_system_operation.h" | 25 #include "webkit/fileapi/file_system_operation.h" |
| 25 #include "webkit/fileapi/file_system_util.h" | 26 #include "webkit/fileapi/file_system_util.h" |
| 26 | 27 |
| 27 using net::URLRequest; | 28 using net::URLRequest; |
| 28 using net::URLRequestJob; | 29 using net::URLRequestJob; |
| 29 using net::URLRequestStatus; | 30 using net::URLRequestStatus; |
| 30 | 31 |
| 31 namespace fileapi { | 32 namespace fileapi { |
| 32 | 33 |
| 33 static FilePath GetRelativePath(const GURL& url) { | 34 static FilePath GetRelativePath(const GURL& url) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 *mime_type = "text/html"; | 133 *mime_type = "text/html"; |
| 133 return true; | 134 return true; |
| 134 } | 135 } |
| 135 | 136 |
| 136 bool FileSystemDirURLRequestJob::GetCharset(std::string* charset) { | 137 bool FileSystemDirURLRequestJob::GetCharset(std::string* charset) { |
| 137 *charset = "utf-8"; | 138 *charset = "utf-8"; |
| 138 return true; | 139 return true; |
| 139 } | 140 } |
| 140 | 141 |
| 141 void FileSystemDirURLRequestJob::StartAsync() { | 142 void FileSystemDirURLRequestJob::StartAsync() { |
| 142 if (request_) | 143 if (!request_) |
| 143 GetNewOperation()->ReadDirectory(request_->url()); | 144 return; |
| 145 FileSystemOperationInterface* operation = GetNewOperation(request_->url()); |
| 146 if (!operation) { |
| 147 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
| 148 net::ERR_INVALID_URL)); |
| 149 return; |
| 150 } |
| 151 operation->ReadDirectory(request_->url()); |
| 144 } | 152 } |
| 145 | 153 |
| 146 void FileSystemDirURLRequestJob::DidReadDirectory( | 154 void FileSystemDirURLRequestJob::DidReadDirectory( |
| 147 const std::vector<base::FileUtilProxy::Entry>& entries, | 155 const std::vector<base::FileUtilProxy::Entry>& entries, |
| 148 bool has_more) { | 156 bool has_more) { |
| 149 if (!request_) | 157 if (!request_) |
| 150 return; | 158 return; |
| 151 | 159 |
| 152 if (data_.empty()) { | 160 if (data_.empty()) { |
| 153 FilePath relative_path = GetRelativePath(request_->url()); | 161 FilePath relative_path = GetRelativePath(request_->url()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 167 #elif defined(OS_POSIX) | 175 #elif defined(OS_POSIX) |
| 168 const string16& name = | 176 const string16& name = |
| 169 WideToUTF16(base::SysNativeMBToWide(it->name)); | 177 WideToUTF16(base::SysNativeMBToWide(it->name)); |
| 170 #endif | 178 #endif |
| 171 data_.append(net::GetDirectoryListingEntry( | 179 data_.append(net::GetDirectoryListingEntry( |
| 172 name, std::string(), it->is_directory, it->size, | 180 name, std::string(), it->is_directory, it->size, |
| 173 it->last_modified_time)); | 181 it->last_modified_time)); |
| 174 } | 182 } |
| 175 | 183 |
| 176 if (has_more) { | 184 if (has_more) { |
| 177 GetNewOperation()->ReadDirectory(request_->url()); | 185 GetNewOperation(request_->url())->ReadDirectory(request_->url()); |
| 178 } else { | 186 } else { |
| 179 set_expected_content_size(data_.size()); | 187 set_expected_content_size(data_.size()); |
| 180 NotifyHeadersComplete(); | 188 NotifyHeadersComplete(); |
| 181 } | 189 } |
| 182 } | 190 } |
| 183 | 191 |
| 184 FileSystemOperation* FileSystemDirURLRequestJob::GetNewOperation() { | 192 FileSystemOperationInterface* |
| 185 return new FileSystemOperation(CallbackDispatcher::Create(this), | 193 FileSystemDirURLRequestJob::GetNewOperation(const GURL& url) { |
| 186 file_thread_proxy_, | 194 return file_system_context_->CreateFileSystemOperation( |
| 187 file_system_context_); | 195 url, |
| 196 CallbackDispatcher::Create(this), |
| 197 file_thread_proxy_); |
| 188 } | 198 } |
| 189 | 199 |
| 190 } // namespace fileapi | 200 } // namespace fileapi |
| OLD | NEW |