Index: chrome/browser/chromeos/drive/drive_feed_processor.cc |
=================================================================== |
--- chrome/browser/chromeos/drive/drive_feed_processor.cc (revision 167238) |
+++ chrome/browser/chromeos/drive/drive_feed_processor.cc (working copy) |
@@ -101,7 +101,6 @@ |
FROM_HERE, |
base::Bind(&DriveFeedProcessor::ApplyNextEntryProto, |
weak_ptr_factory_.GetWeakPtr())); |
- |
} |
void DriveFeedProcessor::ApplyNextEntryProto() { |
@@ -139,45 +138,149 @@ |
} |
void DriveFeedProcessor::ApplyEntryProto(const DriveEntryProto& entry_proto) { |
- scoped_ptr<DriveEntry> entry = |
- resource_metadata_->CreateDriveEntryFromProto(entry_proto); |
- DCHECK(entry.get()); |
- DriveEntry* old_entry = |
- resource_metadata_->GetEntryByResourceId(entry->resource_id()); |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- if (entry->is_deleted()) { |
- // Deleted file/directory. |
- DVLOG(1) << "Removing file " << entry->base_name(); |
- if (old_entry) |
- RemoveEntryFromParent(old_entry); |
- } else if (old_entry) { |
- // Change or move of existing entry. |
- // Please note that entry rename is just a special case of change here |
- // since name is just one of the properties that can change. |
- DVLOG(1) << "Changed file " << entry->base_name(); |
+ // Deleted file/directory. |
+ if (entry_proto.deleted()) { |
+ DVLOG(1) << "RemoveEntryFromParent " << entry_proto.base_name(); |
+ RemoveEntryFromParent(entry_proto.resource_id()); |
+ return; |
+ } |
- // Move children files over if we are dealing with directories. |
- if (old_entry->AsDriveDirectory() && entry->AsDriveDirectory()) { |
- entry->AsDriveDirectory()->TakeOverEntries( |
- old_entry->AsDriveDirectory()); |
- } |
+ resource_metadata_->GetEntryInfoByResourceId(entry_proto.resource_id(), |
+ base::Bind(&DriveFeedProcessor::ContinueApplyEntryProto, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ entry_proto)); |
+} |
- // Remove the old instance of this entry. |
- RemoveEntryFromParent(old_entry); |
+void DriveFeedProcessor::ContinueApplyEntryProto( |
+ const DriveEntryProto& entry_proto, |
+ DriveFileError error, |
+ const FilePath& drive_file_path, |
+ scoped_ptr<DriveEntryProto> old_entry_proto) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
- // Add to parent. |
- AddEntryToParent(entry.release()); |
+ if (error == DRIVE_FILE_OK) { |
+ // Entry exists and needs to be refreshed. |
+ RefreshEntryProto(entry_proto); |
} else { |
- // Adding a new file. |
- AddEntryToParent(entry.release()); |
+ // Adding a new entry. |
+ AddEntryToParent(entry_proto); |
} |
+} |
- // Process the next DriveEntryProto from the map. |
+void DriveFeedProcessor::RefreshEntryProto(const DriveEntryProto& entry_proto) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ // Get all directories to be notified. |
+ resource_metadata_->GetChangedDirectories( |
+ entry_proto.resource_id(), |
+ base::Bind(&DriveFeedProcessor::ContinueRefreshEntryProto, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ entry_proto)); |
+} |
+ |
+void DriveFeedProcessor::ContinueRefreshEntryProto( |
+ const DriveEntryProto& entry_proto, |
+ const std::set<FilePath>& changed_directories) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ resource_metadata_->RefreshEntryProto( |
+ entry_proto, |
+ base::Bind(&DriveFeedProcessor::NotifyForRefreshEntryProto, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ changed_directories)); |
+} |
+ |
+void DriveFeedProcessor::NotifyForRefreshEntryProto( |
+ const std::set<FilePath>& changed_directories, |
+ DriveFileError error, |
+ const FilePath& file_path, |
+ scoped_ptr<DriveEntryProto> entry_proto) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ DVLOG(1) << "NotifyForRefreshEntryProto " << file_path.value(); |
+ if (error == DRIVE_FILE_OK) { |
+ // Notify old children, old self and parent of old self. |
+ changed_dirs_.insert(changed_directories.begin(), |
+ changed_directories.end()); |
+ |
+ // Notify new parent. |
+ changed_dirs_.insert(file_path.DirName()); |
+ |
+ // Notify new self. |
+ if (!entry_proto->has_file_specific_info()) |
+ changed_dirs_.insert(file_path); |
+ } |
+ |
ApplyNextEntryProtoAsync(); |
} |
-void DriveFeedProcessor::AddEntryToParent( |
- DriveEntry* entry) { |
+void DriveFeedProcessor::AddEntryToParent(const DriveEntryProto& entry_proto) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ resource_metadata_->AddEntryToParent(entry_proto, |
+ base::Bind(&DriveFeedProcessor::NotifyForAddEntryToParent, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ !entry_proto.has_file_specific_info())); |
+} |
+ |
+void DriveFeedProcessor::NotifyForAddEntryToParent(bool is_directory, |
+ DriveFileError error, |
+ const FilePath& file_path) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ DVLOG(1) << "NotifyForAddEntryToParent " << file_path.value(); |
+ if (error == DRIVE_FILE_OK) { |
+ // Notify if a directory has been created. |
+ if (is_directory) |
+ changed_dirs_.insert(file_path); |
+ |
+ // Notify parent. |
+ changed_dirs_.insert(file_path.DirName()); |
+ } |
+ |
+ ApplyNextEntryProtoAsync(); |
+} |
+ |
+ |
+void DriveFeedProcessor::RemoveEntryFromParent(const std::string& resource_id) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ // We need to notify all children of entry if entry is a directory. |
+ resource_metadata_->GetChangedDirectories( |
+ resource_id, |
+ base::Bind(&DriveFeedProcessor::ContinueRemoveEntryFromParent, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ resource_id)); |
+} |
+ |
+void DriveFeedProcessor::ContinueRemoveEntryFromParent( |
+ const std::string& resource_id, |
+ const std::set<FilePath>& changed_directories) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ resource_metadata_->RemoveEntryFromParent( |
+ resource_id, |
+ base::Bind(&DriveFeedProcessor::NotifyForRemoveEntryFromParent, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ changed_directories)); |
+} |
+ |
+void DriveFeedProcessor::NotifyForRemoveEntryFromParent( |
+ const std::set<FilePath>& changed_directories, |
+ DriveFileError error, |
+ const FilePath& file_path) { |
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
+ |
+ if (error == DRIVE_FILE_OK) { |
+ changed_dirs_.insert(changed_directories.begin(), |
+ changed_directories.end()); |
+ } |
+ ApplyNextEntryProtoAsync(); |
+} |
+ |
+void DriveFeedProcessor::AddEntryToParent(DriveEntry* entry) { |
DriveDirectory* parent = ResolveParent(entry); |
if (!parent) { // Orphan. |
@@ -197,8 +300,7 @@ |
changed_dirs_.insert(parent->GetFilePath()); |
} |
-void DriveFeedProcessor::RemoveEntryFromParent( |
- DriveEntry* entry) { |
+void DriveFeedProcessor::RemoveEntryFromParent(DriveEntry* entry) { |
DriveDirectory* parent = entry->parent(); |
if (!parent) { |
NOTREACHED(); |
@@ -206,12 +308,9 @@ |
} |
DriveDirectory* dir = entry->AsDriveDirectory(); |
- if (dir) { |
+ if (dir) |
// We need to notify all children of entry if entry is a directory. |
dir->GetChildDirectoryPaths(&changed_dirs_); |
- // Besides children, notify this removed directory too. |
- changed_dirs_.insert(dir->GetFilePath()); |
- } |
parent->RemoveEntry(entry); |
@@ -219,8 +318,7 @@ |
changed_dirs_.insert(parent->GetFilePath()); |
} |
-DriveDirectory* DriveFeedProcessor::ResolveParent( |
- DriveEntry* new_entry) { |
+DriveDirectory* DriveFeedProcessor::ResolveParent(DriveEntry* new_entry) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
const std::string& parent_resource_id = new_entry->parent_resource_id(); |