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

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

Issue 10829277: GDataFileSystem is no longer a friend of GDataDirectory. (Closed) Base URL: svn://chrome-svn/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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/gdata/gdata_files.cc
===================================================================
--- chrome/browser/chromeos/gdata/gdata_files.cc (revision 151008)
+++ chrome/browser/chromeos/gdata/gdata_files.cc (working copy)
@@ -5,7 +5,6 @@
#include "chrome/browser/chromeos/gdata/gdata_files.h"
#include <leveldb/db.h>
-#include <vector>
#include "base/message_loop_proxy.h"
#include "base/platform_file.h"
@@ -254,6 +253,8 @@
}
void GDataDirectory::AddEntry(GDataEntry* entry) {
+ DCHECK(!entry->parent());
+
// The entry name may have been changed due to prior name de-duplication.
// We need to first restore the file name based on the title before going
// through name de-duplication again when it is added to another directory.
@@ -296,6 +297,7 @@
bool GDataDirectory::TakeOverEntries(GDataDirectory* dir) {
for (GDataFileCollection::iterator iter = dir->child_files_.begin();
iter != dir->child_files_.end(); ++iter) {
+ iter->second->SetParent(NULL);
satorux1 2012/08/10 16:14:44 iter->second looks cryptic. maybe add: GDataFi
achuithb 2012/08/11 00:37:45 Done.
AddEntry(iter->second);
}
dir->child_files_.clear();
@@ -303,6 +305,7 @@
for (GDataDirectoryCollection::iterator iter =
dir->child_directories_.begin();
iter != dir->child_directories_.end(); ++iter) {
+ iter->second->SetParent(NULL);
satorux1 2012/08/10 16:14:44 ditto
achuithb 2012/08/11 00:37:45 Done.
AddEntry(iter->second);
}
dir->child_directories_.clear();
@@ -355,6 +358,8 @@
// Then delete it from tree.
child_files_.erase(base_name);
child_directories_.erase(base_name);
+
+ entry->SetParent(NULL);
}
void GDataDirectory::RemoveChildren() {
@@ -563,6 +568,16 @@
root_.reset();
}
+void GDataDirectoryService::AddEntryToDirectory(
+ GDataDirectory* directory,
+ GDataEntry* new_entry,
+ const base::Closure& callback) {
satorux1 2012/08/10 16:14:44 As of now, this function won't fail as we are deal
achuithb 2012/08/11 00:37:45 This is an excellent suggestion, however we want t
+ DCHECK(!callback.is_null());
satorux1 2012/08/10 16:14:44 maybe add DCHECK(directory) and DCHECK(new_entry)
achuithb 2012/08/11 00:37:45 Done.
+ directory->AddEntry(new_entry);
+ base::MessageLoopProxy::current()->PostTask(FROM_HERE, callback);
+}
+
+
void GDataDirectoryService::MoveEntryToDirectory(
const FilePath& directory_path,
GDataEntry* entry,
@@ -591,6 +606,16 @@
}
}
+void GDataDirectoryService::RemoveEntryFromParent(
+ GDataEntry* entry,
+ const base::Closure& callback) {
satorux1 2012/08/10 16:14:44 ditto. FileOperationCallback?
achuithb 2012/08/11 00:37:45 Done. FileMoveCallback here and also in RefreshDir
+ entry->parent()->RemoveEntry(entry);
+ if (!callback.is_null()) {
+ base::MessageLoopProxy::current()->PostTask(FROM_HERE, callback);
+ }
+}
+
+
void GDataDirectoryService::AddEntryToResourceMap(GDataEntry* entry) {
// GDataFileSystem has already locked.
DVLOG(1) << "AddEntryToResourceMap " << entry->resource_id();
@@ -734,6 +759,43 @@
}
}
+void GDataDirectoryService::RefreshDirectory(
+ const std::string& directory_resource_id,
+ const ResourceMap& file_map,
+ const base::Closure& callback) {
satorux1 2012/08/10 16:14:44 DCHECK(!callback.is_null())
achuithb 2012/08/11 00:37:45 Done.
+ GetEntryByResourceIdAsync(directory_resource_id,
satorux1 2012/08/10 16:14:44 nit: please move directory_resource_id to the next
achuithb 2012/08/11 00:37:45 Done.
+ base::Bind(&GDataDirectoryService::RefreshDirectoryInternal,
+ file_map,
+ callback));
+}
+
+// static
+void GDataDirectoryService::RefreshDirectoryInternal(
+ const ResourceMap& file_map,
+ const base::Closure& callback,
+ GDataEntry* directory_entry) {
+ DCHECK(!callback.is_null());
satorux1 2012/08/10 16:14:44 nit: add a blank line like we do elsewhere
achuithb 2012/08/11 00:37:45 Done.
+ if (!directory_entry || !directory_entry->AsGDataDirectory()) {
+ LOG(ERROR) << "RefreshDirectoryInternal: Failed to find directory";
+ return;
+ }
+
+ GDataDirectory* directory = directory_entry->AsGDataDirectory();
+
+ directory->RemoveChildFiles();
+ // Add files from file_map.
+ for (ResourceMap::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());
+ }
+
+ callback.Run();
+}
+
void GDataDirectoryService::InitFromDB(
const FilePath& db_path,
base::SequencedTaskRunner* blocking_task_runner,

Powered by Google App Engine
This is Rietveld 408576698