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

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: rebase 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
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 143
144 int FileSystemURLRequestJob::GetResponseCode() const { 144 int FileSystemURLRequestJob::GetResponseCode() const {
145 if (response_info_.get()) 145 if (response_info_.get())
146 return 200; 146 return 200;
147 return URLRequestJob::GetResponseCode(); 147 return URLRequestJob::GetResponseCode();
148 } 148 }
149 149
150 void FileSystemURLRequestJob::StartAsync() { 150 void FileSystemURLRequestJob::StartAsync() {
151 if (!request_) 151 if (!request_)
152 return; 152 return;
153 DCHECK(!reader_.get());
153 FileSystemOperationInterface* operation = 154 FileSystemOperationInterface* operation =
154 file_system_context_->CreateFileSystemOperation( 155 file_system_context_->CreateFileSystemOperation(
155 request_->url(), 156 request_->url(),
156 file_thread_proxy_); 157 file_thread_proxy_);
157 if (!operation) { 158 if (!operation) {
158 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, 159 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED,
159 net::ERR_INVALID_URL)); 160 net::ERR_INVALID_URL));
160 return; 161 return;
161 } 162 }
162 operation->CreateSnapshotFile( 163 operation->GetMetadata(
163 request_->url(), 164 request_->url(),
164 base::Bind(&FileSystemURLRequestJob::DidCreateSnapshot, this)); 165 base::Bind(&FileSystemURLRequestJob::DidGetMetadata,
166 weak_factory_.GetWeakPtr()));
165 } 167 }
166 168
167 void FileSystemURLRequestJob::DidCreateSnapshot( 169 void FileSystemURLRequestJob::DidGetMetadata(
168 base::PlatformFileError error_code, 170 base::PlatformFileError error_code,
169 const base::PlatformFileInfo& file_info, 171 const base::PlatformFileInfo& file_info,
170 const FilePath& platform_path, 172 const FilePath& platform_path) {
171 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref) {
172 if (error_code != base::PLATFORM_FILE_OK) { 173 if (error_code != base::PLATFORM_FILE_OK) {
173 NotifyFailed(error_code == base::PLATFORM_FILE_ERROR_INVALID_URL ? 174 NotifyFailed(error_code == base::PLATFORM_FILE_ERROR_INVALID_URL ?
174 net::ERR_INVALID_URL : net::ERR_FILE_NOT_FOUND); 175 net::ERR_INVALID_URL : net::ERR_FILE_NOT_FOUND);
175 return; 176 return;
176 } 177 }
177 178
178 // We may have been orphaned... 179 // We may have been orphaned...
179 if (!request_) 180 if (!request_)
180 return; 181 return;
181 182
182 is_directory_ = file_info.is_directory; 183 is_directory_ = file_info.is_directory;
183 184
184 // Keep the reference (if it's non-null) so that the file won't go away.
185 snapshot_ref_ = file_ref;
186
187 if (!byte_range_.ComputeBounds(file_info.size)) { 185 if (!byte_range_.ComputeBounds(file_info.size)) {
188 NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE); 186 NotifyFailed(net::ERR_REQUEST_RANGE_NOT_SATISFIABLE);
189 return; 187 return;
190 } 188 }
191 189
192 if (is_directory_) { 190 if (is_directory_) {
193 NotifyHeadersComplete(); 191 NotifyHeadersComplete();
194 return; 192 return;
195 } 193 }
196 194
197 remaining_bytes_ = byte_range_.last_byte_position() - 195 remaining_bytes_ = byte_range_.last_byte_position() -
198 byte_range_.first_byte_position() + 1; 196 byte_range_.first_byte_position() + 1;
199 DCHECK_GE(remaining_bytes_, 0); 197 DCHECK_GE(remaining_bytes_, 0);
200 198
201 DCHECK(!reader_.get()); 199 DCHECK(!reader_.get());
202 reader_.reset(new LocalFileReader( 200 reader_.reset(new FileSystemFileReader(
203 file_thread_proxy_, platform_path, 201 file_thread_proxy_,
204 byte_range_.first_byte_position(), 202 file_system_context_,
205 base::Time())); 203 request_->url(),
204 byte_range_.first_byte_position()));
206 205
207 set_expected_content_size(remaining_bytes_); 206 set_expected_content_size(remaining_bytes_);
208 response_info_.reset(new net::HttpResponseInfo()); 207 response_info_.reset(new net::HttpResponseInfo());
209 response_info_->headers = CreateHttpResponseHeaders(); 208 response_info_->headers = CreateHttpResponseHeaders();
210 NotifyHeadersComplete(); 209 NotifyHeadersComplete();
211 } 210 }
212 211
213 void FileSystemURLRequestJob::DidRead(int result) { 212 void FileSystemURLRequestJob::DidRead(int result) {
214 if (result > 0) 213 if (result > 0)
215 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status 214 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status
(...skipping 23 matching lines...) Expand all
239 } 238 }
240 239
241 return false; 240 return false;
242 } 241 }
243 242
244 void FileSystemURLRequestJob::NotifyFailed(int rv) { 243 void FileSystemURLRequestJob::NotifyFailed(int rv) {
245 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); 244 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv));
246 } 245 }
247 246
248 } // namespace fileapi 247 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698