| 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 26 matching lines...) Expand all Loading... |
| 37 FileSystemContext* file_system_context) | 37 FileSystemContext* file_system_context) |
| 38 : URLRequestJob(request, network_delegate), | 38 : URLRequestJob(request, network_delegate), |
| 39 storage_domain_(storage_domain), | 39 storage_domain_(storage_domain), |
| 40 file_system_context_(file_system_context), | 40 file_system_context_(file_system_context), |
| 41 weak_factory_(this) { | 41 weak_factory_(this) { |
| 42 } | 42 } |
| 43 | 43 |
| 44 FileSystemDirURLRequestJob::~FileSystemDirURLRequestJob() { | 44 FileSystemDirURLRequestJob::~FileSystemDirURLRequestJob() { |
| 45 } | 45 } |
| 46 | 46 |
| 47 bool FileSystemDirURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size, | 47 int FileSystemDirURLRequestJob::ReadRawData(net::IOBuffer* dest, |
| 48 int *bytes_read) { | 48 int dest_size) { |
| 49 int count = std::min(dest_size, static_cast<int>(data_.size())); | 49 int count = std::min(dest_size, base::checked_cast<int>(data_.size())); |
| 50 if (count > 0) { | 50 if (count > 0) { |
| 51 memcpy(dest->data(), data_.data(), count); | 51 memcpy(dest->data(), data_.data(), count); |
| 52 data_.erase(0, count); | 52 data_.erase(0, count); |
| 53 } | 53 } |
| 54 *bytes_read = count; | 54 return count; |
| 55 return true; | |
| 56 } | 55 } |
| 57 | 56 |
| 58 void FileSystemDirURLRequestJob::Start() { | 57 void FileSystemDirURLRequestJob::Start() { |
| 59 base::MessageLoop::current()->PostTask( | 58 base::MessageLoop::current()->PostTask( |
| 60 FROM_HERE, | 59 FROM_HERE, |
| 61 base::Bind(&FileSystemDirURLRequestJob::StartAsync, | 60 base::Bind(&FileSystemDirURLRequestJob::StartAsync, |
| 62 weak_factory_.GetWeakPtr())); | 61 weak_factory_.GetWeakPtr())); |
| 63 } | 62 } |
| 64 | 63 |
| 65 void FileSystemDirURLRequestJob::Kill() { | 64 void FileSystemDirURLRequestJob::Kill() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 91 } | 90 } |
| 92 if (!file_system_context_->CanServeURLRequest(url_)) { | 91 if (!file_system_context_->CanServeURLRequest(url_)) { |
| 93 // In incognito mode the API is not usable and there should be no data. | 92 // In incognito mode the API is not usable and there should be no data. |
| 94 if (url_.is_valid() && VirtualPath::IsRootPath(url_.virtual_path())) { | 93 if (url_.is_valid() && VirtualPath::IsRootPath(url_.virtual_path())) { |
| 95 // Return an empty directory if the filesystem root is queried. | 94 // Return an empty directory if the filesystem root is queried. |
| 96 DidReadDirectory(base::File::FILE_OK, | 95 DidReadDirectory(base::File::FILE_OK, |
| 97 std::vector<DirectoryEntry>(), | 96 std::vector<DirectoryEntry>(), |
| 98 false); | 97 false); |
| 99 return; | 98 return; |
| 100 } | 99 } |
| 101 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, | 100 NotifyStartError(URLRequestStatus::FromError(net::ERR_FILE_NOT_FOUND)); |
| 102 net::ERR_FILE_NOT_FOUND)); | |
| 103 return; | 101 return; |
| 104 } | 102 } |
| 105 file_system_context_->operation_runner()->ReadDirectory( | 103 file_system_context_->operation_runner()->ReadDirectory( |
| 106 url_, | 104 url_, |
| 107 base::Bind(&FileSystemDirURLRequestJob::DidReadDirectory, this)); | 105 base::Bind(&FileSystemDirURLRequestJob::DidReadDirectory, this)); |
| 108 } | 106 } |
| 109 | 107 |
| 110 void FileSystemDirURLRequestJob::DidAttemptAutoMount(base::File::Error result) { | 108 void FileSystemDirURLRequestJob::DidAttemptAutoMount(base::File::Error result) { |
| 111 if (result >= 0 && | 109 if (result >= 0 && |
| 112 file_system_context_->CrackURL(request_->url()).is_valid()) { | 110 file_system_context_->CrackURL(request_->url()).is_valid()) { |
| 113 StartAsync(); | 111 StartAsync(); |
| 114 } else { | 112 } else { |
| 115 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, | 113 NotifyStartError(URLRequestStatus::FromError(net::ERR_FILE_NOT_FOUND)); |
| 116 net::ERR_FILE_NOT_FOUND)); | |
| 117 } | 114 } |
| 118 } | 115 } |
| 119 | 116 |
| 120 void FileSystemDirURLRequestJob::DidReadDirectory( | 117 void FileSystemDirURLRequestJob::DidReadDirectory( |
| 121 base::File::Error result, | 118 base::File::Error result, |
| 122 const std::vector<DirectoryEntry>& entries, | 119 const std::vector<DirectoryEntry>& entries, |
| 123 bool has_more) { | 120 bool has_more) { |
| 124 if (result != base::File::FILE_OK) { | 121 if (result != base::File::FILE_OK) { |
| 125 int rv = net::ERR_FILE_NOT_FOUND; | 122 int rv = net::ERR_FILE_NOT_FOUND; |
| 126 if (result == base::File::FILE_ERROR_INVALID_URL) | 123 if (result == base::File::FILE_ERROR_INVALID_URL) |
| 127 rv = net::ERR_INVALID_URL; | 124 rv = net::ERR_INVALID_URL; |
| 128 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 125 NotifyStartError(URLRequestStatus::FromError(rv)); |
| 129 return; | 126 return; |
| 130 } | 127 } |
| 131 | 128 |
| 132 if (!request_) | 129 if (!request_) |
| 133 return; | 130 return; |
| 134 | 131 |
| 135 if (data_.empty()) { | 132 if (data_.empty()) { |
| 136 base::FilePath relative_path = url_.path(); | 133 base::FilePath relative_path = url_.path(); |
| 137 #if defined(OS_POSIX) | 134 #if defined(OS_POSIX) |
| 138 relative_path = | 135 relative_path = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 150 it->last_modified_time)); | 147 it->last_modified_time)); |
| 151 } | 148 } |
| 152 | 149 |
| 153 if (!has_more) { | 150 if (!has_more) { |
| 154 set_expected_content_size(data_.size()); | 151 set_expected_content_size(data_.size()); |
| 155 NotifyHeadersComplete(); | 152 NotifyHeadersComplete(); |
| 156 } | 153 } |
| 157 } | 154 } |
| 158 | 155 |
| 159 } // namespace storage | 156 } // namespace storage |
| OLD | NEW |