Chromium Code Reviews| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 private: | 51 private: |
| 52 GDataUploader* uploader_; | 52 GDataUploader* uploader_; |
| 53 int upload_id_; | 53 int upload_id_; |
| 54 FilePath virtual_dir_path_; | 54 FilePath virtual_dir_path_; |
| 55 scoped_ptr<DocumentEntry> entry_; | 55 scoped_ptr<DocumentEntry> entry_; |
| 56 | 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(UploadingExternalData); | 57 DISALLOW_COPY_AND_ASSIGN(UploadingExternalData); |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 // External Data stored in DownloadItem for gdata path. | 60 // External Data stored in DownloadItem for gdata path. |
| 61 class GDataExternalData : public DownloadItem::ExternalData { | 61 class GDataExternalData : public base::SupportsUserData::Data { |
|
achuithb
2012/08/07 17:43:27
Shouldn't we be including base/supports_user_data.
benjhayden
2012/08/07 18:24:34
Done.
| |
| 62 public: | 62 public: |
| 63 explicit GDataExternalData(const FilePath& path) : file_path_(path) {} | 63 explicit GDataExternalData(const FilePath& path) : file_path_(path) {} |
| 64 virtual ~GDataExternalData() {} | 64 virtual ~GDataExternalData() {} |
| 65 | 65 |
| 66 const FilePath& file_path() const { return file_path_; } | 66 const FilePath& file_path() const { return file_path_; } |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 FilePath file_path_; | 69 FilePath file_path_; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 // Extracts UploadingExternalData* from |download|. | 72 // Extracts UploadingExternalData* from |download|. |
| 73 UploadingExternalData* GetUploadingExternalData(DownloadItem* download) { | 73 UploadingExternalData* GetUploadingExternalData(DownloadItem* download) { |
| 74 return static_cast<UploadingExternalData*>( | 74 return static_cast<UploadingExternalData*>( |
| 75 download->GetExternalData(&kUploadingKey)); | 75 download->GetUserData(&kUploadingKey)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 // Extracts GDataExternalData* from |download|. | 78 // Extracts GDataExternalData* from |download|. |
| 79 GDataExternalData* GetGDataExternalData(DownloadItem* download) { | 79 GDataExternalData* GetGDataExternalData(DownloadItem* download) { |
| 80 return static_cast<GDataExternalData*>( | 80 return static_cast<GDataExternalData*>( |
| 81 download->GetExternalData(&kGDataPathKey)); | 81 download->GetUserData(&kGDataPathKey)); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void RunSubstituteGDataDownloadCallback( | 84 void RunSubstituteGDataDownloadCallback( |
| 85 const GDataDownloadObserver::SubstituteGDataDownloadPathCallback& callback, | 85 const GDataDownloadObserver::SubstituteGDataDownloadPathCallback& callback, |
| 86 const FilePath* file_path) { | 86 const FilePath* file_path) { |
| 87 callback.Run(*file_path); | 87 callback.Run(*file_path); |
| 88 } | 88 } |
| 89 | 89 |
| 90 gdata::GDataSystemService* GetSystemService(Profile* profile) { | 90 gdata::GDataSystemService* GetSystemService(Profile* profile) { |
| 91 gdata::GDataSystemService* system_service = | 91 gdata::GDataSystemService* system_service = |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 } | 226 } |
| 227 } | 227 } |
| 228 | 228 |
| 229 // static | 229 // static |
| 230 void GDataDownloadObserver::SetDownloadParams(const FilePath& gdata_path, | 230 void GDataDownloadObserver::SetDownloadParams(const FilePath& gdata_path, |
| 231 DownloadItem* download) { | 231 DownloadItem* download) { |
| 232 if (!download) | 232 if (!download) |
| 233 return; | 233 return; |
| 234 | 234 |
| 235 if (gdata::util::IsUnderGDataMountPoint(gdata_path)) { | 235 if (gdata::util::IsUnderGDataMountPoint(gdata_path)) { |
| 236 download->SetExternalData(&kGDataPathKey, | 236 download->SetUserData(&kGDataPathKey, |
| 237 new GDataExternalData(gdata_path)); | 237 new GDataExternalData(gdata_path)); |
| 238 download->SetDisplayName(gdata_path.BaseName()); | 238 download->SetDisplayName(gdata_path.BaseName()); |
| 239 download->SetIsTemporary(true); | 239 download->SetIsTemporary(true); |
| 240 } else if (IsGDataDownload(download)) { | 240 } else if (IsGDataDownload(download)) { |
| 241 // This may have been previously set if the default download folder is | 241 // 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 | 242 // /drive, and the user has now changed the download target to a local |
| 243 // folder. | 243 // folder. |
| 244 download->SetExternalData(&kGDataPathKey, NULL); | 244 download->SetUserData(&kGDataPathKey, NULL); |
| 245 download->SetDisplayName(gdata_path); | 245 download->SetDisplayName(gdata_path); |
| 246 // TODO(achuith): This is not quite right. | 246 // TODO(achuith): This is not quite right. |
| 247 download->SetIsTemporary(false); | 247 download->SetIsTemporary(false); |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 | 250 |
| 251 // static | 251 // static |
| 252 FilePath GDataDownloadObserver::GetGDataPath(DownloadItem* download) { | 252 FilePath GDataDownloadObserver::GetGDataPath(DownloadItem* download) { |
| 253 GDataExternalData* data = GetGDataExternalData(download); | 253 GDataExternalData* data = GetGDataExternalData(download); |
| 254 // If data is NULL, we've somehow lost the gdata path selected by the file | 254 // If data is NULL, we've somehow lost the gdata path selected by the file |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 DCHECK(!download->IsInProgress()); | 393 DCHECK(!download->IsInProgress()); |
| 394 | 394 |
| 395 DownloadMap::iterator it = pending_downloads_.find(download->GetId()); | 395 DownloadMap::iterator it = pending_downloads_.find(download->GetId()); |
| 396 if (it != pending_downloads_.end()) { | 396 if (it != pending_downloads_.end()) { |
| 397 DetachFromDownload(download); | 397 DetachFromDownload(download); |
| 398 pending_downloads_.erase(it); | 398 pending_downloads_.erase(it); |
| 399 } | 399 } |
| 400 } | 400 } |
| 401 | 401 |
| 402 void GDataDownloadObserver::DetachFromDownload(DownloadItem* download) { | 402 void GDataDownloadObserver::DetachFromDownload(DownloadItem* download) { |
| 403 download->SetExternalData(&kUploadingKey, NULL); | 403 download->SetUserData(&kUploadingKey, NULL); |
| 404 download->SetExternalData(&kGDataPathKey, NULL); | 404 download->SetUserData(&kGDataPathKey, NULL); |
| 405 download->RemoveObserver(this); | 405 download->RemoveObserver(this); |
| 406 } | 406 } |
| 407 | 407 |
| 408 void GDataDownloadObserver::UploadDownloadItem(DownloadItem* download) { | 408 void GDataDownloadObserver::UploadDownloadItem(DownloadItem* download) { |
| 409 // Update metadata of ongoing upload. | 409 // Update metadata of ongoing upload. |
| 410 UpdateUpload(download); | 410 UpdateUpload(download); |
| 411 | 411 |
| 412 if (!ShouldUpload(download)) | 412 if (!ShouldUpload(download)) |
| 413 return; | 413 return; |
| 414 | 414 |
| 415 // Initialize uploading external data. | 415 // Initialize uploading external data. |
| 416 download->SetExternalData(&kUploadingKey, | 416 download->SetUserData(&kUploadingKey, |
| 417 new UploadingExternalData(gdata_uploader_)); | 417 new UploadingExternalData(gdata_uploader_)); |
| 418 | 418 |
| 419 // Create UploadFileInfo structure for the download item. | 419 // Create UploadFileInfo structure for the download item. |
| 420 CreateUploadFileInfo(download); | 420 CreateUploadFileInfo(download); |
| 421 } | 421 } |
| 422 | 422 |
| 423 void GDataDownloadObserver::UpdateUpload(DownloadItem* download) { | 423 void GDataDownloadObserver::UpdateUpload(DownloadItem* download) { |
| 424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 424 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 425 | 425 |
| 426 UploadingExternalData* upload_data = GetUploadingExternalData(download); | 426 UploadingExternalData* upload_data = GetUploadingExternalData(download); |
| (...skipping 143 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. | 570 // use the final target path when the download item is in COMPLETE state. |
| 571 file_system_->AddUploadedFile(UPLOAD_NEW_FILE, | 571 file_system_->AddUploadedFile(UPLOAD_NEW_FILE, |
| 572 upload_data->virtual_dir_path(), | 572 upload_data->virtual_dir_path(), |
| 573 entry.Pass(), | 573 entry.Pass(), |
| 574 download->GetTargetFilePath(), | 574 download->GetTargetFilePath(), |
| 575 GDataCache::FILE_OPERATION_MOVE, | 575 GDataCache::FILE_OPERATION_MOVE, |
| 576 base::Bind(&base::DoNothing)); | 576 base::Bind(&base::DoNothing)); |
| 577 } | 577 } |
| 578 | 578 |
| 579 } // namespace gdata | 579 } // namespace gdata |
| OLD | NEW |