| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/fileapi/external_file_url_request_job.h" | 5 #include "chrome/browser/chromeos/fileapi/external_file_url_request_job.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 | 234 |
| 235 // Check if the entry has a redirect URL. | 235 // Check if the entry has a redirect URL. |
| 236 file_system_context_->external_backend()->GetRedirectURLForContents( | 236 file_system_context_->external_backend()->GetRedirectURLForContents( |
| 237 file_system_url_, | 237 file_system_url_, |
| 238 base::Bind(&ExternalFileURLRequestJob::OnRedirectURLObtained, | 238 base::Bind(&ExternalFileURLRequestJob::OnRedirectURLObtained, |
| 239 weak_ptr_factory_.GetWeakPtr())); | 239 weak_ptr_factory_.GetWeakPtr())); |
| 240 } | 240 } |
| 241 | 241 |
| 242 void ExternalFileURLRequestJob::OnRedirectURLObtained( | 242 void ExternalFileURLRequestJob::OnRedirectURLObtained( |
| 243 const GURL& redirect_url) { | 243 const GURL& redirect_url) { |
| 244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 244 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 245 redirect_url_ = redirect_url; | 245 redirect_url_ = redirect_url; |
| 246 if (!redirect_url_.is_empty()) { | 246 if (!redirect_url_.is_empty()) { |
| 247 NotifyHeadersComplete(); | 247 NotifyHeadersComplete(); |
| 248 return; | 248 return; |
| 249 } | 249 } |
| 250 | 250 |
| 251 // Obtain file system context. | 251 // Obtain file system context. |
| 252 file_system_context_->operation_runner()->GetMetadata( | 252 file_system_context_->operation_runner()->GetMetadata( |
| 253 file_system_url_, | 253 file_system_url_, |
| 254 base::Bind(&ExternalFileURLRequestJob::OnFileInfoObtained, | 254 base::Bind(&ExternalFileURLRequestJob::OnFileInfoObtained, |
| 255 weak_ptr_factory_.GetWeakPtr())); | 255 weak_ptr_factory_.GetWeakPtr())); |
| 256 } | 256 } |
| 257 | 257 |
| 258 void ExternalFileURLRequestJob::OnFileInfoObtained( | 258 void ExternalFileURLRequestJob::OnFileInfoObtained( |
| 259 base::File::Error result, | 259 base::File::Error result, |
| 260 const base::File::Info& file_info) { | 260 const base::File::Info& file_info) { |
| 261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 261 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 262 | 262 |
| 263 if (result == base::File::FILE_ERROR_NOT_FOUND) { | 263 if (result == base::File::FILE_ERROR_NOT_FOUND) { |
| 264 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, | 264 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
| 265 net::ERR_FILE_NOT_FOUND)); | 265 net::ERR_FILE_NOT_FOUND)); |
| 266 return; | 266 return; |
| 267 } | 267 } |
| 268 | 268 |
| 269 if (result != base::File::FILE_OK || file_info.is_directory || | 269 if (result != base::File::FILE_OK || file_info.is_directory || |
| 270 file_info.size < 0) { | 270 file_info.size < 0) { |
| 271 NotifyStartError( | 271 NotifyStartError( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 291 if (!stream_reader_) { | 291 if (!stream_reader_) { |
| 292 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, | 292 NotifyStartError(net::URLRequestStatus(net::URLRequestStatus::FAILED, |
| 293 net::ERR_FILE_NOT_FOUND)); | 293 net::ERR_FILE_NOT_FOUND)); |
| 294 return; | 294 return; |
| 295 } | 295 } |
| 296 | 296 |
| 297 NotifyHeadersComplete(); | 297 NotifyHeadersComplete(); |
| 298 } | 298 } |
| 299 | 299 |
| 300 void ExternalFileURLRequestJob::Kill() { | 300 void ExternalFileURLRequestJob::Kill() { |
| 301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 301 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 302 | 302 |
| 303 stream_reader_.reset(); | 303 stream_reader_.reset(); |
| 304 isolated_file_system_scope_.reset(); | 304 isolated_file_system_scope_.reset(); |
| 305 file_system_context_ = NULL; | 305 file_system_context_ = NULL; |
| 306 net::URLRequestJob::Kill(); | 306 net::URLRequestJob::Kill(); |
| 307 weak_ptr_factory_.InvalidateWeakPtrs(); | 307 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 308 } | 308 } |
| 309 | 309 |
| 310 bool ExternalFileURLRequestJob::GetMimeType(std::string* mime_type) const { | 310 bool ExternalFileURLRequestJob::GetMimeType(std::string* mime_type) const { |
| 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 311 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 312 mime_type->assign(mime_type_); | 312 mime_type->assign(mime_type_); |
| 313 return !mime_type->empty(); | 313 return !mime_type->empty(); |
| 314 } | 314 } |
| 315 | 315 |
| 316 bool ExternalFileURLRequestJob::IsRedirectResponse(GURL* location, | 316 bool ExternalFileURLRequestJob::IsRedirectResponse(GURL* location, |
| 317 int* http_status_code) { | 317 int* http_status_code) { |
| 318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 318 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 319 if (redirect_url_.is_empty()) | 319 if (redirect_url_.is_empty()) |
| 320 return false; | 320 return false; |
| 321 | 321 |
| 322 // Redirect a hosted document. | 322 // Redirect a hosted document. |
| 323 *location = redirect_url_; | 323 *location = redirect_url_; |
| 324 const int kHttpFound = 302; | 324 const int kHttpFound = 302; |
| 325 *http_status_code = kHttpFound; | 325 *http_status_code = kHttpFound; |
| 326 return true; | 326 return true; |
| 327 } | 327 } |
| 328 | 328 |
| 329 bool ExternalFileURLRequestJob::ReadRawData(net::IOBuffer* buf, | 329 bool ExternalFileURLRequestJob::ReadRawData(net::IOBuffer* buf, |
| 330 int buf_size, | 330 int buf_size, |
| 331 int* bytes_read) { | 331 int* bytes_read) { |
| 332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 332 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 333 DCHECK(stream_reader_); | 333 DCHECK(stream_reader_); |
| 334 | 334 |
| 335 if (remaining_bytes_ == 0) { | 335 if (remaining_bytes_ == 0) { |
| 336 *bytes_read = 0; | 336 *bytes_read = 0; |
| 337 return true; | 337 return true; |
| 338 } | 338 } |
| 339 | 339 |
| 340 const int result = stream_reader_->Read( | 340 const int result = stream_reader_->Read( |
| 341 buf, | 341 buf, |
| 342 std::min<int64>(buf_size, remaining_bytes_), | 342 std::min<int64>(buf_size, remaining_bytes_), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 357 // Reading has been finished immediately. | 357 // Reading has been finished immediately. |
| 358 *bytes_read = result; | 358 *bytes_read = result; |
| 359 remaining_bytes_ -= result; | 359 remaining_bytes_ -= result; |
| 360 return true; | 360 return true; |
| 361 } | 361 } |
| 362 | 362 |
| 363 ExternalFileURLRequestJob::~ExternalFileURLRequestJob() { | 363 ExternalFileURLRequestJob::~ExternalFileURLRequestJob() { |
| 364 } | 364 } |
| 365 | 365 |
| 366 void ExternalFileURLRequestJob::OnReadCompleted(int read_result) { | 366 void ExternalFileURLRequestJob::OnReadCompleted(int read_result) { |
| 367 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 367 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 368 | 368 |
| 369 if (read_result < 0) { | 369 if (read_result < 0) { |
| 370 DCHECK_NE(read_result, net::ERR_IO_PENDING); | 370 DCHECK_NE(read_result, net::ERR_IO_PENDING); |
| 371 NotifyDone( | 371 NotifyDone( |
| 372 net::URLRequestStatus(net::URLRequestStatus::FAILED, read_result)); | 372 net::URLRequestStatus(net::URLRequestStatus::FAILED, read_result)); |
| 373 } | 373 } |
| 374 | 374 |
| 375 remaining_bytes_ -= read_result; | 375 remaining_bytes_ -= read_result; |
| 376 SetStatus(net::URLRequestStatus()); // Clear the IO_PENDING status. | 376 SetStatus(net::URLRequestStatus()); // Clear the IO_PENDING status. |
| 377 NotifyReadComplete(read_result); | 377 NotifyReadComplete(read_result); |
| 378 } | 378 } |
| 379 | 379 |
| 380 } // namespace chromeos | 380 } // namespace chromeos |
| OLD | NEW |