| 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 "base/supports_user_data.h" |
| 9 #include "chrome/browser/chromeos/gdata/gdata.pb.h" | 10 #include "chrome/browser/chromeos/gdata/gdata.pb.h" |
| 10 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" | 11 #include "chrome/browser/chromeos/gdata/gdata_documents_service.h" |
| 11 #include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h" | 12 #include "chrome/browser/chromeos/gdata/gdata_file_system_interface.h" |
| 12 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" | 13 #include "chrome/browser/chromeos/gdata/gdata_system_service.h" |
| 13 #include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h" | 14 #include "chrome/browser/chromeos/gdata/gdata_upload_file_info.h" |
| 14 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" | 15 #include "chrome/browser/chromeos/gdata/gdata_uploader.h" |
| 15 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 16 #include "chrome/browser/chromeos/gdata/gdata_util.h" |
| 16 #include "chrome/browser/download/download_completion_blocker.h" | 17 #include "chrome/browser/download/download_completion_blocker.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
| 18 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
| 19 | 20 |
| 20 using content::BrowserThread; | 21 using content::BrowserThread; |
| 21 using content::DownloadManager; | 22 using content::DownloadManager; |
| 22 using content::DownloadItem; | 23 using content::DownloadItem; |
| 23 | 24 |
| 24 namespace gdata { | 25 namespace gdata { |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // Threshold file size after which we stream the file. | 28 // Threshold file size after which we stream the file. |
| 28 const int64 kStreamingFileSize = 1 << 20; // 1MB | 29 const int64 kStreamingFileSize = 1 << 20; // 1MB |
| 29 | 30 |
| 30 // Keys for DownloadItem::ExternalData. | 31 // Keys for base::SupportsUserData::Data. |
| 31 const char kUploadingKey[] = "Uploading"; | 32 const char kUploadingKey[] = "Uploading"; |
| 32 const char kGDataPathKey[] = "GDataPath"; | 33 const char kGDataPathKey[] = "GDataPath"; |
| 33 | 34 |
| 34 // External Data stored in DownloadItem for ongoing uploads. | 35 // User Data stored in DownloadItem for ongoing uploads. |
| 35 class UploadingExternalData : public DownloadCompletionBlocker { | 36 class UploadingUserData : public DownloadCompletionBlocker { |
| 36 public: | 37 public: |
| 37 explicit UploadingExternalData(GDataUploader* uploader) | 38 explicit UploadingUserData(GDataUploader* uploader) |
| 38 : uploader_(uploader), | 39 : uploader_(uploader), |
| 39 upload_id_(-1) { | 40 upload_id_(-1) { |
| 40 } | 41 } |
| 41 virtual ~UploadingExternalData() {} | 42 virtual ~UploadingUserData() {} |
| 42 | 43 |
| 43 GDataUploader* uploader() { return uploader_; } | 44 GDataUploader* uploader() { return uploader_; } |
| 44 void set_upload_id(int upload_id) { upload_id_ = upload_id; } | 45 void set_upload_id(int upload_id) { upload_id_ = upload_id; } |
| 45 int upload_id() const { return upload_id_; } | 46 int upload_id() const { return upload_id_; } |
| 46 void set_virtual_dir_path(const FilePath& path) { virtual_dir_path_ = path; } | 47 void set_virtual_dir_path(const FilePath& path) { virtual_dir_path_ = path; } |
| 47 const FilePath& virtual_dir_path() const { return virtual_dir_path_; } | 48 const FilePath& virtual_dir_path() const { return virtual_dir_path_; } |
| 48 void set_entry(scoped_ptr<DocumentEntry> entry) { entry_ = entry.Pass(); } | 49 void set_entry(scoped_ptr<DocumentEntry> entry) { entry_ = entry.Pass(); } |
| 49 scoped_ptr<DocumentEntry> entry_passed() { return entry_.Pass(); } | 50 scoped_ptr<DocumentEntry> entry_passed() { return entry_.Pass(); } |
| 50 | 51 |
| 51 private: | 52 private: |
| 52 GDataUploader* uploader_; | 53 GDataUploader* uploader_; |
| 53 int upload_id_; | 54 int upload_id_; |
| 54 FilePath virtual_dir_path_; | 55 FilePath virtual_dir_path_; |
| 55 scoped_ptr<DocumentEntry> entry_; | 56 scoped_ptr<DocumentEntry> entry_; |
| 56 | 57 |
| 57 DISALLOW_COPY_AND_ASSIGN(UploadingExternalData); | 58 DISALLOW_COPY_AND_ASSIGN(UploadingUserData); |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 // External Data stored in DownloadItem for gdata path. | 61 // User Data stored in DownloadItem for gdata path. |
| 61 class GDataExternalData : public DownloadItem::ExternalData { | 62 class GDataUserData : public base::SupportsUserData::Data { |
| 62 public: | 63 public: |
| 63 explicit GDataExternalData(const FilePath& path) : file_path_(path) {} | 64 explicit GDataUserData(const FilePath& path) : file_path_(path) {} |
| 64 virtual ~GDataExternalData() {} | 65 virtual ~GDataUserData() {} |
| 65 | 66 |
| 66 const FilePath& file_path() const { return file_path_; } | 67 const FilePath& file_path() const { return file_path_; } |
| 67 | 68 |
| 68 private: | 69 private: |
| 69 FilePath file_path_; | 70 FilePath file_path_; |
| 70 }; | 71 }; |
| 71 | 72 |
| 72 // Extracts UploadingExternalData* from |download|. | 73 // Extracts UploadingUserData* from |download|. |
| 73 UploadingExternalData* GetUploadingExternalData(DownloadItem* download) { | 74 UploadingUserData* GetUploadingUserData(DownloadItem* download) { |
| 74 return static_cast<UploadingExternalData*>( | 75 return static_cast<UploadingUserData*>( |
| 75 download->GetExternalData(&kUploadingKey)); | 76 download->GetUserData(&kUploadingKey)); |
| 76 } | 77 } |
| 77 | 78 |
| 78 // Extracts GDataExternalData* from |download|. | 79 // Extracts GDataUserData* from |download|. |
| 79 GDataExternalData* GetGDataExternalData(DownloadItem* download) { | 80 GDataUserData* GetGDataUserData(DownloadItem* download) { |
| 80 return static_cast<GDataExternalData*>( | 81 return static_cast<GDataUserData*>( |
| 81 download->GetExternalData(&kGDataPathKey)); | 82 download->GetUserData(&kGDataPathKey)); |
| 82 } | 83 } |
| 83 | 84 |
| 84 void RunSubstituteGDataDownloadCallback( | 85 void RunSubstituteGDataDownloadCallback( |
| 85 const GDataDownloadObserver::SubstituteGDataDownloadPathCallback& callback, | 86 const GDataDownloadObserver::SubstituteGDataDownloadPathCallback& callback, |
| 86 const FilePath* file_path) { | 87 const FilePath* file_path) { |
| 87 callback.Run(*file_path); | 88 callback.Run(*file_path); |
| 88 } | 89 } |
| 89 | 90 |
| 90 gdata::GDataSystemService* GetSystemService(Profile* profile) { | 91 gdata::GDataSystemService* GetSystemService(Profile* profile) { |
| 91 gdata::GDataSystemService* system_service = | 92 gdata::GDataSystemService* system_service = |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 } | 227 } |
| 227 } | 228 } |
| 228 | 229 |
| 229 // static | 230 // static |
| 230 void GDataDownloadObserver::SetDownloadParams(const FilePath& gdata_path, | 231 void GDataDownloadObserver::SetDownloadParams(const FilePath& gdata_path, |
| 231 DownloadItem* download) { | 232 DownloadItem* download) { |
| 232 if (!download) | 233 if (!download) |
| 233 return; | 234 return; |
| 234 | 235 |
| 235 if (gdata::util::IsUnderGDataMountPoint(gdata_path)) { | 236 if (gdata::util::IsUnderGDataMountPoint(gdata_path)) { |
| 236 download->SetExternalData(&kGDataPathKey, | 237 download->SetUserData(&kGDataPathKey, |
| 237 new GDataExternalData(gdata_path)); | 238 new GDataUserData(gdata_path)); |
| 238 download->SetDisplayName(gdata_path.BaseName()); | 239 download->SetDisplayName(gdata_path.BaseName()); |
| 239 download->SetIsTemporary(true); | 240 download->SetIsTemporary(true); |
| 240 } else if (IsGDataDownload(download)) { | 241 } else if (IsGDataDownload(download)) { |
| 241 // This may have been previously set if the default download folder is | 242 // This may have been previously set if the default download folder is |
| 242 // /drive, and the user has now changed the download target to a local | 243 // /drive, and the user has now changed the download target to a local |
| 243 // folder. | 244 // folder. |
| 244 download->SetExternalData(&kGDataPathKey, NULL); | 245 download->SetUserData(&kGDataPathKey, NULL); |
| 245 download->SetDisplayName(gdata_path); | 246 download->SetDisplayName(gdata_path); |
| 246 // TODO(achuith): This is not quite right. | 247 // TODO(achuith): This is not quite right. |
| 247 download->SetIsTemporary(false); | 248 download->SetIsTemporary(false); |
| 248 } | 249 } |
| 249 } | 250 } |
| 250 | 251 |
| 251 // static | 252 // static |
| 252 FilePath GDataDownloadObserver::GetGDataPath(DownloadItem* download) { | 253 FilePath GDataDownloadObserver::GetGDataPath(DownloadItem* download) { |
| 253 GDataExternalData* data = GetGDataExternalData(download); | 254 GDataUserData* data = GetGDataUserData(download); |
| 254 // If data is NULL, we've somehow lost the gdata path selected by the file | 255 // If data is NULL, we've somehow lost the gdata path selected by the file |
| 255 // picker. | 256 // picker. |
| 256 DCHECK(data); | 257 DCHECK(data); |
| 257 return data ? util::ExtractGDataPath(data->file_path()) : FilePath(); | 258 return data ? util::ExtractGDataPath(data->file_path()) : FilePath(); |
| 258 } | 259 } |
| 259 | 260 |
| 260 // static | 261 // static |
| 261 bool GDataDownloadObserver::IsGDataDownload(DownloadItem* download) { | 262 bool GDataDownloadObserver::IsGDataDownload(DownloadItem* download) { |
| 262 // We use the existence of the GDataExternalData object in download as a | 263 // We use the existence of the GDataUserData object in download as a |
| 263 // signal that this is a GDataDownload. | 264 // signal that this is a GDataDownload. |
| 264 return !!GetGDataExternalData(download); | 265 return !!GetGDataUserData(download); |
| 265 } | 266 } |
| 266 | 267 |
| 267 // static | 268 // static |
| 268 bool GDataDownloadObserver::IsReadyToComplete( | 269 bool GDataDownloadObserver::IsReadyToComplete( |
| 269 DownloadItem* download, | 270 DownloadItem* download, |
| 270 const base::Closure& complete_callback) { | 271 const base::Closure& complete_callback) { |
| 271 DVLOG(1) << "GDataDownloadObserver::IsReadyToComplete"; | 272 DVLOG(1) << "GDataDownloadObserver::IsReadyToComplete"; |
| 272 // |download| is ready for completion (as far as GData is concerned) if: | 273 // |download| is ready for completion (as far as GData is concerned) if: |
| 273 // 1. It's not a GData download. | 274 // 1. It's not a GData download. |
| 274 // - or - | 275 // - or - |
| 275 // 2. The upload has completed. | 276 // 2. The upload has completed. |
| 276 if (!IsGDataDownload(download)) | 277 if (!IsGDataDownload(download)) |
| 277 return true; | 278 return true; |
| 278 UploadingExternalData* upload_data = GetUploadingExternalData(download); | 279 UploadingUserData* upload_data = GetUploadingUserData(download); |
| 279 DCHECK(upload_data); | 280 DCHECK(upload_data); |
| 280 if (upload_data->is_complete()) | 281 if (upload_data->is_complete()) |
| 281 return true; | 282 return true; |
| 282 upload_data->set_callback(complete_callback); | 283 upload_data->set_callback(complete_callback); |
| 283 return false; | 284 return false; |
| 284 } | 285 } |
| 285 | 286 |
| 286 // static | 287 // static |
| 287 int64 GDataDownloadObserver::GetUploadedBytes(DownloadItem* download) { | 288 int64 GDataDownloadObserver::GetUploadedBytes(DownloadItem* download) { |
| 288 UploadingExternalData* upload_data = GetUploadingExternalData(download); | 289 UploadingUserData* upload_data = GetUploadingUserData(download); |
| 289 if (!upload_data || !upload_data->uploader()) | 290 if (!upload_data || !upload_data->uploader()) |
| 290 return 0; | 291 return 0; |
| 291 return upload_data->uploader()->GetUploadedBytes(upload_data->upload_id()); | 292 return upload_data->uploader()->GetUploadedBytes(upload_data->upload_id()); |
| 292 } | 293 } |
| 293 | 294 |
| 294 // static | 295 // static |
| 295 int GDataDownloadObserver::PercentComplete(DownloadItem* download) { | 296 int GDataDownloadObserver::PercentComplete(DownloadItem* download) { |
| 296 // Progress is unknown until the upload starts. | 297 // Progress is unknown until the upload starts. |
| 297 if (!GetUploadingExternalData(download)) | 298 if (!GetUploadingUserData(download)) |
| 298 return -1; | 299 return -1; |
| 299 int64 complete = GetUploadedBytes(download); | 300 int64 complete = GetUploadedBytes(download); |
| 300 // Once AllDataSaved() is true, we can use the GetReceivedBytes() as the total | 301 // Once AllDataSaved() is true, we can use the GetReceivedBytes() as the total |
| 301 // size. GetTotalBytes() may be set to 0 if there was a mismatch between the | 302 // size. GetTotalBytes() may be set to 0 if there was a mismatch between the |
| 302 // count of received bytes and the size of the download as given by the | 303 // count of received bytes and the size of the download as given by the |
| 303 // Content-Length header. | 304 // Content-Length header. |
| 304 int64 total = (download->AllDataSaved() ? download->GetReceivedBytes() : | 305 int64 total = (download->AllDataSaved() ? download->GetReceivedBytes() : |
| 305 download->GetTotalBytes()); | 306 download->GetTotalBytes()); |
| 306 DCHECK(total <= 0 || complete < total); | 307 DCHECK(total <= 0 || complete < total); |
| 307 if (total > 0) | 308 if (total > 0) |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 DCHECK(!download->IsInProgress()); | 394 DCHECK(!download->IsInProgress()); |
| 394 | 395 |
| 395 DownloadMap::iterator it = pending_downloads_.find(download->GetId()); | 396 DownloadMap::iterator it = pending_downloads_.find(download->GetId()); |
| 396 if (it != pending_downloads_.end()) { | 397 if (it != pending_downloads_.end()) { |
| 397 DetachFromDownload(download); | 398 DetachFromDownload(download); |
| 398 pending_downloads_.erase(it); | 399 pending_downloads_.erase(it); |
| 399 } | 400 } |
| 400 } | 401 } |
| 401 | 402 |
| 402 void GDataDownloadObserver::DetachFromDownload(DownloadItem* download) { | 403 void GDataDownloadObserver::DetachFromDownload(DownloadItem* download) { |
| 403 download->SetExternalData(&kUploadingKey, NULL); | 404 download->SetUserData(&kUploadingKey, NULL); |
| 404 download->SetExternalData(&kGDataPathKey, NULL); | 405 download->SetUserData(&kGDataPathKey, NULL); |
| 405 download->RemoveObserver(this); | 406 download->RemoveObserver(this); |
| 406 } | 407 } |
| 407 | 408 |
| 408 void GDataDownloadObserver::UploadDownloadItem(DownloadItem* download) { | 409 void GDataDownloadObserver::UploadDownloadItem(DownloadItem* download) { |
| 409 // Update metadata of ongoing upload. | 410 // Update metadata of ongoing upload. |
| 410 UpdateUpload(download); | 411 UpdateUpload(download); |
| 411 | 412 |
| 412 if (!ShouldUpload(download)) | 413 if (!ShouldUpload(download)) |
| 413 return; | 414 return; |
| 414 | 415 |
| 415 // Initialize uploading external data. | 416 // Initialize uploading userdata. |
| 416 download->SetExternalData(&kUploadingKey, | 417 download->SetUserData(&kUploadingKey, |
| 417 new UploadingExternalData(gdata_uploader_)); | 418 new UploadingUserData(gdata_uploader_)); |
| 418 | 419 |
| 419 // Create UploadFileInfo structure for the download item. | 420 // Create UploadFileInfo structure for the download item. |
| 420 CreateUploadFileInfo(download); | 421 CreateUploadFileInfo(download); |
| 421 } | 422 } |
| 422 | 423 |
| 423 void GDataDownloadObserver::UpdateUpload(DownloadItem* download) { | 424 void GDataDownloadObserver::UpdateUpload(DownloadItem* download) { |
| 424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 425 | 426 |
| 426 UploadingExternalData* upload_data = GetUploadingExternalData(download); | 427 UploadingUserData* upload_data = GetUploadingUserData(download); |
| 427 if (!upload_data) { | 428 if (!upload_data) { |
| 428 DVLOG(1) << "No UploadingExternalData for download " << download->GetId(); | 429 DVLOG(1) << "No UploadingUserData for download " << download->GetId(); |
| 429 return; | 430 return; |
| 430 } | 431 } |
| 431 | 432 |
| 432 gdata_uploader_->UpdateUpload(upload_data->upload_id(), download); | 433 gdata_uploader_->UpdateUpload(upload_data->upload_id(), download); |
| 433 } | 434 } |
| 434 | 435 |
| 435 bool GDataDownloadObserver::ShouldUpload(DownloadItem* download) { | 436 bool GDataDownloadObserver::ShouldUpload(DownloadItem* download) { |
| 436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 437 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 437 | 438 |
| 438 // Upload if the item is in pending_downloads_, | 439 // Upload if the item is in pending_downloads_, |
| 439 // is complete or large enough to stream, and, | 440 // is complete or large enough to stream, and, |
| 440 // is not already being uploaded. | 441 // is not already being uploaded. |
| 441 return (pending_downloads_.count(download->GetId()) != 0) && | 442 return (pending_downloads_.count(download->GetId()) != 0) && |
| 442 (download->AllDataSaved() || | 443 (download->AllDataSaved() || |
| 443 download->GetReceivedBytes() > kStreamingFileSize) && | 444 download->GetReceivedBytes() > kStreamingFileSize) && |
| 444 (GetUploadingExternalData(download) == NULL); | 445 (GetUploadingUserData(download) == NULL); |
| 445 } | 446 } |
| 446 | 447 |
| 447 void GDataDownloadObserver::CreateUploadFileInfo(DownloadItem* download) { | 448 void GDataDownloadObserver::CreateUploadFileInfo(DownloadItem* download) { |
| 448 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 449 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 449 | 450 |
| 450 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo()); | 451 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo()); |
| 451 | 452 |
| 452 // GetFullPath will be a temporary location if we're streaming. | 453 // GetFullPath will be a temporary location if we're streaming. |
| 453 upload_file_info->file_path = download->GetFullPath(); | 454 upload_file_info->file_path = download->GetFullPath(); |
| 454 upload_file_info->file_size = download->GetReceivedBytes(); | 455 upload_file_info->file_size = download->GetReceivedBytes(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 | 506 |
| 506 // Look up the DownloadItem for the |download_id|. | 507 // Look up the DownloadItem for the |download_id|. |
| 507 DownloadMap::iterator iter = pending_downloads_.find(download_id); | 508 DownloadMap::iterator iter = pending_downloads_.find(download_id); |
| 508 if (iter == pending_downloads_.end()) { | 509 if (iter == pending_downloads_.end()) { |
| 509 DVLOG(1) << "Pending download not found" << download_id; | 510 DVLOG(1) << "Pending download not found" << download_id; |
| 510 return; | 511 return; |
| 511 } | 512 } |
| 512 DVLOG(1) << "Starting upload for download ID " << download_id; | 513 DVLOG(1) << "Starting upload for download ID " << download_id; |
| 513 DownloadItem* download_item = iter->second; | 514 DownloadItem* download_item = iter->second; |
| 514 | 515 |
| 515 UploadingExternalData* upload_data = GetUploadingExternalData(download_item); | 516 UploadingUserData* upload_data = GetUploadingUserData(download_item); |
| 516 DCHECK(upload_data); | 517 DCHECK(upload_data); |
| 517 upload_data->set_virtual_dir_path(upload_file_info->gdata_path.DirName()); | 518 upload_data->set_virtual_dir_path(upload_file_info->gdata_path.DirName()); |
| 518 | 519 |
| 519 // Start upload and save the upload id for future reference. | 520 // Start upload and save the upload id for future reference. |
| 520 const int upload_id = gdata_uploader_->UploadNewFile(upload_file_info.Pass()); | 521 const int upload_id = gdata_uploader_->UploadNewFile(upload_file_info.Pass()); |
| 521 upload_data->set_upload_id(upload_id); | 522 upload_data->set_upload_id(upload_id); |
| 522 } | 523 } |
| 523 | 524 |
| 524 void GDataDownloadObserver::OnUploadComplete( | 525 void GDataDownloadObserver::OnUploadComplete( |
| 525 int32 download_id, | 526 int32 download_id, |
| 526 GDataFileError error, | 527 GDataFileError error, |
| 527 scoped_ptr<UploadFileInfo> upload_file_info) { | 528 scoped_ptr<UploadFileInfo> upload_file_info) { |
| 528 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 529 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 529 DCHECK(upload_file_info.get()); | 530 DCHECK(upload_file_info.get()); |
| 530 DCHECK(upload_file_info->entry.get()); | 531 DCHECK(upload_file_info->entry.get()); |
| 531 | 532 |
| 532 // Look up the DownloadItem for the |download_id|. | 533 // Look up the DownloadItem for the |download_id|. |
| 533 DownloadMap::iterator iter = pending_downloads_.find(download_id); | 534 DownloadMap::iterator iter = pending_downloads_.find(download_id); |
| 534 if (iter == pending_downloads_.end()) { | 535 if (iter == pending_downloads_.end()) { |
| 535 DVLOG(1) << "Pending download not found" << download_id; | 536 DVLOG(1) << "Pending download not found" << download_id; |
| 536 return; | 537 return; |
| 537 } | 538 } |
| 538 DVLOG(1) << "Completing upload for download ID " << download_id; | 539 DVLOG(1) << "Completing upload for download ID " << download_id; |
| 539 DownloadItem* download_item = iter->second; | 540 DownloadItem* download_item = iter->second; |
| 540 | 541 |
| 541 UploadingExternalData* upload_data = GetUploadingExternalData(download_item); | 542 UploadingUserData* upload_data = GetUploadingUserData(download_item); |
| 542 DCHECK(upload_data); | 543 DCHECK(upload_data); |
| 543 | 544 |
| 544 // Take ownership of the DocumentEntry from UploadFileInfo. This is used by | 545 // Take ownership of the DocumentEntry from UploadFileInfo. This is used by |
| 545 // GDataFileSystem::AddUploadedFile() to add the entry to GDataCache after the | 546 // GDataFileSystem::AddUploadedFile() to add the entry to GDataCache after the |
| 546 // upload completes. | 547 // upload completes. |
| 547 upload_data->set_entry(upload_file_info->entry.Pass()); | 548 upload_data->set_entry(upload_file_info->entry.Pass()); |
| 548 | 549 |
| 549 // Allow the download item to complete. | 550 // Allow the download item to complete. |
| 550 upload_data->CompleteDownload(); | 551 upload_data->CompleteDownload(); |
| 551 } | 552 } |
| 552 | 553 |
| 553 void GDataDownloadObserver::MoveFileToGDataCache(DownloadItem* download) { | 554 void GDataDownloadObserver::MoveFileToGDataCache(DownloadItem* download) { |
| 554 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 555 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 555 | 556 |
| 556 UploadingExternalData* upload_data = GetUploadingExternalData(download); | 557 UploadingUserData* upload_data = GetUploadingUserData(download); |
| 557 if (!upload_data) { | 558 if (!upload_data) { |
| 558 NOTREACHED(); | 559 NOTREACHED(); |
| 559 return; | 560 return; |
| 560 } | 561 } |
| 561 | 562 |
| 562 // Pass ownership of the DocumentEntry object to AddUploadedFile(). | 563 // Pass ownership of the DocumentEntry object to AddUploadedFile(). |
| 563 scoped_ptr<DocumentEntry> entry = upload_data->entry_passed(); | 564 scoped_ptr<DocumentEntry> entry = upload_data->entry_passed(); |
| 564 if (!entry.get()) { | 565 if (!entry.get()) { |
| 565 NOTREACHED(); | 566 NOTREACHED(); |
| 566 return; | 567 return; |
| 567 } | 568 } |
| 568 | 569 |
| 569 // Move downloaded file to gdata cache. Note that |content_file_path| should | 570 // Move downloaded file to gdata cache. Note that |content_file_path| should |
| 570 // use the final target path when the download item is in COMPLETE state. | 571 // use the final target path when the download item is in COMPLETE state. |
| 571 file_system_->AddUploadedFile(UPLOAD_NEW_FILE, | 572 file_system_->AddUploadedFile(UPLOAD_NEW_FILE, |
| 572 upload_data->virtual_dir_path(), | 573 upload_data->virtual_dir_path(), |
| 573 entry.Pass(), | 574 entry.Pass(), |
| 574 download->GetTargetFilePath(), | 575 download->GetTargetFilePath(), |
| 575 GDataCache::FILE_OPERATION_MOVE, | 576 GDataCache::FILE_OPERATION_MOVE, |
| 576 base::Bind(&base::DoNothing)); | 577 base::Bind(&base::DoNothing)); |
| 577 } | 578 } |
| 578 | 579 |
| 579 } // namespace gdata | 580 } // namespace gdata |
| OLD | NEW |