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/gdata/gdata_uploader.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 << "\" for reading: " << net::ErrorToString(result) | 242 << "\" for reading: " << net::ErrorToString(result) |
243 << ", tries=" << upload_file_info->num_file_open_tries; | 243 << ", tries=" << upload_file_info->num_file_open_tries; |
244 | 244 |
245 // Stop trying to open this file if we exceed kMaxFileOpenTries. | 245 // Stop trying to open this file if we exceed kMaxFileOpenTries. |
246 const bool exceeded_max_attempts = | 246 const bool exceeded_max_attempts = |
247 upload_file_info->num_file_open_tries >= kMaxFileOpenTries; | 247 upload_file_info->num_file_open_tries >= kMaxFileOpenTries; |
248 upload_file_info->should_retry_file_open = !exceeded_max_attempts; | 248 upload_file_info->should_retry_file_open = !exceeded_max_attempts; |
249 } | 249 } |
250 if (!upload_file_info->should_retry_file_open) { | 250 if (!upload_file_info->should_retry_file_open) { |
251 UploadFailed(scoped_ptr<UploadFileInfo>(upload_file_info), | 251 UploadFailed(scoped_ptr<UploadFileInfo>(upload_file_info), |
252 GDATA_FILE_ERROR_NOT_FOUND); | 252 DRIVE_FILE_ERROR_NOT_FOUND); |
253 } | 253 } |
254 return; | 254 return; |
255 } | 255 } |
256 | 256 |
257 // Open succeeded, initiate the upload. | 257 // Open succeeded, initiate the upload. |
258 upload_file_info->should_retry_file_open = false; | 258 upload_file_info->should_retry_file_open = false; |
259 if (upload_file_info->initial_upload_location.is_empty()) { | 259 if (upload_file_info->initial_upload_location.is_empty()) { |
260 UploadFailed(scoped_ptr<UploadFileInfo>(upload_file_info), | 260 UploadFailed(scoped_ptr<UploadFileInfo>(upload_file_info), |
261 GDATA_FILE_ERROR_ABORT); | 261 DRIVE_FILE_ERROR_ABORT); |
262 return; | 262 return; |
263 } | 263 } |
264 drive_service_->InitiateUpload( | 264 drive_service_->InitiateUpload( |
265 InitiateUploadParams(upload_file_info->upload_mode, | 265 InitiateUploadParams(upload_file_info->upload_mode, |
266 upload_file_info->title, | 266 upload_file_info->title, |
267 upload_file_info->content_type, | 267 upload_file_info->content_type, |
268 upload_file_info->content_length, | 268 upload_file_info->content_length, |
269 upload_file_info->initial_upload_location, | 269 upload_file_info->initial_upload_location, |
270 upload_file_info->gdata_path), | 270 upload_file_info->gdata_path), |
271 base::Bind(&GDataUploader::OnUploadLocationReceived, | 271 base::Bind(&GDataUploader::OnUploadLocationReceived, |
(...skipping 10 matching lines...) Expand all Loading... |
282 UploadFileInfo* upload_file_info = GetUploadFileInfo(upload_id); | 282 UploadFileInfo* upload_file_info = GetUploadFileInfo(upload_id); |
283 if (!upload_file_info) | 283 if (!upload_file_info) |
284 return; | 284 return; |
285 | 285 |
286 DVLOG(1) << "Got upload location [" << upload_location.spec() | 286 DVLOG(1) << "Got upload location [" << upload_location.spec() |
287 << "] for [" << upload_file_info->title << "]"; | 287 << "] for [" << upload_file_info->title << "]"; |
288 | 288 |
289 if (code != HTTP_SUCCESS) { | 289 if (code != HTTP_SUCCESS) { |
290 // TODO(achuith): Handle error codes from Google Docs server. | 290 // TODO(achuith): Handle error codes from Google Docs server. |
291 UploadFailed(scoped_ptr<UploadFileInfo>(upload_file_info), | 291 UploadFailed(scoped_ptr<UploadFileInfo>(upload_file_info), |
292 GDATA_FILE_ERROR_ABORT); | 292 DRIVE_FILE_ERROR_ABORT); |
293 return; | 293 return; |
294 } | 294 } |
295 | 295 |
296 upload_file_info->upload_location = upload_location; | 296 upload_file_info->upload_location = upload_location; |
297 | 297 |
298 // Start the upload from the beginning of the file. | 298 // Start the upload from the beginning of the file. |
299 UploadNextChunk(upload_file_info); | 299 UploadNextChunk(upload_file_info); |
300 } | 300 } |
301 | 301 |
302 void GDataUploader::UploadNextChunk(UploadFileInfo* upload_file_info) { | 302 void GDataUploader::UploadNextChunk(UploadFileInfo* upload_file_info) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 << upload_file_info->title; | 418 << upload_file_info->title; |
419 | 419 |
420 // Remove |upload_id| from the UploadFileInfoMap. The UploadFileInfo object | 420 // Remove |upload_id| from the UploadFileInfoMap. The UploadFileInfo object |
421 // will be deleted upon completion of completion_callback. | 421 // will be deleted upon completion of completion_callback. |
422 RemoveUpload(upload_id); | 422 RemoveUpload(upload_id); |
423 | 423 |
424 // Done uploading. | 424 // Done uploading. |
425 upload_file_info->entry = entry.Pass(); | 425 upload_file_info->entry = entry.Pass(); |
426 if (!upload_file_info->completion_callback.is_null()) { | 426 if (!upload_file_info->completion_callback.is_null()) { |
427 upload_file_info->completion_callback.Run( | 427 upload_file_info->completion_callback.Run( |
428 GDATA_FILE_OK, | 428 DRIVE_FILE_OK, |
429 scoped_ptr<UploadFileInfo>(upload_file_info)); | 429 scoped_ptr<UploadFileInfo>(upload_file_info)); |
430 } | 430 } |
431 return; | 431 return; |
432 } | 432 } |
433 | 433 |
434 // If code is 308 (RESUME_INCOMPLETE) and range_received is what has been | 434 // If code is 308 (RESUME_INCOMPLETE) and range_received is what has been |
435 // previously uploaded (i.e. = upload_file_info->end_range), proceed to | 435 // previously uploaded (i.e. = upload_file_info->end_range), proceed to |
436 // upload the next chunk. | 436 // upload the next chunk. |
437 if (response.code != HTTP_RESUME_INCOMPLETE || | 437 if (response.code != HTTP_RESUME_INCOMPLETE || |
438 response.start_range_received != 0 || | 438 response.start_range_received != 0 || |
439 response.end_range_received != upload_file_info->end_range) { | 439 response.end_range_received != upload_file_info->end_range) { |
440 // TODO(achuith): Handle error cases, e.g. | 440 // TODO(achuith): Handle error cases, e.g. |
441 // - when previously uploaded data wasn't received by Google Docs server, | 441 // - when previously uploaded data wasn't received by Google Docs server, |
442 // i.e. when end_range_received < upload_file_info->end_range | 442 // i.e. when end_range_received < upload_file_info->end_range |
443 LOG(ERROR) << "UploadNextChunk http code=" << response.code | 443 LOG(ERROR) << "UploadNextChunk http code=" << response.code |
444 << ", start_range_received=" << response.start_range_received | 444 << ", start_range_received=" << response.start_range_received |
445 << ", end_range_received=" << response.end_range_received | 445 << ", end_range_received=" << response.end_range_received |
446 << ", expected end range=" << upload_file_info->end_range; | 446 << ", expected end range=" << upload_file_info->end_range; |
447 UploadFailed( | 447 UploadFailed( |
448 scoped_ptr<UploadFileInfo>(upload_file_info), | 448 scoped_ptr<UploadFileInfo>(upload_file_info), |
449 response.code == HTTP_FORBIDDEN ? | 449 response.code == HTTP_FORBIDDEN ? |
450 GDATA_FILE_ERROR_NO_SPACE : | 450 DRIVE_FILE_ERROR_NO_SPACE : |
451 GDATA_FILE_ERROR_ABORT); | 451 DRIVE_FILE_ERROR_ABORT); |
452 return; | 452 return; |
453 } | 453 } |
454 | 454 |
455 DVLOG(1) << "Received range " << response.start_range_received | 455 DVLOG(1) << "Received range " << response.start_range_received |
456 << "-" << response.end_range_received | 456 << "-" << response.end_range_received |
457 << " for [" << upload_file_info->title << "]"; | 457 << " for [" << upload_file_info->title << "]"; |
458 | 458 |
459 // Continue uploading. | 459 // Continue uploading. |
460 UploadNextChunk(upload_file_info); | 460 UploadNextChunk(upload_file_info); |
461 } | 461 } |
462 | 462 |
463 void GDataUploader::UploadFailed(scoped_ptr<UploadFileInfo> upload_file_info, | 463 void GDataUploader::UploadFailed(scoped_ptr<UploadFileInfo> upload_file_info, |
464 GDataFileError error) { | 464 DriveFileError error) { |
465 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 465 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
466 | 466 |
467 RemoveUpload(upload_file_info->upload_id); | 467 RemoveUpload(upload_file_info->upload_id); |
468 | 468 |
469 LOG(ERROR) << "Upload failed " << upload_file_info->DebugString(); | 469 LOG(ERROR) << "Upload failed " << upload_file_info->DebugString(); |
470 // This is subtle but we should take the callback reference before | 470 // This is subtle but we should take the callback reference before |
471 // calling upload_file_info.Pass(). Otherwise, it'll crash. | 471 // calling upload_file_info.Pass(). Otherwise, it'll crash. |
472 const UploadFileInfo::UploadCompletionCallback& callback = | 472 const UploadFileInfo::UploadCompletionCallback& callback = |
473 upload_file_info->completion_callback; | 473 upload_file_info->completion_callback; |
474 if (!callback.is_null()) | 474 if (!callback.is_null()) |
475 callback.Run(error, upload_file_info.Pass()); | 475 callback.Run(error, upload_file_info.Pass()); |
476 } | 476 } |
477 | 477 |
478 void GDataUploader::RemoveUpload(int upload_id) { | 478 void GDataUploader::RemoveUpload(int upload_id) { |
479 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 479 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
480 pending_uploads_.erase(upload_id); | 480 pending_uploads_.erase(upload_id); |
481 } | 481 } |
482 | 482 |
483 } // namespace gdata | 483 } // namespace gdata |
OLD | NEW |