| 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 "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" | 8 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" |
| 9 #include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h" | 9 #include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h" |
| 10 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 10 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 126 } |
| 127 | 127 |
| 128 // static | 128 // static |
| 129 bool GDataDownloadObserver::IsReadyToComplete(DownloadItem* download) { | 129 bool GDataDownloadObserver::IsReadyToComplete(DownloadItem* download) { |
| 130 // |download| is ready for completion (as far as GData is concerned) if: | 130 // |download| is ready for completion (as far as GData is concerned) if: |
| 131 // 1. It's not a GData download. | 131 // 1. It's not a GData download. |
| 132 // - or - | 132 // - or - |
| 133 // 2. The upload has completed. | 133 // 2. The upload has completed. |
| 134 UploadingExternalData* upload_data = GetUploadingExternalData(download); | 134 UploadingExternalData* upload_data = GetUploadingExternalData(download); |
| 135 return !IsGDataDownload(download) || | 135 return !IsGDataDownload(download) || |
| 136 (upload_data && upload_data->is_complete()); | 136 (upload_data && upload_data->is_complete()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 // static | 139 // static |
| 140 int64 GDataDownloadObserver::GetUploadedBytes(DownloadItem* download) { | 140 int64 GDataDownloadObserver::GetUploadedBytes(DownloadItem* download) { |
| 141 UploadingExternalData* upload_data = GetUploadingExternalData(download); | 141 UploadingExternalData* upload_data = GetUploadingExternalData(download); |
| 142 if (!upload_data || !upload_data->uploader()) | 142 if (!upload_data || !upload_data->uploader()) |
| 143 return 0; | 143 return 0; |
| 144 return upload_data->uploader()->GetUploadedBytes(upload_data->upload_id()); | 144 return upload_data->uploader()->GetUploadedBytes(upload_data->upload_id()); |
| 145 } | 145 } |
| 146 | 146 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 284 |
| 285 gdata_uploader_->UpdateUpload(upload_data->upload_id(), download); | 285 gdata_uploader_->UpdateUpload(upload_data->upload_id(), download); |
| 286 } | 286 } |
| 287 | 287 |
| 288 bool GDataDownloadObserver::ShouldUpload(DownloadItem* download) { | 288 bool GDataDownloadObserver::ShouldUpload(DownloadItem* download) { |
| 289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 290 | 290 |
| 291 // Upload if the item is in pending_downloads_, | 291 // Upload if the item is in pending_downloads_, |
| 292 // is complete or large enough to stream, and, | 292 // is complete or large enough to stream, and, |
| 293 // is not already being uploaded. | 293 // is not already being uploaded. |
| 294 return pending_downloads_.count(download->GetId()) != 0 && | 294 return (pending_downloads_.count(download->GetId()) != 0) && |
| 295 (download->AllDataSaved() || | 295 (download->AllDataSaved() || |
| 296 download->GetReceivedBytes() > kStreamingFileSize) && | 296 download->GetReceivedBytes() > kStreamingFileSize) && |
| 297 GetUploadingExternalData(download) == NULL; | 297 (GetUploadingExternalData(download) == NULL); |
| 298 } | 298 } |
| 299 | 299 |
| 300 scoped_ptr<UploadFileInfo> GDataDownloadObserver::CreateUploadFileInfo( | 300 scoped_ptr<UploadFileInfo> GDataDownloadObserver::CreateUploadFileInfo( |
| 301 DownloadItem* download) { | 301 DownloadItem* download) { |
| 302 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo()); | 302 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo()); |
| 303 | 303 |
| 304 // GetFullPath will be a temporary location if we're streaming. | 304 // GetFullPath will be a temporary location if we're streaming. |
| 305 upload_file_info->file_path = download->GetFullPath(); | 305 upload_file_info->file_path = download->GetFullPath(); |
| 306 upload_file_info->file_size = download->GetReceivedBytes(); | 306 upload_file_info->file_size = download->GetReceivedBytes(); |
| 307 | 307 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 333 if (iter == pending_downloads_.end()) { | 333 if (iter == pending_downloads_.end()) { |
| 334 DVLOG(1) << "Pending download not found" << download_id; | 334 DVLOG(1) << "Pending download not found" << download_id; |
| 335 return; | 335 return; |
| 336 } | 336 } |
| 337 DVLOG(1) << "Completing upload for download ID " << download_id; | 337 DVLOG(1) << "Completing upload for download ID " << download_id; |
| 338 DownloadItem* download = iter->second; | 338 DownloadItem* download = iter->second; |
| 339 UploadingExternalData* upload_data = GetUploadingExternalData(download); | 339 UploadingExternalData* upload_data = GetUploadingExternalData(download); |
| 340 DCHECK(upload_data); | 340 DCHECK(upload_data); |
| 341 upload_data->MarkAsComplete(); | 341 upload_data->MarkAsComplete(); |
| 342 download->MaybeCompleteDownload(); | 342 download->MaybeCompleteDownload(); |
| 343 // MaybeCompleteDownload() only works for non-SavePackage downloads. |
| 344 // SavePackage::Finish() is the SavePackage equivalent of |
| 345 // MaybeCompleteDownload(). MHTML SavePackages may upload to GData (see |
| 346 // SavePackageFilePickerChromeOS), so MHTML SavePackages use |
| 347 // OnDownloadUpdated() to wait for the upload to complete before calling |
| 348 // Finish(). Call UpdateObservers() manually now in case this download is an |
| 349 // MHTML SavePackage. |
| 350 download->UpdateObservers(); |
| 343 } | 351 } |
| 344 | 352 |
| 345 } // namespace gdata | 353 } // namespace gdata |
| OLD | NEW |