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