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

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

Issue 10825160: gdata: Cleanup GDataFileSystem::AddUploadedFileOnUIThread(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_file_system.h" 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 3509 matching lines...) Expand 10 before | Expand all | Expand 10 after
3520 } 3520 }
3521 3521
3522 void GDataFileSystem::AddUploadedFileOnUIThread( 3522 void GDataFileSystem::AddUploadedFileOnUIThread(
3523 UploadMode upload_mode, 3523 UploadMode upload_mode,
3524 const FilePath& virtual_dir_path, 3524 const FilePath& virtual_dir_path,
3525 scoped_ptr<DocumentEntry> entry, 3525 scoped_ptr<DocumentEntry> entry,
3526 const FilePath& file_content_path, 3526 const FilePath& file_content_path,
3527 GDataCache::FileOperationType cache_operation, 3527 GDataCache::FileOperationType cache_operation,
3528 const base::Closure& callback) { 3528 const base::Closure& callback) {
3529 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3529 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3530 DCHECK(!callback.is_null()); 3530 base::ScopedClosureRunner callback_runner(callback);
achuithb 2012/08/02 19:08:37 nit: Please add a comment since this is not common
satorux1 2012/08/02 19:41:13 ah this is pretty cool.
hshi1 2012/08/02 19:55:13 Done.
3531 3531
3532 if (!entry.get()) { 3532 if (!entry.get()) {
3533 NOTREACHED(); 3533 NOTREACHED();
3534 callback.Run();
3535 return; 3534 return;
3536 } 3535 }
3537 3536
3538 GDataEntry* dir_entry = directory_service_->FindEntryByPathSync( 3537 GDataEntry* dir_entry = directory_service_->FindEntryByPathSync(
3539 virtual_dir_path); 3538 virtual_dir_path);
3540 if (!dir_entry) { 3539 if (!dir_entry)
3541 callback.Run();
3542 return; 3540 return;
3543 }
3544 3541
3545 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); 3542 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory();
3546 if (!parent_dir) { 3543 if (!parent_dir)
3547 callback.Run();
3548 return; 3544 return;
3549 }
3550 3545
3551 scoped_ptr<GDataEntry> new_entry( 3546 scoped_ptr<GDataEntry> new_entry(
3552 GDataEntry::FromDocumentEntry( 3547 GDataEntry::FromDocumentEntry(
3553 parent_dir, entry.get(), directory_service_.get())); 3548 parent_dir, entry.get(), directory_service_.get()));
3554 if (!new_entry.get()) { 3549 if (!new_entry.get())
3555 callback.Run();
3556 return; 3550 return;
3557 }
3558 3551
3559 if (upload_mode == UPLOAD_EXISTING_FILE) { 3552 if (upload_mode == UPLOAD_EXISTING_FILE) {
3560 // Remove an existing entry, which should be present. 3553 // Remove an existing entry, which should be present.
3561 const std::string& resource_id = new_entry->resource_id(); 3554 const std::string& resource_id = new_entry->resource_id();
3562 directory_service_->GetEntryByResourceIdAsync(resource_id, 3555 directory_service_->GetEntryByResourceIdAsync(resource_id,
3563 base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir)); 3556 base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir));
3564 } 3557 }
3565 3558
3566 GDataFile* file = new_entry->AsGDataFile(); 3559 GDataFile* file = new_entry->AsGDataFile();
3567 DCHECK(file); 3560 DCHECK(file);
3568 const std::string& resource_id = file->resource_id(); 3561 const std::string& resource_id = file->resource_id();
3569 const std::string& md5 = file->file_md5(); 3562 const std::string& md5 = file->file_md5();
3570 parent_dir->AddEntry(new_entry.release()); 3563 parent_dir->AddEntry(new_entry.release());
3571 3564
3572 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, 3565 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_,
3573 OnDirectoryChanged(virtual_dir_path)); 3566 OnDirectoryChanged(virtual_dir_path));
3574 3567
3575 if (upload_mode == UPLOAD_NEW_FILE) { 3568 if (upload_mode == UPLOAD_NEW_FILE) {
3576 // Add the file to the cache if we have uploaded a new file. 3569 // Add the file to the cache if we have uploaded a new file.
3577 cache_->StoreOnUIThread(resource_id, 3570 cache_->StoreOnUIThread(resource_id,
3578 md5, 3571 md5,
3579 file_content_path, 3572 file_content_path,
3580 cache_operation, 3573 cache_operation,
3581 base::Bind(&OnCacheUpdatedForAddUploadedFile, 3574 base::Bind(&OnCacheUpdatedForAddUploadedFile,
3582 callback)); 3575 callback_runner.Release()));
3583 } else if (upload_mode == UPLOAD_EXISTING_FILE) { 3576 } else if (upload_mode == UPLOAD_EXISTING_FILE) {
3584 // Clear the dirty bit if we have updated an existing file. 3577 // Clear the dirty bit if we have updated an existing file.
3585 cache_->ClearDirtyOnUIThread(resource_id, 3578 cache_->ClearDirtyOnUIThread(resource_id,
3586 md5, 3579 md5,
3587 base::Bind(&OnCacheUpdatedForAddUploadedFile, 3580 base::Bind(&OnCacheUpdatedForAddUploadedFile,
3588 callback)); 3581 callback_runner.Release()));
3589 } else { 3582 } else {
3590 NOTREACHED() << "Unexpected upload mode: " << upload_mode; 3583 NOTREACHED() << "Unexpected upload mode: " << upload_mode;
3591 } 3584 }
3592 } 3585 }
3593 3586
3594 void GDataFileSystem::Observe(int type, 3587 void GDataFileSystem::Observe(int type,
3595 const content::NotificationSource& source, 3588 const content::NotificationSource& source,
3596 const content::NotificationDetails& details) { 3589 const content::NotificationDetails& details) {
3597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 3590 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
3598 3591
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
4051 } 4044 }
4052 4045
4053 PlatformFileInfoProto entry_file_info; 4046 PlatformFileInfoProto entry_file_info;
4054 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); 4047 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info);
4055 *entry_proto->mutable_file_info() = entry_file_info; 4048 *entry_proto->mutable_file_info() = entry_file_info;
4056 if (!callback.is_null()) 4049 if (!callback.is_null())
4057 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); 4050 callback.Run(GDATA_FILE_OK, entry_proto.Pass());
4058 } 4051 }
4059 4052
4060 } // namespace gdata 4053 } // namespace gdata
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698