| Index: chrome/browser/chromeos/gdata/gdata_download_observer.cc
|
| diff --git a/chrome/browser/chromeos/gdata/gdata_download_observer.cc b/chrome/browser/chromeos/gdata/gdata_download_observer.cc
|
| index b566a009a4a64278e5de1fce5b393a4291bebe61..903c058dc6be3b88604ba8f49526eb651abadcbc 100644
|
| --- a/chrome/browser/chromeos/gdata/gdata_download_observer.cc
|
| +++ b/chrome/browser/chromeos/gdata/gdata_download_observer.cc
|
| @@ -34,7 +34,20 @@ class UploadingExternalData : public DownloadItem::ExternalData {
|
| }
|
| virtual ~UploadingExternalData() {}
|
|
|
| - void MarkAsComplete() { is_complete_ = true; }
|
| + // |cb| will be called when this Upload is marked as complete.
|
| + void set_complete_callback(const base::Closure& cb) {
|
| + // Be very careful to avoid calling cb twice, or more than one cb!
|
| + if (!is_complete_)
|
| + complete_callback_ = cb;
|
| + }
|
| +
|
| + void CompleteDownload() {
|
| + is_complete_ = true;
|
| + if (!complete_callback_.is_null()) {
|
| + complete_callback_.Run();
|
| + complete_callback_.Reset();
|
| + }
|
| + }
|
|
|
| int upload_id() const { return upload_id_; }
|
| bool is_complete() const { return is_complete_; }
|
| @@ -42,6 +55,7 @@ class UploadingExternalData : public DownloadItem::ExternalData {
|
|
|
| private:
|
| GDataUploader* uploader_;
|
| + base::Closure complete_callback_;
|
| int upload_id_;
|
| bool is_complete_;
|
| };
|
| @@ -126,14 +140,21 @@ bool GDataDownloadObserver::IsGDataDownload(DownloadItem* download) {
|
| }
|
|
|
| // static
|
| -bool GDataDownloadObserver::IsReadyToComplete(DownloadItem* download) {
|
| +bool GDataDownloadObserver::IsReadyToComplete(
|
| + DownloadItem* download,
|
| + const base::Closure& complete_callback) {
|
| // |download| is ready for completion (as far as GData is concerned) if:
|
| // 1. It's not a GData download.
|
| // - or -
|
| // 2. The upload has completed.
|
| + if (!IsGDataDownload(download))
|
| + return true;
|
| UploadingExternalData* upload_data = GetUploadingExternalData(download);
|
| - return !IsGDataDownload(download) ||
|
| - (upload_data && upload_data->is_complete());
|
| + DCHECK(upload_data);
|
| + if (upload_data->is_complete())
|
| + return true;
|
| + upload_data->set_complete_callback(complete_callback);
|
| + return false;
|
| }
|
|
|
| // static
|
| @@ -335,19 +356,10 @@ void GDataDownloadObserver::OnUploadComplete(int32 download_id,
|
| return;
|
| }
|
| DVLOG(1) << "Completing upload for download ID " << download_id;
|
| - DownloadItem* download = iter->second;
|
| - UploadingExternalData* upload_data = GetUploadingExternalData(download);
|
| + DownloadItem* download_item = iter->second;
|
| + UploadingExternalData* upload_data = GetUploadingExternalData(download_item);
|
| DCHECK(upload_data);
|
| - upload_data->MarkAsComplete();
|
| - download->MaybeCompleteDownload();
|
| - // MaybeCompleteDownload() only works for non-SavePackage downloads.
|
| - // SavePackage::Finish() is the SavePackage equivalent of
|
| - // MaybeCompleteDownload(). MHTML SavePackages may upload to GData (see
|
| - // SavePackageFilePickerChromeOS), so MHTML SavePackages use
|
| - // OnDownloadUpdated() to wait for the upload to complete before calling
|
| - // Finish(). Call UpdateObservers() manually now in case this download is an
|
| - // MHTML SavePackage.
|
| - download->UpdateObservers();
|
| + upload_data->CompleteDownload();
|
| }
|
|
|
| } // namespace gdata
|
|
|