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/drive_download_observer.h" | 5 #include "chrome/browser/chromeos/gdata/drive_download_observer.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 DownloadManager* download_manager) { | 344 DownloadManager* download_manager) { |
345 download_manager->RemoveObserver(this); | 345 download_manager->RemoveObserver(this); |
346 download_manager_ = NULL; | 346 download_manager_ = NULL; |
347 } | 347 } |
348 | 348 |
349 void DriveDownloadObserver::ModelChanged(DownloadManager* download_manager) { | 349 void DriveDownloadObserver::ModelChanged(DownloadManager* download_manager) { |
350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
351 | 351 |
352 DownloadManager::DownloadVector downloads; | 352 DownloadManager::DownloadVector downloads; |
353 // Drive downloads are considered temporary downloads. | 353 // Drive downloads are considered temporary downloads. |
354 download_manager->GetTemporaryDownloads(drive_tmp_download_path_, | 354 download_manager->GetAllDownloads(&downloads); |
355 &downloads); | |
356 for (size_t i = 0; i < downloads.size(); ++i) { | 355 for (size_t i = 0; i < downloads.size(); ++i) { |
357 // Only accept downloads that have the Drive meta data associated with | 356 // Only accept downloads that have the Drive meta data associated with |
358 // them. Otherwise we might trip over non-Drive downloads being saved to | 357 // them. Otherwise we might trip over non-Drive downloads being saved to |
359 // drive_tmp_download_path_. | 358 // drive_tmp_download_path_. |
360 if (IsDriveDownload(downloads[i])) | 359 if (downloads[i]->IsTemporary() && |
| 360 (downloads[i]->GetTargetFilePath().DirName() == |
| 361 drive_tmp_download_path_) && |
| 362 IsDriveDownload(downloads[i])) |
361 OnDownloadUpdated(downloads[i]); | 363 OnDownloadUpdated(downloads[i]); |
362 } | 364 } |
363 } | 365 } |
364 | 366 |
365 void DriveDownloadObserver::OnDownloadUpdated(DownloadItem* download) { | 367 void DriveDownloadObserver::OnDownloadUpdated(DownloadItem* download) { |
366 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
367 | 369 |
368 const DownloadItem::DownloadState state = download->GetState(); | 370 const DownloadItem::DownloadState state = download->GetState(); |
369 switch (state) { | 371 switch (state) { |
370 case DownloadItem::IN_PROGRESS: | 372 case DownloadItem::IN_PROGRESS: |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 return; | 451 return; |
450 } | 452 } |
451 | 453 |
452 drive_uploader_->UpdateUpload(upload_data->upload_id(), download); | 454 drive_uploader_->UpdateUpload(upload_data->upload_id(), download); |
453 } | 455 } |
454 | 456 |
455 bool DriveDownloadObserver::ShouldUpload(DownloadItem* download) { | 457 bool DriveDownloadObserver::ShouldUpload(DownloadItem* download) { |
456 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
457 | 459 |
458 // Upload if the item is in pending_downloads_, | 460 // Upload if the item is in pending_downloads_, |
| 461 // has a filename, |
459 // is complete or large enough to stream, and, | 462 // is complete or large enough to stream, and, |
460 // is not already being uploaded. | 463 // is not already being uploaded. |
461 return (pending_downloads_.count(download->GetId()) != 0) && | 464 return (pending_downloads_.count(download->GetId()) != 0) && |
| 465 !download->GetFullPath().empty() && |
462 (download->AllDataSaved() || | 466 (download->AllDataSaved() || |
463 download->GetReceivedBytes() > kStreamingFileSize) && | 467 download->GetReceivedBytes() > kStreamingFileSize) && |
464 (GetUploadingUserData(download) == NULL); | 468 (GetUploadingUserData(download) == NULL); |
465 } | 469 } |
466 | 470 |
467 void DriveDownloadObserver::CreateUploadFileInfo(DownloadItem* download) { | 471 void DriveDownloadObserver::CreateUploadFileInfo(DownloadItem* download) { |
468 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 472 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
469 | 473 |
470 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo()); | 474 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo()); |
471 | 475 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 file_system_->AddUploadedFile(UPLOAD_NEW_FILE, | 669 file_system_->AddUploadedFile(UPLOAD_NEW_FILE, |
666 upload_data->virtual_dir_path(), | 670 upload_data->virtual_dir_path(), |
667 entry.Pass(), | 671 entry.Pass(), |
668 download->GetTargetFilePath(), | 672 download->GetTargetFilePath(), |
669 DriveCache::FILE_OPERATION_MOVE, | 673 DriveCache::FILE_OPERATION_MOVE, |
670 base::Bind(&base::DoNothing)); | 674 base::Bind(&base::DoNothing)); |
671 } | 675 } |
672 } | 676 } |
673 | 677 |
674 } // namespace gdata | 678 } // namespace gdata |
OLD | NEW |