| 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/chromeos/drive/drive_uploader.h" | 5 #include "chrome/browser/chromeos/drive/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 11 matching lines...) Expand all Loading... |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // Google Documents List API requires uploading in chunks of 512kB. | 24 // Google Documents List API requires uploading in chunks of 512kB. |
| 25 const int64 kUploadChunkSize = 512 * 1024; | 25 const int64 kUploadChunkSize = 512 * 1024; |
| 26 | 26 |
| 27 // Maximum number of times we try to open a file before giving up. | 27 // Maximum number of times we try to open a file before giving up. |
| 28 const int kMaxFileOpenTries = 5; | 28 const int kMaxFileOpenTries = 5; |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 namespace gdata { | 32 namespace drive { |
| 33 | 33 |
| 34 DriveUploader::DriveUploader(DriveServiceInterface* drive_service) | 34 DriveUploader::DriveUploader(DriveServiceInterface* drive_service) |
| 35 : drive_service_(drive_service), | 35 : drive_service_(drive_service), |
| 36 next_upload_id_(0), | 36 next_upload_id_(0), |
| 37 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 37 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 38 } | 38 } |
| 39 | 39 |
| 40 DriveUploader::~DriveUploader() { | 40 DriveUploader::~DriveUploader() { |
| 41 STLDeleteContainerPairSecondPointers(pending_uploads_.begin(), | 41 STLDeleteContainerPairSecondPointers(pending_uploads_.begin(), |
| 42 pending_uploads_.end()); | 42 pending_uploads_.end()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 53 const UploadCompletionCallback& completion_callback, | 53 const UploadCompletionCallback& completion_callback, |
| 54 const UploaderReadyCallback& ready_callback) { | 54 const UploaderReadyCallback& ready_callback) { |
| 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 55 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 56 DCHECK(!upload_location.is_empty()); | 56 DCHECK(!upload_location.is_empty()); |
| 57 DCHECK(!drive_file_path.empty()); | 57 DCHECK(!drive_file_path.empty()); |
| 58 DCHECK(!local_file_path.empty()); | 58 DCHECK(!local_file_path.empty()); |
| 59 DCHECK(!title.empty()); | 59 DCHECK(!title.empty()); |
| 60 DCHECK(!content_type.empty()); | 60 DCHECK(!content_type.empty()); |
| 61 | 61 |
| 62 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo); | 62 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo); |
| 63 upload_file_info->upload_mode = UPLOAD_NEW_FILE; | 63 upload_file_info->upload_mode = gdata::UPLOAD_NEW_FILE; |
| 64 upload_file_info->initial_upload_location = upload_location; | 64 upload_file_info->initial_upload_location = upload_location; |
| 65 upload_file_info->drive_path = drive_file_path; | 65 upload_file_info->drive_path = drive_file_path; |
| 66 upload_file_info->file_path = local_file_path; | 66 upload_file_info->file_path = local_file_path; |
| 67 upload_file_info->title = title; | 67 upload_file_info->title = title; |
| 68 upload_file_info->content_type = content_type; | 68 upload_file_info->content_type = content_type; |
| 69 upload_file_info->content_length = content_length; | 69 upload_file_info->content_length = content_length; |
| 70 upload_file_info->file_size = file_size; | 70 upload_file_info->file_size = file_size; |
| 71 upload_file_info->all_bytes_present = content_length == file_size; | 71 upload_file_info->all_bytes_present = content_length == file_size; |
| 72 upload_file_info->completion_callback = completion_callback; | 72 upload_file_info->completion_callback = completion_callback; |
| 73 upload_file_info->ready_callback = ready_callback; | 73 upload_file_info->ready_callback = ready_callback; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 89 int64 file_size, | 89 int64 file_size, |
| 90 const UploadCompletionCallback& completion_callback, | 90 const UploadCompletionCallback& completion_callback, |
| 91 const UploaderReadyCallback& ready_callback) { | 91 const UploaderReadyCallback& ready_callback) { |
| 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 93 DCHECK(!upload_location.is_empty()); | 93 DCHECK(!upload_location.is_empty()); |
| 94 DCHECK(!drive_file_path.empty()); | 94 DCHECK(!drive_file_path.empty()); |
| 95 DCHECK(!local_file_path.empty()); | 95 DCHECK(!local_file_path.empty()); |
| 96 DCHECK(!content_type.empty()); | 96 DCHECK(!content_type.empty()); |
| 97 | 97 |
| 98 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo); | 98 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo); |
| 99 upload_file_info->upload_mode = UPLOAD_EXISTING_FILE; | 99 upload_file_info->upload_mode = gdata::UPLOAD_EXISTING_FILE; |
| 100 upload_file_info->initial_upload_location = upload_location; | 100 upload_file_info->initial_upload_location = upload_location; |
| 101 upload_file_info->drive_path = drive_file_path; | 101 upload_file_info->drive_path = drive_file_path; |
| 102 upload_file_info->file_path = local_file_path; | 102 upload_file_info->file_path = local_file_path; |
| 103 upload_file_info->content_type = content_type; | 103 upload_file_info->content_type = content_type; |
| 104 upload_file_info->content_length = content_length; | 104 upload_file_info->content_length = content_length; |
| 105 upload_file_info->file_size = file_size; | 105 upload_file_info->file_size = file_size; |
| 106 upload_file_info->all_bytes_present = content_length == file_size; | 106 upload_file_info->all_bytes_present = content_length == file_size; |
| 107 upload_file_info->completion_callback = completion_callback; | 107 upload_file_info->completion_callback = completion_callback; |
| 108 upload_file_info->ready_callback = ready_callback; | 108 upload_file_info->ready_callback = ready_callback; |
| 109 | 109 |
| 110 // When uploading a new file, we should retry file open as the file may | 110 // When uploading a new file, we should retry file open as the file may |
| 111 // not yet be ready. See comments in OpenCompletionCallback. | 111 // not yet be ready. See comments in OpenCompletionCallback. |
| 112 // TODO(satorux): The retry should be done only when we are uploading | 112 // TODO(satorux): The retry should be done only when we are uploading |
| 113 // while downloading files from web sites (i.e. saving files to Drive). | 113 // while downloading files from web sites (i.e. saving files to Drive). |
| 114 upload_file_info->should_retry_file_open = true; | 114 upload_file_info->should_retry_file_open = true; |
| 115 return StartUploadFile(upload_file_info.Pass()); | 115 return StartUploadFile(upload_file_info.Pass()); |
| 116 } | 116 } |
| 117 | 117 |
| 118 int DriveUploader::StartUploadFile( | 118 int DriveUploader::StartUploadFile( |
| 119 scoped_ptr<UploadFileInfo> upload_file_info) { | 119 scoped_ptr<UploadFileInfo> upload_file_info) { |
| 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 121 DCHECK(upload_file_info.get()); | 121 DCHECK(upload_file_info.get()); |
| 122 DCHECK_EQ(upload_file_info->upload_id, -1); | 122 DCHECK_EQ(upload_file_info->upload_id, -1); |
| 123 DCHECK_NE(UPLOAD_INVALID, upload_file_info->upload_mode); | 123 DCHECK_NE(gdata::UPLOAD_INVALID, upload_file_info->upload_mode); |
| 124 | 124 |
| 125 const int upload_id = next_upload_id_++; | 125 const int upload_id = next_upload_id_++; |
| 126 upload_file_info->upload_id = upload_id; | 126 upload_file_info->upload_id = upload_id; |
| 127 | 127 |
| 128 // Add upload_file_info to our internal map and take ownership. | 128 // Add upload_file_info to our internal map and take ownership. |
| 129 pending_uploads_[upload_id] = upload_file_info.release(); | 129 pending_uploads_[upload_id] = upload_file_info.release(); |
| 130 UploadFileInfo* info = GetUploadFileInfo(upload_id); | 130 UploadFileInfo* info = GetUploadFileInfo(upload_id); |
| 131 DVLOG(1) << "Uploading file: " << info->DebugString(); | 131 DVLOG(1) << "Uploading file: " << info->DebugString(); |
| 132 | 132 |
| 133 // Create a FileStream to make sure the file can be opened successfully. | 133 // Create a FileStream to make sure the file can be opened successfully. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 150 int64 file_size, | 150 int64 file_size, |
| 151 const UploadCompletionCallback& completion_callback, | 151 const UploadCompletionCallback& completion_callback, |
| 152 const UploaderReadyCallback& ready_callback) { | 152 const UploaderReadyCallback& ready_callback) { |
| 153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 154 DCHECK(!upload_location.is_empty()); | 154 DCHECK(!upload_location.is_empty()); |
| 155 DCHECK(!drive_file_path.empty()); | 155 DCHECK(!drive_file_path.empty()); |
| 156 DCHECK(!local_file_path.empty()); | 156 DCHECK(!local_file_path.empty()); |
| 157 DCHECK(!content_type.empty()); | 157 DCHECK(!content_type.empty()); |
| 158 | 158 |
| 159 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo); | 159 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo); |
| 160 upload_file_info->upload_mode = UPLOAD_EXISTING_FILE; | 160 upload_file_info->upload_mode = gdata::UPLOAD_EXISTING_FILE; |
| 161 upload_file_info->initial_upload_location = upload_location; | 161 upload_file_info->initial_upload_location = upload_location; |
| 162 upload_file_info->drive_path = drive_file_path; | 162 upload_file_info->drive_path = drive_file_path; |
| 163 upload_file_info->file_path = local_file_path; | 163 upload_file_info->file_path = local_file_path; |
| 164 upload_file_info->content_type = content_type; | 164 upload_file_info->content_type = content_type; |
| 165 upload_file_info->content_length = file_size; | 165 upload_file_info->content_length = file_size; |
| 166 upload_file_info->file_size = file_size; | 166 upload_file_info->file_size = file_size; |
| 167 upload_file_info->all_bytes_present = true; | 167 upload_file_info->all_bytes_present = true; |
| 168 upload_file_info->completion_callback = completion_callback; | 168 upload_file_info->completion_callback = completion_callback; |
| 169 upload_file_info->ready_callback = ready_callback; | 169 upload_file_info->ready_callback = ready_callback; |
| 170 | 170 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 return; | 292 return; |
| 293 } | 293 } |
| 294 } else { | 294 } else { |
| 295 // Open succeeded, initiate the upload. | 295 // Open succeeded, initiate the upload. |
| 296 upload_file_info->should_retry_file_open = false; | 296 upload_file_info->should_retry_file_open = false; |
| 297 if (upload_file_info->initial_upload_location.is_empty()) { | 297 if (upload_file_info->initial_upload_location.is_empty()) { |
| 298 UploadFailed(upload_file_info, DRIVE_FILE_ERROR_ABORT); | 298 UploadFailed(upload_file_info, DRIVE_FILE_ERROR_ABORT); |
| 299 return; | 299 return; |
| 300 } | 300 } |
| 301 drive_service_->InitiateUpload( | 301 drive_service_->InitiateUpload( |
| 302 InitiateUploadParams(upload_file_info->upload_mode, | 302 gdata::InitiateUploadParams(upload_file_info->upload_mode, |
| 303 upload_file_info->title, | 303 upload_file_info->title, |
| 304 upload_file_info->content_type, | 304 upload_file_info->content_type, |
| 305 upload_file_info->content_length, | 305 upload_file_info->content_length, |
| 306 upload_file_info->initial_upload_location, | 306 upload_file_info->initial_upload_location, |
| 307 upload_file_info->drive_path), | 307 upload_file_info->drive_path), |
| 308 base::Bind(&DriveUploader::OnUploadLocationReceived, | 308 base::Bind(&DriveUploader::OnUploadLocationReceived, |
| 309 weak_ptr_factory_.GetWeakPtr(), | 309 weak_ptr_factory_.GetWeakPtr(), |
| 310 upload_file_info->upload_id)); | 310 upload_file_info->upload_id)); |
| 311 } | 311 } |
| 312 // The uploader gets ready after we complete opening the file, called | 312 // The uploader gets ready after we complete opening the file, called |
| 313 // from the StartUploadFile method. We use PostTask on purpose, because | 313 // from the StartUploadFile method. We use PostTask on purpose, because |
| 314 // this callback is called by FileStream, and we may access FileStream | 314 // this callback is called by FileStream, and we may access FileStream |
| 315 // again from the |ready_callback| implementation. FileStream is not | 315 // again from the |ready_callback| implementation. FileStream is not |
| 316 // reentrant. | 316 // reentrant. |
| 317 // | 317 // |
| 318 // Note, that we call this callback if we opened the file, or if we | 318 // Note, that we call this callback if we opened the file, or if we |
| 319 // failed, but further retries are scheduled. The callback will not be | 319 // failed, but further retries are scheduled. The callback will not be |
| 320 // called if the upload has been aborted. | 320 // called if the upload has been aborted. |
| 321 if (open_type == FILE_OPEN_START_UPLOAD && | 321 if (open_type == FILE_OPEN_START_UPLOAD && |
| 322 !upload_file_info->ready_callback.is_null()) { | 322 !upload_file_info->ready_callback.is_null()) { |
| 323 BrowserThread::PostTask( | 323 BrowserThread::PostTask( |
| 324 BrowserThread::UI, | 324 BrowserThread::UI, |
| 325 FROM_HERE, | 325 FROM_HERE, |
| 326 base::Bind(upload_file_info->ready_callback, upload_id)); | 326 base::Bind(upload_file_info->ready_callback, upload_id)); |
| 327 } | 327 } |
| 328 } | 328 } |
| 329 | 329 |
| 330 void DriveUploader::OnUploadLocationReceived( | 330 void DriveUploader::OnUploadLocationReceived( |
| 331 int upload_id, | 331 int upload_id, |
| 332 GDataErrorCode code, | 332 gdata::GDataErrorCode code, |
| 333 const GURL& upload_location) { | 333 const GURL& upload_location) { |
| 334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 335 | 335 |
| 336 UploadFileInfo* upload_file_info = GetUploadFileInfo(upload_id); | 336 UploadFileInfo* upload_file_info = GetUploadFileInfo(upload_id); |
| 337 if (!upload_file_info) | 337 if (!upload_file_info) |
| 338 return; | 338 return; |
| 339 | 339 |
| 340 DVLOG(1) << "Got upload location [" << upload_location.spec() | 340 DVLOG(1) << "Got upload location [" << upload_location.spec() |
| 341 << "] for [" << upload_file_info->title << "]"; | 341 << "] for [" << upload_file_info->title << "]"; |
| 342 | 342 |
| 343 if (code != HTTP_SUCCESS) { | 343 if (code != gdata::HTTP_SUCCESS) { |
| 344 // TODO(achuith): Handle error codes from Google Docs server. | 344 // TODO(achuith): Handle error codes from Google Docs server. |
| 345 UploadFailed(upload_file_info, DRIVE_FILE_ERROR_ABORT); | 345 UploadFailed(upload_file_info, DRIVE_FILE_ERROR_ABORT); |
| 346 return; | 346 return; |
| 347 } | 347 } |
| 348 | 348 |
| 349 upload_file_info->upload_location = upload_location; | 349 upload_file_info->upload_location = upload_location; |
| 350 | 350 |
| 351 // Start the upload from the beginning of the file. | 351 // Start the upload from the beginning of the file. |
| 352 UploadNextChunk(upload_file_info); | 352 UploadNextChunk(upload_file_info); |
| 353 } | 353 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 | 434 |
| 435 ResumeUpload(upload_id); | 435 ResumeUpload(upload_id); |
| 436 } | 436 } |
| 437 | 437 |
| 438 void DriveUploader::ResumeUpload(int upload_id) { | 438 void DriveUploader::ResumeUpload(int upload_id) { |
| 439 UploadFileInfo* upload_file_info = GetUploadFileInfo(upload_id); | 439 UploadFileInfo* upload_file_info = GetUploadFileInfo(upload_id); |
| 440 if (!upload_file_info) | 440 if (!upload_file_info) |
| 441 return; | 441 return; |
| 442 | 442 |
| 443 drive_service_->ResumeUpload( | 443 drive_service_->ResumeUpload( |
| 444 ResumeUploadParams(upload_file_info->upload_mode, | 444 gdata::ResumeUploadParams(upload_file_info->upload_mode, |
| 445 upload_file_info->start_range, | 445 upload_file_info->start_range, |
| 446 upload_file_info->end_range, | 446 upload_file_info->end_range, |
| 447 upload_file_info->content_length, | 447 upload_file_info->content_length, |
| 448 upload_file_info->content_type, | 448 upload_file_info->content_type, |
| 449 upload_file_info->buf, | 449 upload_file_info->buf, |
| 450 upload_file_info->upload_location, | 450 upload_file_info->upload_location, |
| 451 upload_file_info->drive_path), | 451 upload_file_info->drive_path), |
| 452 base::Bind(&DriveUploader::OnResumeUploadResponseReceived, | 452 base::Bind(&DriveUploader::OnResumeUploadResponseReceived, |
| 453 weak_ptr_factory_.GetWeakPtr(), | 453 weak_ptr_factory_.GetWeakPtr(), |
| 454 upload_file_info->upload_id)); | 454 upload_file_info->upload_id)); |
| 455 } | 455 } |
| 456 | 456 |
| 457 void DriveUploader::OnResumeUploadResponseReceived( | 457 void DriveUploader::OnResumeUploadResponseReceived( |
| 458 int upload_id, | 458 int upload_id, |
| 459 const ResumeUploadResponse& response, | 459 const gdata::ResumeUploadResponse& response, |
| 460 scoped_ptr<DocumentEntry> entry) { | 460 scoped_ptr<gdata::DocumentEntry> entry) { |
| 461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 462 | 462 |
| 463 UploadFileInfo* upload_file_info = GetUploadFileInfo(upload_id); | 463 UploadFileInfo* upload_file_info = GetUploadFileInfo(upload_id); |
| 464 if (!upload_file_info) | 464 if (!upload_file_info) |
| 465 return; | 465 return; |
| 466 | 466 |
| 467 const UploadMode upload_mode = upload_file_info->upload_mode; | 467 const gdata::UploadMode upload_mode = upload_file_info->upload_mode; |
| 468 if ((upload_mode == UPLOAD_NEW_FILE && response.code == HTTP_CREATED) || | 468 if ((upload_mode == gdata::UPLOAD_NEW_FILE && |
| 469 (upload_mode == UPLOAD_EXISTING_FILE && response.code == HTTP_SUCCESS)) { | 469 response.code == gdata::HTTP_CREATED) || |
| 470 (upload_mode == gdata::UPLOAD_EXISTING_FILE && |
| 471 response.code == gdata::HTTP_SUCCESS)) { |
| 470 DVLOG(1) << "Successfully created uploaded file=[" | 472 DVLOG(1) << "Successfully created uploaded file=[" |
| 471 << upload_file_info->title; | 473 << upload_file_info->title; |
| 472 | 474 |
| 473 // Done uploading. | 475 // Done uploading. |
| 474 upload_file_info->entry = entry.Pass(); | 476 upload_file_info->entry = entry.Pass(); |
| 475 if (!upload_file_info->completion_callback.is_null()) { | 477 if (!upload_file_info->completion_callback.is_null()) { |
| 476 upload_file_info->completion_callback.Run( | 478 upload_file_info->completion_callback.Run( |
| 477 DRIVE_FILE_OK, | 479 DRIVE_FILE_OK, |
| 478 upload_file_info->drive_path, | 480 upload_file_info->drive_path, |
| 479 upload_file_info->file_path, | 481 upload_file_info->file_path, |
| 480 upload_file_info->entry.Pass()); | 482 upload_file_info->entry.Pass()); |
| 481 } | 483 } |
| 482 | 484 |
| 483 // This will delete |upload_file_info|. | 485 // This will delete |upload_file_info|. |
| 484 RemoveUpload(scoped_ptr<UploadFileInfo>(upload_file_info)); | 486 RemoveUpload(scoped_ptr<UploadFileInfo>(upload_file_info)); |
| 485 return; | 487 return; |
| 486 } | 488 } |
| 487 | 489 |
| 488 // If code is 308 (RESUME_INCOMPLETE) and range_received is what has been | 490 // If code is 308 (RESUME_INCOMPLETE) and range_received is what has been |
| 489 // previously uploaded (i.e. = upload_file_info->end_range), proceed to | 491 // previously uploaded (i.e. = upload_file_info->end_range), proceed to |
| 490 // upload the next chunk. | 492 // upload the next chunk. |
| 491 if (response.code != HTTP_RESUME_INCOMPLETE || | 493 if (response.code != gdata::HTTP_RESUME_INCOMPLETE || |
| 492 response.start_range_received != 0 || | 494 response.start_range_received != 0 || |
| 493 response.end_range_received != upload_file_info->end_range) { | 495 response.end_range_received != upload_file_info->end_range) { |
| 494 // TODO(achuith): Handle error cases, e.g. | 496 // TODO(achuith): Handle error cases, e.g. |
| 495 // - when previously uploaded data wasn't received by Google Docs server, | 497 // - when previously uploaded data wasn't received by Google Docs server, |
| 496 // i.e. when end_range_received < upload_file_info->end_range | 498 // i.e. when end_range_received < upload_file_info->end_range |
| 497 LOG(ERROR) << "UploadNextChunk http code=" << response.code | 499 LOG(ERROR) << "UploadNextChunk http code=" << response.code |
| 498 << ", start_range_received=" << response.start_range_received | 500 << ", start_range_received=" << response.start_range_received |
| 499 << ", end_range_received=" << response.end_range_received | 501 << ", end_range_received=" << response.end_range_received |
| 500 << ", expected end range=" << upload_file_info->end_range; | 502 << ", expected end range=" << upload_file_info->end_range; |
| 501 UploadFailed( | 503 UploadFailed( |
| 502 upload_file_info, | 504 upload_file_info, |
| 503 response.code == HTTP_FORBIDDEN ? | 505 response.code == gdata::HTTP_FORBIDDEN ? |
| 504 DRIVE_FILE_ERROR_NO_SPACE : DRIVE_FILE_ERROR_ABORT); | 506 DRIVE_FILE_ERROR_NO_SPACE : DRIVE_FILE_ERROR_ABORT); |
| 505 return; | 507 return; |
| 506 } | 508 } |
| 507 | 509 |
| 508 DVLOG(1) << "Received range " << response.start_range_received | 510 DVLOG(1) << "Received range " << response.start_range_received |
| 509 << "-" << response.end_range_received | 511 << "-" << response.end_range_received |
| 510 << " for [" << upload_file_info->title << "]"; | 512 << " for [" << upload_file_info->title << "]"; |
| 511 | 513 |
| 512 // Continue uploading. | 514 // Continue uploading. |
| 513 UploadNextChunk(upload_file_info); | 515 UploadNextChunk(upload_file_info); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 532 | 534 |
| 533 void DriveUploader::RemoveUpload(scoped_ptr<UploadFileInfo> upload_file_info) { | 535 void DriveUploader::RemoveUpload(scoped_ptr<UploadFileInfo> upload_file_info) { |
| 534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 536 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 535 pending_uploads_.erase(upload_file_info->upload_id); | 537 pending_uploads_.erase(upload_file_info->upload_id); |
| 536 } | 538 } |
| 537 | 539 |
| 538 DriveUploader::UploadFileInfo::UploadFileInfo() | 540 DriveUploader::UploadFileInfo::UploadFileInfo() |
| 539 : upload_id(-1), | 541 : upload_id(-1), |
| 540 file_size(0), | 542 file_size(0), |
| 541 content_length(0), | 543 content_length(0), |
| 542 upload_mode(UPLOAD_INVALID), | 544 upload_mode(gdata::UPLOAD_INVALID), |
| 543 file_stream(NULL), | 545 file_stream(NULL), |
| 544 buf_len(0), | 546 buf_len(0), |
| 545 start_range(0), | 547 start_range(0), |
| 546 end_range(-1), | 548 end_range(-1), |
| 547 all_bytes_present(false), | 549 all_bytes_present(false), |
| 548 upload_paused(false), | 550 upload_paused(false), |
| 549 should_retry_file_open(false), | 551 should_retry_file_open(false), |
| 550 num_file_open_tries(0) { | 552 num_file_open_tries(0) { |
| 551 } | 553 } |
| 552 | 554 |
| 553 DriveUploader::UploadFileInfo::~UploadFileInfo() { } | 555 DriveUploader::UploadFileInfo::~UploadFileInfo() { } |
| 554 | 556 |
| 555 int64 DriveUploader::UploadFileInfo::SizeRemaining() const { | 557 int64 DriveUploader::UploadFileInfo::SizeRemaining() const { |
| 556 DCHECK(file_size > end_range); | 558 DCHECK(file_size > end_range); |
| 557 // Note that uploaded_bytes = end_range + 1; | 559 // Note that uploaded_bytes = end_range + 1; |
| 558 return file_size - end_range - 1; | 560 return file_size - end_range - 1; |
| 559 } | 561 } |
| 560 | 562 |
| 561 std::string DriveUploader::UploadFileInfo::DebugString() const { | 563 std::string DriveUploader::UploadFileInfo::DebugString() const { |
| 562 return "title=[" + title + | 564 return "title=[" + title + |
| 563 "], file_path=[" + file_path.AsUTF8Unsafe() + | 565 "], file_path=[" + file_path.AsUTF8Unsafe() + |
| 564 "], content_type=[" + content_type + | 566 "], content_type=[" + content_type + |
| 565 "], content_length=[" + base::UintToString(content_length) + | 567 "], content_length=[" + base::UintToString(content_length) + |
| 566 "], file_size=[" + base::UintToString(file_size) + | 568 "], file_size=[" + base::UintToString(file_size) + |
| 567 "], drive_path=[" + drive_path.AsUTF8Unsafe() + | 569 "], drive_path=[" + drive_path.AsUTF8Unsafe() + |
| 568 "]"; | 570 "]"; |
| 569 } | 571 } |
| 570 | 572 |
| 571 } // namespace gdata | 573 } // namespace drive |
| OLD | NEW |