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

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

Issue 10825218: Simplify implementation of FindEntryByPathSync (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: remove FindChildAsync 2 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 150246)
+++ chrome/browser/chromeos/gdata/gdata_files.cc (working copy)
@@ -350,14 +350,11 @@
return true;
}
-bool GDataDirectory::RemoveEntry(GDataEntry* entry) {
+void GDataDirectory::RemoveEntry(GDataEntry* entry) {
DCHECK(entry);
- if (!RemoveChild(entry))
- return false;
-
+ RemoveChild(entry);
satorux1 2012/08/07 22:38:09 The new behavior may be rather scary. Previously i
achuithb 2012/08/07 22:48:35 We're using this function in 2 places in GDataFile
delete entry;
- return true;
}
GDataEntry* GDataDirectory::FindChild(
@@ -386,16 +383,10 @@
child_directories_.insert(std::make_pair(entry->base_name(), directory));
}
-bool GDataDirectory::RemoveChild(GDataEntry* entry) {
+void GDataDirectory::RemoveChild(GDataEntry* entry) {
DCHECK(entry);
- const std::string file_name(entry->base_name());
- GDataEntry* found_entry = FindChild(file_name);
- if (!found_entry)
- return false;
-
- DCHECK_EQ(entry, found_entry);
-
+ const std::string& file_name(entry->base_name());
satorux1 2012/08/07 22:27:05 file_name -> base_name ?
achuithb 2012/08/07 22:29:43 Done.
// Remove entry from resource map first.
if (directory_service_)
directory_service_->RemoveEntryFromResourceMap(entry);
@@ -403,8 +394,6 @@
// Then delete it from tree.
child_files_.erase(file_name);
child_directories_.erase(file_name);
-
- return true;
}
void GDataDirectory::RemoveChildren() {
@@ -619,39 +608,22 @@
GDataEntry* GDataDirectoryService::FindEntryByPathSync(
const FilePath& file_path) {
+ if (file_path == root_->GetFilePath())
+ return root_.get();
+
std::vector<FilePath::StringType> components;
file_path.GetComponents(&components);
-
GDataDirectory* current_dir = root_.get();
- FilePath directory_path;
- for (size_t i = 0; i < components.size() && current_dir; i++) {
- directory_path = directory_path.Append(current_dir->base_name());
-
- // Last element must match, if not last then it must be a directory.
- if (i == components.size() - 1) {
- if (current_dir->base_name() == components[i])
- return current_dir;
- else
- return NULL;
- }
-
- // Not the last part of the path, search for the next segment.
- GDataEntry* entry = current_dir->FindChild(components[i + 1]);
- if (!entry) {
+ for (size_t i = 1; i < components.size() && current_dir; ++i) {
+ GDataEntry* entry = current_dir->FindChild(components[i]);
+ if (!entry)
return NULL;
- }
- // Found file, must be the last segment.
- if (entry->file_info().is_directory) {
- // Found directory, continue traversal.
+ if (i == components.size() - 1) // Last component.
+ return entry;
+ else
current_dir = entry->AsGDataDirectory();
- } else {
- if ((i + 1) == (components.size() - 1))
- return entry;
- else
- return NULL;
- }
}
satorux1 2012/08/07 22:27:05 Much simpler! Nice.
return NULL;
}

Powered by Google App Engine
This is Rietveld 408576698