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

Unified Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 10386226: gdata: Add requestDirectoryRefresh to file_browser_private. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix dcheck failures Created 8 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/gdata/gdata_file_system.cc
diff --git a/chrome/browser/chromeos/gdata/gdata_file_system.cc b/chrome/browser/chromeos/gdata/gdata_file_system.cc
index 48b3d12a4a28c3ad061c9bc48164ead19bcd7432..d2d5c9a40b772453413c1faff5b1da338f89c940 100644
--- a/chrome/browser/chromeos/gdata/gdata_file_system.cc
+++ b/chrome/browser/chromeos/gdata/gdata_file_system.cc
@@ -2551,6 +2551,110 @@ void GDataFileSystem::OnReadDirectory(const ReadDirectoryCallback& callback,
callback.Run(base::PLATFORM_FILE_OK, directory_proto.Pass());
}
+void GDataFileSystem::RequestDirectoryRefresh(
+ const FilePath& file_path) {
+ if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ const bool posted = BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ base::Bind(&GDataFileSystem::RequestDirectoryRefreshOnUIThread,
+ ui_weak_ptr_,
+ file_path));
+ DCHECK(posted);
+ return;
+ }
+
+ RequestDirectoryRefreshOnUIThread(file_path);
+}
+
+void GDataFileSystem::RequestDirectoryRefreshOnUIThread(
+ const FilePath& file_path) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ base::AutoLock lock(lock_); // To use GetGDataEntryByPath() and root_.
+ GDataEntry* entry = GetGDataEntryByPath(file_path);
+ if (!entry || !entry->AsGDataDirectory()) {
+ LOG(ERROR) << "Directory entry not found: " << file_path.value();
+ return;
+ }
+
+ if (entry->resource_id().empty()) {
+ // This can happen if the directory is a virtual directory for search.
+ LOG(ERROR) << "Resource ID not found: " << file_path.value();
+ return;
+ }
+
+ LoadFeedFromServer(root_->origin(),
+ 0, // Not delta feed.
+ 0, // Not used.
+ true, // multiple feeds
+ file_path,
+ std::string(), // No search query
+ entry->resource_id(),
+ FindEntryCallback(), // Not used.
+ base::Bind(&GDataFileSystem::OnRequestDirectoryRefresh,
+ ui_weak_ptr_));
+}
+
+void GDataFileSystem::OnRequestDirectoryRefresh(
+ GetDocumentsParams* params,
+ base::PlatformFileError error) {
+ DCHECK(params);
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ const FilePath& directory_path = params->search_file_path;
+ if (error != base::PLATFORM_FILE_OK) {
+ LOG(ERROR) << "Failed to refresh directory: " << directory_path.value()
+ << ": " << error;
+ return;
+ }
+
+ base::AutoLock lock(lock_); // To use FeedToFileResourceMap() and root_.
+
+ int unused_delta_feed_changestamp = 0;
+ int unused_num_regular_files = 0;
+ int unused_num_hosted_documents = 0;
+ FileResourceIdMap file_map;
+ error = FeedToFileResourceMap(*params->feed_list,
+ &file_map,
+ &unused_delta_feed_changestamp,
+ &unused_num_regular_files,
+ &unused_num_hosted_documents);
+ if (error != base::PLATFORM_FILE_OK) {
+ LOG(ERROR) << "Failed to convert feed: " << directory_path.value()
+ << ": " << error;
+ return;
+ }
+
+ GDataEntry* directory_entry = root_->GetEntryByResourceId(
+ params->directory_resource_id);
+ if (!directory_entry || !directory_entry->AsGDataDirectory()) {
+ LOG(ERROR) << "Directory entry is gone: " << directory_path.value()
+ << ": " << params->directory_resource_id;
+ return;
+ }
+ GDataDirectory* directory = directory_entry->AsGDataDirectory();
+
+ // Remove the existing files.
+ directory->RemoveChildFiles();
+ // Go through all entires generated by the feed and add files.
+ for (FileResourceIdMap::const_iterator it = file_map.begin();
+ it != file_map.end(); ++it) {
+ scoped_ptr<GDataEntry> entry(it->second);
+ // Skip if it's not a file (i.e. directory).
+ if (!entry->AsGDataFile())
+ continue;
+ directory->AddEntry(entry.release());
+ }
+
+ // Note that there may be no change in the directory, but it's expensive to
+ // check if the new metadata matches the existing one, so we just always
+ // notify that the directory is changed.
+ NotifyDirectoryChanged(directory_path);
+ DVLOG(1) << "Directory refreshed: " << directory_path.value();
+}
+
bool GDataFileSystem::GetFileInfoByPath(
const FilePath& file_path, GDataFileProperties* properties) {
DCHECK(properties);
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698