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/callback.h" | 7 #include "base/callback.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "chrome/browser/chromeos/gdata/gdata.pb.h" | 9 #include "chrome/browser/chromeos/gdata/gdata.pb.h" |
10 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" | 10 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 break; | 356 break; |
357 | 357 |
358 case DownloadItem::COMPLETE: | 358 case DownloadItem::COMPLETE: |
359 UploadDownloadItem(download); | 359 UploadDownloadItem(download); |
360 MoveFileToGDataCache(download); | 360 MoveFileToGDataCache(download); |
361 RemovePendingDownload(download); | 361 RemovePendingDownload(download); |
362 break; | 362 break; |
363 | 363 |
364 // TODO(achuith): Stop the pending upload and delete the file. | 364 // TODO(achuith): Stop the pending upload and delete the file. |
365 case DownloadItem::CANCELLED: | 365 case DownloadItem::CANCELLED: |
| 366 case DownloadItem::REMOVING: |
366 case DownloadItem::INTERRUPTED: | 367 case DownloadItem::INTERRUPTED: |
367 RemovePendingDownload(download); | 368 RemovePendingDownload(download); |
368 break; | 369 break; |
369 | 370 |
370 default: | 371 default: |
371 NOTREACHED(); | 372 NOTREACHED(); |
372 } | 373 } |
373 | 374 |
374 DVLOG(1) << "Number of pending downloads=" << pending_downloads_.size(); | 375 DVLOG(1) << "Number of pending downloads=" << pending_downloads_.size(); |
375 } | 376 } |
376 | 377 |
377 void GDataDownloadObserver::OnDownloadDestroyed(DownloadItem* download) { | |
378 RemovePendingDownload(download); | |
379 } | |
380 | |
381 void GDataDownloadObserver::AddPendingDownload(DownloadItem* download) { | 378 void GDataDownloadObserver::AddPendingDownload(DownloadItem* download) { |
382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
383 | 380 |
384 // Add ourself as an observer of this download if we've never seen it before. | 381 // Add ourself as an observer of this download if we've never seen it before. |
385 if (pending_downloads_.count(download->GetId()) == 0) { | 382 if (pending_downloads_.count(download->GetId()) == 0) { |
386 pending_downloads_[download->GetId()] = download; | 383 pending_downloads_[download->GetId()] = download; |
387 download->AddObserver(this); | 384 download->AddObserver(this); |
388 DVLOG(1) << "new download total bytes=" << download->GetTotalBytes() | 385 DVLOG(1) << "new download total bytes=" << download->GetTotalBytes() |
389 << ", full path=" << download->GetFullPath().value() | 386 << ", full path=" << download->GetFullPath().value() |
390 << ", mime type=" << download->GetMimeType(); | 387 << ", mime type=" << download->GetMimeType(); |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 // use the final target path when the download item is in COMPLETE state. | 570 // use the final target path when the download item is in COMPLETE state. |
574 file_system_->AddUploadedFile(UPLOAD_NEW_FILE, | 571 file_system_->AddUploadedFile(UPLOAD_NEW_FILE, |
575 upload_data->virtual_dir_path(), | 572 upload_data->virtual_dir_path(), |
576 entry.Pass(), | 573 entry.Pass(), |
577 download->GetTargetFilePath(), | 574 download->GetTargetFilePath(), |
578 GDataCache::FILE_OPERATION_MOVE, | 575 GDataCache::FILE_OPERATION_MOVE, |
579 base::Bind(&base::DoNothing)); | 576 base::Bind(&base::DoNothing)); |
580 } | 577 } |
581 | 578 |
582 } // namespace gdata | 579 } // namespace gdata |
OLD | NEW |