Chromium Code Reviews| 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 3cb89fb37a46dfe357cda973f292628911e1781d..32840f1cee124d24486fb745c84f4890a58f4f52 100644 |
| --- a/chrome/browser/chromeos/gdata/gdata_download_observer.cc |
| +++ b/chrome/browser/chromeos/gdata/gdata_download_observer.cc |
| @@ -34,7 +34,19 @@ 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) { |
| + if (!is_complete_) |
| + complete_cb_ = cb; |
| + } |
| + |
| + void MarkAsComplete() { |
|
asanka
2012/05/01 15:54:10
Nit: Perhaps rename to something like CompleteDown
benjhayden
2012/05/01 18:02:52
Done.
|
| + is_complete_ = true; |
| + if (!complete_cb_.is_null()) { |
| + complete_cb_.Run(); |
| + complete_cb_.Reset(); |
| + } |
| + } |
| int upload_id() const { return upload_id_; } |
| bool is_complete() const { return is_complete_; } |
| @@ -42,6 +54,7 @@ class UploadingExternalData : public DownloadItem::ExternalData { |
| private: |
| GDataUploader* uploader_; |
| + base::Closure complete_cb_; |
| int upload_id_; |
| bool is_complete_; |
| }; |
| @@ -126,14 +139,20 @@ bool GDataDownloadObserver::IsGDataDownload(DownloadItem* download) { |
| } |
| // static |
| -bool GDataDownloadObserver::IsReadyToComplete(DownloadItem* download) { |
| +bool GDataDownloadObserver::IsReadyToComplete( |
| + DownloadItem* download, |
| + const base::Closure& maybe_complete_download) { |
|
asanka
2012/05/01 15:54:10
Nit: Just call it complete_cb or something generic
benjhayden
2012/05/01 18:02:52
Done.
|
| // |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. |
| UploadingExternalData* upload_data = GetUploadingExternalData(download); |
| - return !IsGDataDownload(download) || |
| - (upload_data && upload_data->is_complete()); |
| + if (!IsGDataDownload(download) || |
| + (upload_data && upload_data->is_complete())) |
|
asanka
2012/05/01 15:54:10
Could upload_data be NULL at this point? It should
benjhayden
2012/05/01 18:02:52
Done.
|
| + return true; |
| + if (!maybe_complete_download.is_null()) |
| + upload_data->set_complete_cb(maybe_complete_download); |
| + return false; |
| } |
| // static |
| @@ -335,11 +354,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(); |
| } |
| } // namespace gdata |