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

Side by Side Diff: webkit/fileapi/file_system_url_request_job.cc

Issue 10038019: Add FileReader interface and implement FileSystemFileReader (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 8 years, 8 months 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 | Annotate | Revision Log
« no previous file with comments | « webkit/fileapi/file_system_url_request_job.h ('k') | webkit/fileapi/webkit_fileapi.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "webkit/fileapi/file_system_url_request_job.h" 5 #include "webkit/fileapi/file_system_url_request_job.h"
6 6
7 #include <vector>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
9 #include "base/file_path.h" 11 #include "base/file_path.h"
10 #include "base/file_util_proxy.h" 12 #include "base/file_util_proxy.h"
11 #include "base/message_loop.h" 13 #include "base/message_loop.h"
12 #include "base/platform_file.h" 14 #include "base/platform_file.h"
13 #include "base/threading/thread_restrictions.h" 15 #include "base/threading/thread_restrictions.h"
14 #include "base/time.h" 16 #include "base/time.h"
15 #include "build/build_config.h" 17 #include "build/build_config.h"
16 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
17 #include "net/base/file_stream.h" 19 #include "net/base/file_stream.h"
18 #include "net/base/io_buffer.h" 20 #include "net/base/io_buffer.h"
19 #include "net/base/mime_util.h" 21 #include "net/base/mime_util.h"
20 #include "net/base/net_errors.h" 22 #include "net/base/net_errors.h"
21 #include "net/base/net_util.h" 23 #include "net/base/net_util.h"
22 #include "net/http/http_response_headers.h" 24 #include "net/http/http_response_headers.h"
23 #include "net/http/http_response_info.h" 25 #include "net/http/http_response_info.h"
24 #include "net/http/http_util.h" 26 #include "net/http/http_util.h"
25 #include "net/url_request/url_request.h" 27 #include "net/url_request/url_request.h"
26 #include "webkit/blob/local_file_reader.h"
27 #include "webkit/blob/shareable_file_reference.h"
28 #include "webkit/fileapi/file_system_context.h" 28 #include "webkit/fileapi/file_system_context.h"
29 #include "webkit/fileapi/file_system_file_reader.h"
29 #include "webkit/fileapi/file_system_operation.h" 30 #include "webkit/fileapi/file_system_operation.h"
30 #include "webkit/fileapi/file_system_util.h" 31 #include "webkit/fileapi/file_system_util.h"
31 32
32 using net::URLRequest; 33 using net::URLRequest;
33 using net::URLRequestJob; 34 using net::URLRequestJob;
34 using net::URLRequestStatus; 35 using net::URLRequestStatus;
35 using webkit_blob::LocalFileReader; 36 using webkit_blob::LocalFileReader;
36 37
37 namespace fileapi { 38 namespace fileapi {
38 39
(...skipping 27 matching lines...) Expand all
66 FileSystemURLRequestJob::~FileSystemURLRequestJob() {} 67 FileSystemURLRequestJob::~FileSystemURLRequestJob() {}
67 68
68 void FileSystemURLRequestJob::Start() { 69 void FileSystemURLRequestJob::Start() {
69 MessageLoop::current()->PostTask( 70 MessageLoop::current()->PostTask(
70 FROM_HERE, 71 FROM_HERE,
71 base::Bind(&FileSystemURLRequestJob::StartAsync, 72 base::Bind(&FileSystemURLRequestJob::StartAsync,
72 weak_factory_.GetWeakPtr())); 73 weak_factory_.GetWeakPtr()));
73 } 74 }
74 75
75 void FileSystemURLRequestJob::Kill() { 76 void FileSystemURLRequestJob::Kill() {
76 if (reader_.get() != NULL) 77 reader_.reset();
77 reader_.reset();
78 URLRequestJob::Kill(); 78 URLRequestJob::Kill();
79 weak_factory_.InvalidateWeakPtrs(); 79 weak_factory_.InvalidateWeakPtrs();
80 } 80 }
81 81
82 bool FileSystemURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size, 82 bool FileSystemURLRequestJob::ReadRawData(net::IOBuffer* dest, int dest_size,
83 int *bytes_read) { 83 int *bytes_read) {
84 DCHECK_NE(dest_size, 0); 84 DCHECK_NE(dest_size, 0);
85 DCHECK(bytes_read); 85 DCHECK(bytes_read);
86 DCHECK_GE(remaining_bytes_, 0); 86 DCHECK_GE(remaining_bytes_, 0);
87 87
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 150
151 int FileSystemURLRequestJob::GetResponseCode() const { 151 int FileSystemURLRequestJob::GetResponseCode() const {
152 if (response_info_.get()) 152 if (response_info_.get())
153 return 200; 153 return 200;
154 return URLRequestJob::GetResponseCode(); 154 return URLRequestJob::GetResponseCode();
155 } 155 }
156 156
157 void FileSystemURLRequestJob::StartAsync() { 157 void FileSystemURLRequestJob::StartAsync() {
158 if (!request_) 158 if (!request_)
159 return; 159 return;
160 DCHECK(!reader_.get());
160 FileSystemOperationInterface* operation = 161 FileSystemOperationInterface* operation =
161 file_system_context_->CreateFileSystemOperation( 162 file_system_context_->CreateFileSystemOperation(
162 request_->url(), 163 request_->url(),
163 file_thread_proxy_); 164 file_thread_proxy_);
164 if (!operation) { 165 if (!operation) {
165 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, 166 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
166 net::ERR_INVALID_URL)); 167 net::ERR_INVALID_URL));
167 return; 168 return;
168 } 169 }
169 operation->CreateSnapshotFile( 170 operation->GetMetadata(
170 request_->url(), 171 request_->url(),
171 base::Bind(&FileSystemURLRequestJob::DidCreateSnapshot, this)); 172 base::Bind(&FileSystemURLRequestJob::DidGetMetadata,
173 weak_factory_.GetWeakPtr()));
172 } 174 }
173 175
174 void FileSystemURLRequestJob::DidCreateSnapshot( 176 void FileSystemURLRequestJob::DidGetMetadata(
175 base::PlatformFileError error_code, 177 base::PlatformFileError error_code,
176 const base::PlatformFileInfo& file_info, 178 const base::PlatformFileInfo& file_info,
177 const FilePath& platform_path, 179 const FilePath& platform_path) {
178 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) {
179 if (error_code != base::PLATFORM_FILE_OK) { 180 if (error_code != base::PLATFORM_FILE_OK) {
180 NotifyFailed(error_code == base::PLATFORM_FILE_ERROR_INVALID_URL ? 181 NotifyFailed(error_code == base::PLATFORM_FILE_ERROR_INVALID_URL ?
181 net::ERR_INVALID_URL : net::ERR_FILE_NOT_FOUND); 182 net::ERR_INVALID_URL : net::ERR_FILE_NOT_FOUND);
182 return; 183 return;
183 } 184 }
184 185
185 // We may have been orphaned... 186 // We may have been orphaned...
186 if (!request_) 187 if (!request_)
187 return; 188 return;
188 189
189 is_directory_ = file_info.is_directory; 190 is_directory_ = file_info.is_directory;
190 191
191 // Keep the reference (if it's non-null) so that the file won't go away.
192 snapshot_ref_ = file_ref;
193
194 if (!byte_range_.ComputeBounds(file_info.size)) { 192 if (!byte_range_.ComputeBounds(file_info.size)) {
195 NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); 193 NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE);
196 return; 194 return;
197 } 195 }
198 196
199 if (is_directory_) { 197 if (is_directory_) {
200 NotifyHeadersComplete(); 198 NotifyHeadersComplete();
201 return; 199 return;
202 } 200 }
203 201
204 remaining_bytes_ = byte_range_.last_byte_position() - 202 remaining_bytes_ = byte_range_.last_byte_position() -
205 byte_range_.first_byte_position() + 1; 203 byte_range_.first_byte_position() + 1;
206 DCHECK_GE(remaining_bytes_, 0); 204 DCHECK_GE(remaining_bytes_, 0);
207 205
208 DCHECK(!reader_.get()); 206 DCHECK(!reader_.get());
209 reader_.reset(new LocalFileReader( 207 reader_.reset(new FileSystemFileReader(
210 file_thread_proxy_, platform_path, 208 file_thread_proxy_,
211 byte_range_.first_byte_position(), 209 file_system_context_,
212 base::Time())); 210 request_->url(),
211 byte_range_.first_byte_position()));
213 212
214 set_expected_content_size(remaining_bytes_); 213 set_expected_content_size(remaining_bytes_);
215 response_info_.reset(new net::HttpResponseInfo()); 214 response_info_.reset(new net::HttpResponseInfo());
216 response_info_->headers = CreateHttpResponseHeaders(); 215 response_info_->headers = CreateHttpResponseHeaders();
217 NotifyHeadersComplete(); 216 NotifyHeadersComplete();
218 } 217 }
219 218
220 void FileSystemURLRequestJob::DidRead(int result) { 219 void FileSystemURLRequestJob::DidRead(int result) {
221 if (result > 0) 220 if (result > 0)
222 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status 221 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status
(...skipping 23 matching lines...) Expand all
246 } 245 }
247 246
248 return false; 247 return false;
249 } 248 }
250 249
251 void FileSystemURLRequestJob::NotifyFailed(int rv) { 250 void FileSystemURLRequestJob::NotifyFailed(int rv) {
252 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); 251 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
253 } 252 }
254 253
255 } // namespace fileapi 254 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_url_request_job.h ('k') | webkit/fileapi/webkit_fileapi.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698