| 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/browser/fileapi/file_system_dir_url_request_job.h" | 5 #include "webkit/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 17 matching lines...) Expand all Loading... |
| 28 using net::NetworkDelegate; | 28 using net::NetworkDelegate; |
| 29 using net::URLRequest; | 29 using net::URLRequest; |
| 30 using net::URLRequestJob; | 30 using net::URLRequestJob; |
| 31 using net::URLRequestStatus; | 31 using net::URLRequestStatus; |
| 32 | 32 |
| 33 namespace fileapi { | 33 namespace fileapi { |
| 34 | 34 |
| 35 FileSystemDirURLRequestJob::FileSystemDirURLRequestJob( | 35 FileSystemDirURLRequestJob::FileSystemDirURLRequestJob( |
| 36 URLRequest* request, | 36 URLRequest* request, |
| 37 NetworkDelegate* network_delegate, | 37 NetworkDelegate* network_delegate, |
| 38 const std::string& storage_domain, |
| 38 FileSystemContext* file_system_context) | 39 FileSystemContext* file_system_context) |
| 39 : URLRequestJob(request, network_delegate), | 40 : URLRequestJob(request, network_delegate), |
| 41 storage_domain_(storage_domain), |
| 40 file_system_context_(file_system_context), | 42 file_system_context_(file_system_context), |
| 41 weak_factory_(this) { | 43 weak_factory_(this) { |
| 42 } | 44 } |
| 43 | 45 |
| 44 FileSystemDirURLRequestJob::~FileSystemDirURLRequestJob() { | 46 FileSystemDirURLRequestJob::~FileSystemDirURLRequestJob() { |
| 45 } | 47 } |
| 46 | 48 |
| 47 bool FileSystemDirURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size, | 49 bool FileSystemDirURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size, |
| 48 int *bytes_read) { | 50 int *bytes_read) { |
| 49 int count = std::min(dest_size, static_cast<int>(data_.size())); | 51 int count = std::min(dest_size, static_cast<int>(data_.size())); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 74 | 76 |
| 75 bool FileSystemDirURLRequestJob::GetCharset(std::string* charset) { | 77 bool FileSystemDirURLRequestJob::GetCharset(std::string* charset) { |
| 76 *charset = "utf-8"; | 78 *charset = "utf-8"; |
| 77 return true; | 79 return true; |
| 78 } | 80 } |
| 79 | 81 |
| 80 void FileSystemDirURLRequestJob::StartAsync() { | 82 void FileSystemDirURLRequestJob::StartAsync() { |
| 81 if (!request_) | 83 if (!request_) |
| 82 return; | 84 return; |
| 83 url_ = file_system_context_->CrackURL(request_->url()); | 85 url_ = file_system_context_->CrackURL(request_->url()); |
| 86 if (!url_.is_valid()) { |
| 87 file_system_context_->AttemptAutoMountForURLRequest( |
| 88 request_, |
| 89 storage_domain_, |
| 90 base::Bind(&FileSystemDirURLRequestJob::DidAttemptAutoMount, |
| 91 weak_factory_.GetWeakPtr())); |
| 92 return; |
| 93 } |
| 84 if (!file_system_context_->CanServeURLRequest(url_)) { | 94 if (!file_system_context_->CanServeURLRequest(url_)) { |
| 85 // In incognito mode the API is not usable and there should be no data. | 95 // In incognito mode the API is not usable and there should be no data. |
| 86 if (url_.is_valid() && VirtualPath::IsRootPath(url_.virtual_path())) { | 96 if (url_.is_valid() && VirtualPath::IsRootPath(url_.virtual_path())) { |
| 87 // Return an empty directory if the filesystem root is queried. | 97 // Return an empty directory if the filesystem root is queried. |
| 88 DidReadDirectory(base::File::FILE_OK, | 98 DidReadDirectory(base::File::FILE_OK, |
| 89 std::vector<DirectoryEntry>(), | 99 std::vector<DirectoryEntry>(), |
| 90 false); | 100 false); |
| 91 return; | 101 return; |
| 92 } | 102 } |
| 93 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, | 103 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
| 94 net::ERR_FILE_NOT_FOUND)); | 104 net::ERR_FILE_NOT_FOUND)); |
| 95 return; | 105 return; |
| 96 } | 106 } |
| 97 file_system_context_->operation_runner()->ReadDirectory( | 107 file_system_context_->operation_runner()->ReadDirectory( |
| 98 url_, | 108 url_, |
| 99 base::Bind(&FileSystemDirURLRequestJob::DidReadDirectory, this)); | 109 base::Bind(&FileSystemDirURLRequestJob::DidReadDirectory, this)); |
| 100 } | 110 } |
| 101 | 111 |
| 112 void FileSystemDirURLRequestJob::DidAttemptAutoMount(base::File::Error result) { |
| 113 if (result >= 0 && |
| 114 file_system_context_->CrackURL(request_->url()).is_valid()) { |
| 115 StartAsync(); |
| 116 } else { |
| 117 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
| 118 net::ERR_FILE_NOT_FOUND)); |
| 119 } |
| 120 } |
| 121 |
| 102 void FileSystemDirURLRequestJob::DidReadDirectory( | 122 void FileSystemDirURLRequestJob::DidReadDirectory( |
| 103 base::File::Error result, | 123 base::File::Error result, |
| 104 const std::vector<DirectoryEntry>& entries, | 124 const std::vector<DirectoryEntry>& entries, |
| 105 bool has_more) { | 125 bool has_more) { |
| 106 if (result != base::File::FILE_OK) { | 126 if (result != base::File::FILE_OK) { |
| 107 int rv = net::ERR_FILE_NOT_FOUND; | 127 int rv = net::ERR_FILE_NOT_FOUND; |
| 108 if (result == base::File::FILE_ERROR_INVALID_URL) | 128 if (result == base::File::FILE_ERROR_INVALID_URL) |
| 109 rv = net::ERR_INVALID_URL; | 129 rv = net::ERR_INVALID_URL; |
| 110 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 130 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
| 111 return; | 131 return; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 132 it->last_modified_time)); | 152 it->last_modified_time)); |
| 133 } | 153 } |
| 134 | 154 |
| 135 if (!has_more) { | 155 if (!has_more) { |
| 136 set_expected_content_size(data_.size()); | 156 set_expected_content_size(data_.size()); |
| 137 NotifyHeadersComplete(); | 157 NotifyHeadersComplete(); |
| 138 } | 158 } |
| 139 } | 159 } |
| 140 | 160 |
| 141 } // namespace fileapi | 161 } // namespace fileapi |
| OLD | NEW |