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/fileapi/file_system_url_request_job.h" | 5 #include "webkit/fileapi/file_system_url_request_job.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
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/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/file_util_proxy.h" | 12 #include "base/file_util_proxy.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/message_loop_proxy.h" |
14 #include "base/platform_file.h" | 15 #include "base/platform_file.h" |
15 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
16 #include "base/time.h" | 17 #include "base/time.h" |
17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
19 #include "net/base/file_stream.h" | 20 #include "net/base/file_stream.h" |
20 #include "net/base/io_buffer.h" | 21 #include "net/base/io_buffer.h" |
21 #include "net/base/mime_util.h" | 22 #include "net/base/mime_util.h" |
22 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
23 #include "net/base/net_util.h" | 24 #include "net/base/net_util.h" |
(...skipping 22 matching lines...) Expand all Loading... |
46 | 47 |
47 // Tell WebKit never to cache this content. | 48 // Tell WebKit never to cache this content. |
48 std::string cache_control(net::HttpRequestHeaders::kCacheControl); | 49 std::string cache_control(net::HttpRequestHeaders::kCacheControl); |
49 cache_control.append(": no-cache"); | 50 cache_control.append(": no-cache"); |
50 headers->AddHeader(cache_control); | 51 headers->AddHeader(cache_control); |
51 | 52 |
52 return headers; | 53 return headers; |
53 } | 54 } |
54 | 55 |
55 FileSystemURLRequestJob::FileSystemURLRequestJob( | 56 FileSystemURLRequestJob::FileSystemURLRequestJob( |
56 URLRequest* request, FileSystemContext* file_system_context, | 57 URLRequest* request, FileSystemContext* file_system_context) |
57 scoped_refptr<base::MessageLoopProxy> file_thread_proxy) | |
58 : URLRequestJob(request), | 58 : URLRequestJob(request), |
59 file_system_context_(file_system_context), | 59 file_system_context_(file_system_context), |
60 file_thread_proxy_(file_thread_proxy), | |
61 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 60 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
62 is_directory_(false), | 61 is_directory_(false), |
63 remaining_bytes_(0) { | 62 remaining_bytes_(0) { |
64 } | 63 } |
65 | 64 |
66 FileSystemURLRequestJob::~FileSystemURLRequestJob() {} | 65 FileSystemURLRequestJob::~FileSystemURLRequestJob() {} |
67 | 66 |
68 void FileSystemURLRequestJob::Start() { | 67 void FileSystemURLRequestJob::Start() { |
69 MessageLoop::current()->PostTask( | 68 MessageLoop::current()->PostTask( |
70 FROM_HERE, | 69 FROM_HERE, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 if (response_info_.get()) | 150 if (response_info_.get()) |
152 return 200; | 151 return 200; |
153 return URLRequestJob::GetResponseCode(); | 152 return URLRequestJob::GetResponseCode(); |
154 } | 153 } |
155 | 154 |
156 void FileSystemURLRequestJob::StartAsync() { | 155 void FileSystemURLRequestJob::StartAsync() { |
157 if (!request_) | 156 if (!request_) |
158 return; | 157 return; |
159 DCHECK(!reader_.get()); | 158 DCHECK(!reader_.get()); |
160 FileSystemOperationInterface* operation = | 159 FileSystemOperationInterface* operation = |
161 file_system_context_->CreateFileSystemOperation( | 160 file_system_context_->CreateFileSystemOperation(request_->url()); |
162 request_->url(), | |
163 file_thread_proxy_); | |
164 if (!operation) { | 161 if (!operation) { |
165 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, | 162 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, |
166 net::ERR_INVALID_URL)); | 163 net::ERR_INVALID_URL)); |
167 return; | 164 return; |
168 } | 165 } |
169 operation->GetMetadata( | 166 operation->GetMetadata( |
170 request_->url(), | 167 request_->url(), |
171 base::Bind(&FileSystemURLRequestJob::DidGetMetadata, | 168 base::Bind(&FileSystemURLRequestJob::DidGetMetadata, |
172 weak_factory_.GetWeakPtr())); | 169 weak_factory_.GetWeakPtr())); |
173 } | 170 } |
(...skipping 25 matching lines...) Expand all Loading... |
199 } | 196 } |
200 | 197 |
201 remaining_bytes_ = byte_range_.last_byte_position() - | 198 remaining_bytes_ = byte_range_.last_byte_position() - |
202 byte_range_.first_byte_position() + 1; | 199 byte_range_.first_byte_position() + 1; |
203 DCHECK_GE(remaining_bytes_, 0); | 200 DCHECK_GE(remaining_bytes_, 0); |
204 | 201 |
205 DCHECK(!reader_.get()); | 202 DCHECK(!reader_.get()); |
206 reader_.reset( | 203 reader_.reset( |
207 file_system_context_->CreateFileReader( | 204 file_system_context_->CreateFileReader( |
208 request_->url(), | 205 request_->url(), |
209 byte_range_.first_byte_position(), | 206 byte_range_.first_byte_position())); |
210 file_thread_proxy_)); | |
211 | 207 |
212 set_expected_content_size(remaining_bytes_); | 208 set_expected_content_size(remaining_bytes_); |
213 response_info_.reset(new net::HttpResponseInfo()); | 209 response_info_.reset(new net::HttpResponseInfo()); |
214 response_info_->headers = CreateHttpResponseHeaders(); | 210 response_info_->headers = CreateHttpResponseHeaders(); |
215 NotifyHeadersComplete(); | 211 NotifyHeadersComplete(); |
216 } | 212 } |
217 | 213 |
218 void FileSystemURLRequestJob::DidRead(int result) { | 214 void FileSystemURLRequestJob::DidRead(int result) { |
219 if (result > 0) | 215 if (result > 0) |
220 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status | 216 SetStatus(URLRequestStatus()); // Clear the IO_PENDING status |
(...skipping 23 matching lines...) Expand all Loading... |
244 } | 240 } |
245 | 241 |
246 return false; | 242 return false; |
247 } | 243 } |
248 | 244 |
249 void FileSystemURLRequestJob::NotifyFailed(int rv) { | 245 void FileSystemURLRequestJob::NotifyFailed(int rv) { |
250 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); | 246 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, rv)); |
251 } | 247 } |
252 | 248 |
253 } // namespace fileapi | 249 } // namespace fileapi |
OLD | NEW |