Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: storage/browser/fileapi/file_system_dir_url_request_job.cc

Issue 1459333002: Revert "Reland: URLRequestJob: change ReadRawData contract" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/strings/sys_string_conversions.h" 12 #include "base/strings/sys_string_conversions.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "net/base/io_buffer.h" 16 #include "net/base/io_buffer.h"
17 #include "net/base/net_errors.h"
17 #include "net/base/net_util.h" 18 #include "net/base/net_util.h"
18 #include "net/url_request/url_request.h" 19 #include "net/url_request/url_request.h"
19 #include "storage/browser/fileapi/file_system_context.h" 20 #include "storage/browser/fileapi/file_system_context.h"
20 #include "storage/browser/fileapi/file_system_operation_runner.h" 21 #include "storage/browser/fileapi/file_system_operation_runner.h"
21 #include "storage/common/fileapi/directory_entry.h" 22 #include "storage/common/fileapi/directory_entry.h"
22 #include "storage/common/fileapi/file_system_util.h" 23 #include "storage/common/fileapi/file_system_util.h"
23 #include "url/gurl.h" 24 #include "url/gurl.h"
24 25
25 using net::NetworkDelegate; 26 using net::NetworkDelegate;
26 using net::URLRequest; 27 using net::URLRequest;
27 using net::URLRequestJob; 28 using net::URLRequestJob;
28 using net::URLRequestStatus; 29 using net::URLRequestStatus;
29 30
30 namespace storage { 31 namespace storage {
31 32
32 FileSystemDirURLRequestJob::FileSystemDirURLRequestJob( 33 FileSystemDirURLRequestJob::FileSystemDirURLRequestJob(
33 URLRequest* request, 34 URLRequest* request,
34 NetworkDelegate* network_delegate, 35 NetworkDelegate* network_delegate,
35 const std::string& storage_domain, 36 const std::string& storage_domain,
36 FileSystemContext* file_system_context) 37 FileSystemContext* file_system_context)
37 : URLRequestJob(request, network_delegate), 38 : URLRequestJob(request, network_delegate),
38 storage_domain_(storage_domain), 39 storage_domain_(storage_domain),
39 file_system_context_(file_system_context), 40 file_system_context_(file_system_context),
40 weak_factory_(this) { 41 weak_factory_(this) {
41 } 42 }
42 43
43 FileSystemDirURLRequestJob::~FileSystemDirURLRequestJob() { 44 FileSystemDirURLRequestJob::~FileSystemDirURLRequestJob() {
44 } 45 }
45 46
46 int FileSystemDirURLRequestJob::ReadRawData(net::IOBuffer* dest, 47 bool FileSystemDirURLRequestJob::ReadRawData(net::IOBuffer* dest,
47 int dest_size) { 48 int dest_size,
48 int count = std::min(dest_size, base::checked_cast<int>(data_.size())); 49 int* bytes_read) {
50 int count = std::min(dest_size, static_cast<int>(data_.size()));
49 if (count > 0) { 51 if (count > 0) {
50 memcpy(dest->data(), data_.data(), count); 52 memcpy(dest->data(), data_.data(), count);
51 data_.erase(0, count); 53 data_.erase(0, count);
52 } 54 }
53 return count; 55 *bytes_read = count;
56 return true;
54 } 57 }
55 58
56 void FileSystemDirURLRequestJob::Start() { 59 void FileSystemDirURLRequestJob::Start() {
57 base::MessageLoop::current()->PostTask( 60 base::MessageLoop::current()->PostTask(
58 FROM_HERE, 61 FROM_HERE,
59 base::Bind(&FileSystemDirURLRequestJob::StartAsync, 62 base::Bind(&FileSystemDirURLRequestJob::StartAsync,
60 weak_factory_.GetWeakPtr())); 63 weak_factory_.GetWeakPtr()));
61 } 64 }
62 65
63 void FileSystemDirURLRequestJob::Kill() { 66 void FileSystemDirURLRequestJob::Kill() {
(...skipping 25 matching lines...) Expand all
89 } 92 }
90 if (!file_system_context_->CanServeURLRequest(url_)) { 93 if (!file_system_context_->CanServeURLRequest(url_)) {
91 // In incognito mode the API is not usable and there should be no data. 94 // In incognito mode the API is not usable and there should be no data.
92 if (url_.is_valid() && VirtualPath::IsRootPath(url_.virtual_path())) { 95 if (url_.is_valid() && VirtualPath::IsRootPath(url_.virtual_path())) {
93 // Return an empty directory if the filesystem root is queried. 96 // Return an empty directory if the filesystem root is queried.
94 DidReadDirectory(base::File::FILE_OK, 97 DidReadDirectory(base::File::FILE_OK,
95 std::vector<DirectoryEntry>(), 98 std::vector<DirectoryEntry>(),
96 false); 99 false);
97 return; 100 return;
98 } 101 }
99 NotifyStartError(URLRequestStatus::FromError(net::ERR_FILE_NOT_FOUND)); 102 NotifyDone(
103 URLRequestStatus(URLRequestStatus::FAILED, net::ERR_FILE_NOT_FOUND));
100 return; 104 return;
101 } 105 }
102 file_system_context_->operation_runner()->ReadDirectory( 106 file_system_context_->operation_runner()->ReadDirectory(
103 url_, 107 url_,
104 base::Bind(&FileSystemDirURLRequestJob::DidReadDirectory, this)); 108 base::Bind(&FileSystemDirURLRequestJob::DidReadDirectory, this));
105 } 109 }
106 110
107 void FileSystemDirURLRequestJob::DidAttemptAutoMount(base::File::Error result) { 111 void FileSystemDirURLRequestJob::DidAttemptAutoMount(base::File::Error result) {
108 if (result >= 0 && 112 if (result >= 0 &&
109 file_system_context_->CrackURL(request_->url()).is_valid()) { 113 file_system_context_->CrackURL(request_->url()).is_valid()) {
110 StartAsync(); 114 StartAsync();
111 } else { 115 } else {
112 NotifyStartError(URLRequestStatus::FromError(net::ERR_FILE_NOT_FOUND)); 116 NotifyDone(
117 URLRequestStatus(URLRequestStatus::FAILED, net::ERR_FILE_NOT_FOUND));
113 } 118 }
114 } 119 }
115 120
116 void FileSystemDirURLRequestJob::DidReadDirectory( 121 void FileSystemDirURLRequestJob::DidReadDirectory(
117 base::File::Error result, 122 base::File::Error result,
118 const std::vector<DirectoryEntry>& entries, 123 const std::vector<DirectoryEntry>& entries,
119 bool has_more) { 124 bool has_more) {
120 if (result != base::File::FILE_OK) { 125 if (result != base::File::FILE_OK) {
121 int rv = net::ERR_FILE_NOT_FOUND; 126 int rv = net::ERR_FILE_NOT_FOUND;
122 if (result == base::File::FILE_ERROR_INVALID_URL) 127 if (result == base::File::FILE_ERROR_INVALID_URL)
123 rv = net::ERR_INVALID_URL; 128 rv = net::ERR_INVALID_URL;
124 NotifyStartError(URLRequestStatus::FromError(rv)); 129 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
125 return; 130 return;
126 } 131 }
127 132
128 if (!request_) 133 if (!request_)
129 return; 134 return;
130 135
131 if (data_.empty()) { 136 if (data_.empty()) {
132 base::FilePath relative_path = url_.path(); 137 base::FilePath relative_path = url_.path();
133 #if defined(OS_POSIX) 138 #if defined(OS_POSIX)
134 relative_path = 139 relative_path =
(...skipping 28 matching lines...) Expand all
163 } 168 }
164 169
165 void FileSystemDirURLRequestJob::DidGetMetadata( 170 void FileSystemDirURLRequestJob::DidGetMetadata(
166 size_t index, 171 size_t index,
167 base::File::Error result, 172 base::File::Error result,
168 const base::File::Info& file_info) { 173 const base::File::Info& file_info) {
169 if (result != base::File::FILE_OK) { 174 if (result != base::File::FILE_OK) {
170 int rv = net::ERR_FILE_NOT_FOUND; 175 int rv = net::ERR_FILE_NOT_FOUND;
171 if (result == base::File::FILE_ERROR_INVALID_URL) 176 if (result == base::File::FILE_ERROR_INVALID_URL)
172 rv = net::ERR_INVALID_URL; 177 rv = net::ERR_INVALID_URL;
173 NotifyStartError(URLRequestStatus(URLRequestStatus::FAILED, rv)); 178 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
174 } 179 }
175 180
176 if (!request_) 181 if (!request_)
177 return; 182 return;
178 183
179 const DirectoryEntry& entry = entries_[index]; 184 const DirectoryEntry& entry = entries_[index];
180 const base::string16& name = base::FilePath(entry.name).LossyDisplayName(); 185 const base::string16& name = base::FilePath(entry.name).LossyDisplayName();
181 data_.append(net::GetDirectoryListingEntry(name, std::string(), 186 data_.append(net::GetDirectoryListingEntry(name, std::string(),
182 entry.is_directory, file_info.size, 187 entry.is_directory, file_info.size,
183 file_info.last_modified)); 188 file_info.last_modified));
184 189
185 if (index < entries_.size() - 1) { 190 if (index < entries_.size() - 1) {
186 GetMetadata(index + 1); 191 GetMetadata(index + 1);
187 } else { 192 } else {
188 set_expected_content_size(data_.size()); 193 set_expected_content_size(data_.size());
189 NotifyHeadersComplete(); 194 NotifyHeadersComplete();
190 } 195 }
191 } 196 }
192 197
193 } // namespace storage 198 } // namespace storage
OLDNEW
« no previous file with comments | « storage/browser/fileapi/file_system_dir_url_request_job.h ('k') | storage/browser/fileapi/file_system_url_request_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698