Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1003)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_uploader.cc

Issue 10759007: gdata: Move GDataFileSystem::AddUploadedFile() call out of uploader and into GDataDownloadObserver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments for Patch #10. Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_uploader.h" 5 #include "chrome/browser/chromeos/gdata/gdata_uploader.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // Retry opening this file if we failed before. File open can fail because 160 // Retry opening this file if we failed before. File open can fail because
161 // the downloads system sets the full path on the UI thread and schedules a 161 // the downloads system sets the full path on the UI thread and schedules a
162 // rename on the FILE thread. Thus the new path is visible on the UI thread 162 // rename on the FILE thread. Thus the new path is visible on the UI thread
163 // before the renamed file is available on the file system. 163 // before the renamed file is available on the file system.
164 if (upload_file_info->should_retry_file_open) { 164 if (upload_file_info->should_retry_file_open) {
165 DCHECK(!download->IsComplete()); 165 DCHECK(!download->IsComplete());
166 // Disallow further retries. 166 // Disallow further retries.
167 upload_file_info->should_retry_file_open = false; 167 upload_file_info->should_retry_file_open = false;
168 OpenFile(upload_file_info); 168 OpenFile(upload_file_info);
169 } 169 }
170
171 if (download->IsComplete())
172 MoveFileToCache(upload_file_info);
173 } 170 }
174 171
175 int64 GDataUploader::GetUploadedBytes(int upload_id) const { 172 int64 GDataUploader::GetUploadedBytes(int upload_id) const {
176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
177 UploadFileInfo* upload_info = GetUploadFileInfo(upload_id); 174 UploadFileInfo* upload_info = GetUploadFileInfo(upload_id);
178 // We return the start_range as the count of uploaded bytes since that is the 175 // We return the start_range as the count of uploaded bytes since that is the
179 // start of the next or currently uploading chunk. 176 // start of the next or currently uploading chunk.
180 // TODO(asanka): Use a finer grained progress value than this. We end up 177 // TODO(asanka): Use a finer grained progress value than this. We end up
181 // reporting progress in kUploadChunkSize increments. 178 // reporting progress in kUploadChunkSize increments.
182 return upload_info ? upload_info->start_range : 0; 179 return upload_info ? upload_info->start_range : 0;
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } 476 }
480 477
481 DVLOG(1) << "Received range " << response.start_range_received 478 DVLOG(1) << "Received range " << response.start_range_received
482 << "-" << response.end_range_received 479 << "-" << response.end_range_received
483 << " for [" << upload_file_info->title << "]"; 480 << " for [" << upload_file_info->title << "]";
484 481
485 // Continue uploading. 482 // Continue uploading.
486 UploadNextChunk(upload_file_info); 483 UploadNextChunk(upload_file_info);
487 } 484 }
488 485
489 void GDataUploader::MoveFileToCache(UploadFileInfo* upload_file_info) {
490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
491 if (upload_file_info->entry == NULL)
492 return;
493
494 // Remove |upload_id| from the UploadFileInfoMap. The UploadFileInfo object
495 // will be deleted upon completion of AddUploadedFile.
496 RemoveUpload(upload_file_info->upload_id);
497
498 DVLOG(1) << "MoveFileToCache " << upload_file_info->file_path.value();
499 file_system_->AddUploadedFile(
500 UPLOAD_NEW_FILE,
501 upload_file_info->gdata_path.DirName(),
502 upload_file_info->entry.get(),
503 upload_file_info->file_path,
504 GDataCache::FILE_OPERATION_MOVE,
505 base::Bind(&base::DeletePointer<UploadFileInfo>,
506 upload_file_info));
507 }
508
509 void GDataUploader::UploadFailed(scoped_ptr<UploadFileInfo> upload_file_info, 486 void GDataUploader::UploadFailed(scoped_ptr<UploadFileInfo> upload_file_info,
510 base::PlatformFileError error) { 487 base::PlatformFileError error) {
511 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 488 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
512 489
513 RemoveUpload(upload_file_info->upload_id); 490 RemoveUpload(upload_file_info->upload_id);
514 491
515 LOG(ERROR) << "Upload failed " << upload_file_info->DebugString(); 492 LOG(ERROR) << "Upload failed " << upload_file_info->DebugString();
516 // This is subtle but we should take the callback reference before 493 // This is subtle but we should take the callback reference before
517 // calling upload_file_info.Pass(). Otherwise, it'll crash. 494 // calling upload_file_info.Pass(). Otherwise, it'll crash.
518 const UploadFileInfo::UploadCompletionCallback& callback = 495 const UploadFileInfo::UploadCompletionCallback& callback =
519 upload_file_info->completion_callback; 496 upload_file_info->completion_callback;
520 if (!callback.is_null()) 497 if (!callback.is_null())
521 callback.Run(error, upload_file_info.Pass()); 498 callback.Run(error, upload_file_info.Pass());
522 } 499 }
523 500
524 void GDataUploader::RemoveUpload(int upload_id) { 501 void GDataUploader::RemoveUpload(int upload_id) {
525 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 502 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
526 pending_uploads_.erase(upload_id); 503 pending_uploads_.erase(upload_id);
527 } 504 }
528 505
529 } // namespace gdata 506 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698