| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 return true; | 127 return true; |
| 127 } | 128 } |
| 128 | 129 |
| 129 bool FileSystemDirURLRequestJob::GetCharset(std::string* charset) { | 130 bool FileSystemDirURLRequestJob::GetCharset(std::string* charset) { |
| 130 *charset = "utf-8"; | 131 *charset = "utf-8"; |
| 131 return true; | 132 return true; |
| 132 } | 133 } |
| 133 | 134 |
| 134 void FileSystemDirURLRequestJob::StartAsync() { | 135 void FileSystemDirURLRequestJob::StartAsync() { |
| 135 if (request_) | 136 if (request_) |
| 136 GetNewOperation()->ReadDirectory(request_->url()); | 137 GetNewOperation(request_->url())->ReadDirectory(request_->url()); |
| 137 } | 138 } |
| 138 | 139 |
| 139 void FileSystemDirURLRequestJob::DidReadDirectory( | 140 void FileSystemDirURLRequestJob::DidReadDirectory( |
| 140 const std::vector<base::FileUtilProxy::Entry>& entries, | 141 const std::vector<base::FileUtilProxy::Entry>& entries, |
| 141 bool has_more) { | 142 bool has_more) { |
| 142 if (!request_) | 143 if (!request_) |
| 143 return; | 144 return; |
| 144 | 145 |
| 145 if (data_.empty()) { | 146 if (data_.empty()) { |
| 146 FilePath relative_path = GetRelativePath(request_->url()); | 147 FilePath relative_path = GetRelativePath(request_->url()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 160 #elif defined(OS_POSIX) | 161 #elif defined(OS_POSIX) |
| 161 const string16& name = | 162 const string16& name = |
| 162 WideToUTF16(base::SysNativeMBToWide(it->name)); | 163 WideToUTF16(base::SysNativeMBToWide(it->name)); |
| 163 #endif | 164 #endif |
| 164 data_.append(net::GetDirectoryListingEntry( | 165 data_.append(net::GetDirectoryListingEntry( |
| 165 name, std::string(), it->is_directory, it->size, | 166 name, std::string(), it->is_directory, it->size, |
| 166 it->last_modified_time)); | 167 it->last_modified_time)); |
| 167 } | 168 } |
| 168 | 169 |
| 169 if (has_more) { | 170 if (has_more) { |
| 170 GetNewOperation()->ReadDirectory(request_->url()); | 171 GetNewOperation(request_->url())->ReadDirectory(request_->url()); |
| 171 } else { | 172 } else { |
| 172 set_expected_content_size(data_.size()); | 173 set_expected_content_size(data_.size()); |
| 173 NotifyHeadersComplete(); | 174 NotifyHeadersComplete(); |
| 174 } | 175 } |
| 175 } | 176 } |
| 176 | 177 |
| 177 FileSystemOperation* FileSystemDirURLRequestJob::GetNewOperation() { | 178 FileSystemOperationInterface* |
| 178 return new FileSystemOperation(new CallbackDispatcher(this), | 179 FileSystemDirURLRequestJob::GetNewOperation(const GURL& url) { |
| 179 file_thread_proxy_, | 180 return file_system_context_->CreateFileSystemOperation( |
| 180 file_system_context_); | 181 url, |
| 182 new CallbackDispatcher(this), |
| 183 file_thread_proxy_); |
| 181 } | 184 } |
| 182 | 185 |
| 183 } // namespace fileapi | 186 } // namespace fileapi |
| OLD | NEW |