| 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_download_observer.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 return system_service; | 111 return system_service; |
| 112 } | 112 } |
| 113 | 113 |
| 114 // Substitutes virtual gdata path for local temporary path. | 114 // Substitutes virtual gdata path for local temporary path. |
| 115 void SubstituteGDataDownloadPathInternal(Profile* profile, | 115 void SubstituteGDataDownloadPathInternal(Profile* profile, |
| 116 const GDataDownloadObserver::SubstituteGDataDownloadPathCallback& | 116 const GDataDownloadObserver::SubstituteGDataDownloadPathCallback& |
| 117 callback) { | 117 callback) { |
| 118 DVLOG(1) << "SubstituteGDataDownloadPathInternal"; | 118 DVLOG(1) << "SubstituteGDataDownloadPathInternal"; |
| 119 | 119 |
| 120 const FilePath gdata_tmp_download_dir = GetSystemService(profile)->cache()-> | 120 const FilePath gdata_tmp_download_dir = GetSystemService(profile)->cache()-> |
| 121 GetCacheDirectoryPath(GDataCache::CACHE_TYPE_TMP_DOWNLOADS); | 121 GetCacheDirectoryPath(DriveCache::CACHE_TYPE_TMP_DOWNLOADS); |
| 122 | 122 |
| 123 // Swap the gdata path with a local path. Local path must be created | 123 // Swap the gdata path with a local path. Local path must be created |
| 124 // on a blocking thread. | 124 // on a blocking thread. |
| 125 FilePath* gdata_tmp_download_path(new FilePath()); | 125 FilePath* gdata_tmp_download_path(new FilePath()); |
| 126 BrowserThread::GetBlockingPool()->PostTaskAndReply( | 126 BrowserThread::GetBlockingPool()->PostTaskAndReply( |
| 127 FROM_HERE, | 127 FROM_HERE, |
| 128 base::Bind(&GDataDownloadObserver::GetGDataTempDownloadPath, | 128 base::Bind(&GDataDownloadObserver::GetGDataTempDownloadPath, |
| 129 gdata_tmp_download_dir, | 129 gdata_tmp_download_dir, |
| 130 gdata_tmp_download_path), | 130 gdata_tmp_download_path), |
| 131 base::Bind(&RunSubstituteGDataDownloadCallback, | 131 base::Bind(&RunSubstituteGDataDownloadCallback, |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 367 |
| 368 const DownloadItem::DownloadState state = download->GetState(); | 368 const DownloadItem::DownloadState state = download->GetState(); |
| 369 switch (state) { | 369 switch (state) { |
| 370 case DownloadItem::IN_PROGRESS: | 370 case DownloadItem::IN_PROGRESS: |
| 371 AddPendingDownload(download); | 371 AddPendingDownload(download); |
| 372 UploadDownloadItem(download); | 372 UploadDownloadItem(download); |
| 373 break; | 373 break; |
| 374 | 374 |
| 375 case DownloadItem::COMPLETE: | 375 case DownloadItem::COMPLETE: |
| 376 UploadDownloadItem(download); | 376 UploadDownloadItem(download); |
| 377 MoveFileToGDataCache(download); | 377 MoveFileToDriveCache(download); |
| 378 RemovePendingDownload(download); | 378 RemovePendingDownload(download); |
| 379 break; | 379 break; |
| 380 | 380 |
| 381 // TODO(achuith): Stop the pending upload and delete the file. | 381 // TODO(achuith): Stop the pending upload and delete the file. |
| 382 case DownloadItem::CANCELLED: | 382 case DownloadItem::CANCELLED: |
| 383 case DownloadItem::INTERRUPTED: | 383 case DownloadItem::INTERRUPTED: |
| 384 RemovePendingDownload(download); | 384 RemovePendingDownload(download); |
| 385 break; | 385 break; |
| 386 | 386 |
| 387 default: | 387 default: |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 DVLOG(1) << "Pending download not found" << download_id; | 621 DVLOG(1) << "Pending download not found" << download_id; |
| 622 return; | 622 return; |
| 623 } | 623 } |
| 624 DVLOG(1) << "Completing upload for download ID " << download_id; | 624 DVLOG(1) << "Completing upload for download ID " << download_id; |
| 625 DownloadItem* download_item = iter->second; | 625 DownloadItem* download_item = iter->second; |
| 626 | 626 |
| 627 UploadingUserData* upload_data = GetUploadingUserData(download_item); | 627 UploadingUserData* upload_data = GetUploadingUserData(download_item); |
| 628 DCHECK(upload_data); | 628 DCHECK(upload_data); |
| 629 | 629 |
| 630 // Take ownership of the DocumentEntry from UploadFileInfo. This is used by | 630 // Take ownership of the DocumentEntry from UploadFileInfo. This is used by |
| 631 // GDataFileSystem::AddUploadedFile() to add the entry to GDataCache after the | 631 // GDataFileSystem::AddUploadedFile() to add the entry to DriveCache after the |
| 632 // upload completes. | 632 // upload completes. |
| 633 upload_data->set_entry(upload_file_info->entry.Pass()); | 633 upload_data->set_entry(upload_file_info->entry.Pass()); |
| 634 | 634 |
| 635 // Allow the download item to complete. | 635 // Allow the download item to complete. |
| 636 upload_data->CompleteDownload(); | 636 upload_data->CompleteDownload(); |
| 637 } | 637 } |
| 638 | 638 |
| 639 void GDataDownloadObserver::MoveFileToGDataCache(DownloadItem* download) { | 639 void GDataDownloadObserver::MoveFileToDriveCache(DownloadItem* download) { |
| 640 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 640 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 641 | 641 |
| 642 UploadingUserData* upload_data = GetUploadingUserData(download); | 642 UploadingUserData* upload_data = GetUploadingUserData(download); |
| 643 if (!upload_data) { | 643 if (!upload_data) { |
| 644 NOTREACHED(); | 644 NOTREACHED(); |
| 645 return; | 645 return; |
| 646 } | 646 } |
| 647 | 647 |
| 648 // Pass ownership of the DocumentEntry object. | 648 // Pass ownership of the DocumentEntry object. |
| 649 scoped_ptr<DocumentEntry> entry = upload_data->entry_passed(); | 649 scoped_ptr<DocumentEntry> entry = upload_data->entry_passed(); |
| 650 if (!entry.get()) { | 650 if (!entry.get()) { |
| 651 NOTREACHED(); | 651 NOTREACHED(); |
| 652 return; | 652 return; |
| 653 } | 653 } |
| 654 | 654 |
| 655 if (upload_data->is_overwrite()) { | 655 if (upload_data->is_overwrite()) { |
| 656 file_system_->UpdateEntryData(upload_data->resource_id(), | 656 file_system_->UpdateEntryData(upload_data->resource_id(), |
| 657 upload_data->md5(), | 657 upload_data->md5(), |
| 658 entry.Pass(), | 658 entry.Pass(), |
| 659 download->GetTargetFilePath(), | 659 download->GetTargetFilePath(), |
| 660 base::Bind(&base::DoNothing)); | 660 base::Bind(&base::DoNothing)); |
| 661 } else { | 661 } else { |
| 662 // Move downloaded file to gdata cache. Note that |content_file_path| should | 662 // Move downloaded file to gdata cache. Note that |content_file_path| should |
| 663 // use the final target path (download->GetTargetFilePath()) when the | 663 // use the final target path (download->GetTargetFilePath()) when the |
| 664 // download item has transitioned to the DownloadItem::COMPLETE state. | 664 // download item has transitioned to the DownloadItem::COMPLETE state. |
| 665 file_system_->AddUploadedFile(UPLOAD_NEW_FILE, | 665 file_system_->AddUploadedFile(UPLOAD_NEW_FILE, |
| 666 upload_data->virtual_dir_path(), | 666 upload_data->virtual_dir_path(), |
| 667 entry.Pass(), | 667 entry.Pass(), |
| 668 download->GetTargetFilePath(), | 668 download->GetTargetFilePath(), |
| 669 GDataCache::FILE_OPERATION_MOVE, | 669 DriveCache::FILE_OPERATION_MOVE, |
| 670 base::Bind(&base::DoNothing)); | 670 base::Bind(&base::DoNothing)); |
| 671 } | 671 } |
| 672 } | 672 } |
| 673 | 673 |
| 674 } // namespace gdata | 674 } // namespace gdata |
| OLD | NEW |