| 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 "chrome/browser/google_apis/drive_uploader.h" | 5 #include "chrome/browser/google_apis/drive_uploader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 | 307 |
| 308 // Determine number of bytes to read for this upload iteration. | 308 // Determine number of bytes to read for this upload iteration. |
| 309 const int bytes_to_read = std::min(upload_file_info->SizeRemaining(), | 309 const int bytes_to_read = std::min(upload_file_info->SizeRemaining(), |
| 310 kUploadChunkSize); | 310 kUploadChunkSize); |
| 311 | 311 |
| 312 if (bytes_to_read == 0) { | 312 if (bytes_to_read == 0) { |
| 313 // net::FileStream doesn't allow to read 0 bytes, so directly proceed to the | 313 // net::FileStream doesn't allow to read 0 bytes, so directly proceed to the |
| 314 // completion callback. PostTask is necessary because we have to finish | 314 // completion callback. PostTask is necessary because we have to finish |
| 315 // InitiateUpload's callback before calling ResumeUpload, due to the | 315 // InitiateUpload's callback before calling ResumeUpload, due to the |
| 316 // implementation of OperationRegistry. (http://crbug.com/134814) | 316 // implementation of OperationRegistry. (http://crbug.com/134814) |
| 317 MessageLoop::current()->PostTask( | 317 base::MessageLoop::current()->PostTask( |
| 318 FROM_HERE, | 318 FROM_HERE, |
| 319 base::Bind(&DriveUploader::ReadCompletionCallback, | 319 base::Bind(&DriveUploader::ReadCompletionCallback, |
| 320 weak_ptr_factory_.GetWeakPtr(), | 320 weak_ptr_factory_.GetWeakPtr(), |
| 321 base::Passed(&upload_file_info), 0, 0)); | 321 base::Passed(&upload_file_info), |
| 322 0, |
| 323 0)); |
| 322 return; | 324 return; |
| 323 } | 325 } |
| 324 | 326 |
| 325 // Passing a raw |file_stream| and |buf| to the blocking pool is safe, because | 327 // Passing a raw |file_stream| and |buf| to the blocking pool is safe, because |
| 326 // they are owned by |upload_file_info| in the reply callback. | 328 // they are owned by |upload_file_info| in the reply callback. |
| 327 UploadFileInfo* info_ptr = upload_file_info.get(); | 329 UploadFileInfo* info_ptr = upload_file_info.get(); |
| 328 base::PostTaskAndReplyWithResult( | 330 base::PostTaskAndReplyWithResult( |
| 329 blocking_task_runner_.get(), | 331 blocking_task_runner_.get(), |
| 330 FROM_HERE, | 332 FROM_HERE, |
| 331 base::Bind(&net::FileStream::ReadUntilComplete, | 333 base::Bind(&net::FileStream::ReadUntilComplete, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 | 454 |
| 453 LOG(ERROR) << "Upload failed " << upload_file_info->DebugString(); | 455 LOG(ERROR) << "Upload failed " << upload_file_info->DebugString(); |
| 454 | 456 |
| 455 upload_file_info->completion_callback.Run(error, | 457 upload_file_info->completion_callback.Run(error, |
| 456 upload_file_info->drive_path, | 458 upload_file_info->drive_path, |
| 457 upload_file_info->file_path, | 459 upload_file_info->file_path, |
| 458 scoped_ptr<ResourceEntry>()); | 460 scoped_ptr<ResourceEntry>()); |
| 459 } | 461 } |
| 460 | 462 |
| 461 } // namespace google_apis | 463 } // namespace google_apis |
| OLD | NEW |