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