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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 base::Bind(&OnEntryFound, profile, gdata_dir_path, | 162 base::Bind(&OnEntryFound, profile, gdata_dir_path, |
| 163 substitute_callback)); | 163 substitute_callback)); |
| 164 } else { | 164 } else { |
| 165 // TODO(achuith): Handle this. | 165 // TODO(achuith): Handle this. |
| 166 NOTREACHED(); | 166 NOTREACHED(); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 | 169 |
| 170 } // namespace | 170 } // namespace |
| 171 | 171 |
| 172 GDataDownloadObserver::GDataDownloadObserver() | 172 GDataDownloadObserver::GDataDownloadObserver( |
| 173 : gdata_uploader_(NULL), | 173 GDataUploader* uploader, |
| 174 GDataFileSystem* file_system) | |
| 175 : gdata_uploader_(uploader), | |
| 176 file_system_(file_system), | |
| 174 download_manager_(NULL), | 177 download_manager_(NULL), |
| 175 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 178 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 176 } | 179 } |
| 177 | 180 |
| 178 GDataDownloadObserver::~GDataDownloadObserver() { | 181 GDataDownloadObserver::~GDataDownloadObserver() { |
| 179 if (download_manager_) | 182 if (download_manager_) |
| 180 download_manager_->RemoveObserver(this); | 183 download_manager_->RemoveObserver(this); |
| 181 | 184 |
| 182 for (DownloadMap::iterator iter = pending_downloads_.begin(); | 185 for (DownloadMap::iterator iter = pending_downloads_.begin(); |
| 183 iter != pending_downloads_.end(); ++iter) { | 186 iter != pending_downloads_.end(); ++iter) { |
| 184 DetachFromDownload(iter->second); | 187 DetachFromDownload(iter->second); |
| 185 } | 188 } |
| 186 } | 189 } |
| 187 | 190 |
| 188 void GDataDownloadObserver::Initialize( | 191 void GDataDownloadObserver::Initialize( |
| 189 GDataUploader* gdata_uploader, | |
| 190 DownloadManager* download_manager, | 192 DownloadManager* download_manager, |
| 191 const FilePath& gdata_tmp_download_path) { | 193 const FilePath& gdata_tmp_download_path) { |
| 192 DCHECK(gdata_uploader); | |
| 193 DCHECK(!gdata_tmp_download_path.empty()); | 194 DCHECK(!gdata_tmp_download_path.empty()); |
| 194 gdata_uploader_ = gdata_uploader; | |
| 195 download_manager_ = download_manager; | 195 download_manager_ = download_manager; |
| 196 if (download_manager_) | 196 if (download_manager_) |
| 197 download_manager_->AddObserver(this); | 197 download_manager_->AddObserver(this); |
| 198 gdata_tmp_download_path_ = gdata_tmp_download_path; | 198 gdata_tmp_download_path_ = gdata_tmp_download_path; |
| 199 } | 199 } |
| 200 | 200 |
| 201 // static | 201 // static |
| 202 void GDataDownloadObserver::SubstituteGDataDownloadPath(Profile* profile, | 202 void GDataDownloadObserver::SubstituteGDataDownloadPath(Profile* profile, |
| 203 const FilePath& gdata_path, content::DownloadItem* download, | 203 const FilePath& gdata_path, content::DownloadItem* download, |
| 204 const SubstituteGDataDownloadPathCallback& callback) { | 204 const SubstituteGDataDownloadPathCallback& callback) { |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 download->GetId()); | 467 download->GetId()); |
| 468 | 468 |
| 469 return upload_file_info.Pass(); | 469 return upload_file_info.Pass(); |
| 470 } | 470 } |
| 471 | 471 |
| 472 void GDataDownloadObserver::OnUploadComplete( | 472 void GDataDownloadObserver::OnUploadComplete( |
| 473 int32 download_id, | 473 int32 download_id, |
| 474 base::PlatformFileError error, | 474 base::PlatformFileError error, |
| 475 scoped_ptr<UploadFileInfo> upload_file_info) { | 475 scoped_ptr<UploadFileInfo> upload_file_info) { |
| 476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 477 DCHECK(upload_file_info.get()); | |
| 478 | |
| 479 if (error == base::PLATFORM_FILE_OK && upload_file_info->entry.get()) { | |
| 480 // Save a local copy of the UploadFileInfo pointer. Depending on order of | |
| 481 // argument evaluation, scoped_ptr<T>::release() may invalidate the scoped | |
| 482 // pointer before it can be dereferenced to access its members. | |
| 483 const UploadFileInfo* upload_file_info_ptr = upload_file_info.get(); | |
| 484 file_system_->AddUploadedFile(UPLOAD_NEW_FILE, | |
| 485 upload_file_info_ptr->gdata_path.DirName(), | |
|
satorux1
2012/07/09 22:08:16
nit: indentation is off? please align parameters v
hshi1
2012/07/09 22:11:49
Done.
| |
| 486 upload_file_info_ptr->entry.get(), | |
| 487 upload_file_info_ptr->file_path, | |
| 488 GDataCache::FILE_OPERATION_COPY, | |
| 489 base::Bind(&base::DeletePointer<UploadFileInfo>, | |
| 490 upload_file_info.release())); | |
| 491 } | |
| 492 | |
| 477 DownloadMap::iterator iter = pending_downloads_.find(download_id); | 493 DownloadMap::iterator iter = pending_downloads_.find(download_id); |
| 478 if (iter == pending_downloads_.end()) { | 494 if (iter == pending_downloads_.end()) { |
| 479 DVLOG(1) << "Pending download not found" << download_id; | 495 DVLOG(1) << "Pending download not found" << download_id; |
| 480 return; | 496 return; |
| 481 } | 497 } |
| 482 DVLOG(1) << "Completing upload for download ID " << download_id; | 498 DVLOG(1) << "Completing upload for download ID " << download_id; |
| 483 DownloadItem* download_item = iter->second; | 499 DownloadItem* download_item = iter->second; |
| 484 UploadingExternalData* upload_data = GetUploadingExternalData(download_item); | 500 UploadingExternalData* upload_data = GetUploadingExternalData(download_item); |
| 485 DCHECK(upload_data); | 501 DCHECK(upload_data); |
| 486 upload_data->CompleteDownload(); | 502 upload_data->CompleteDownload(); |
| 487 } | 503 } |
| 488 | 504 |
| 489 } // namespace gdata | 505 } // namespace gdata |
| OLD | NEW |