Index: chrome/browser/chromeos/gdata/gdata_files.cc |
=================================================================== |
--- chrome/browser/chromeos/gdata/gdata_files.cc (revision 126063) |
+++ chrome/browser/chromeos/gdata/gdata_files.cc (working copy) |
@@ -77,6 +77,10 @@ |
return path; |
} |
+void GDataFileBase::UseOriginalFileName() { |
+ file_name_ = EscapeUtf8FileName(original_file_name_); |
+} |
+ |
// static. |
GDataFileBase* GDataFileBase::FromDocumentEntry(GDataDirectory* parent, |
DocumentEntry* doc) { |
@@ -125,27 +129,36 @@ |
return this; |
} |
+void GDataFile::UseOriginalFileName() { |
+ if (is_hosted_document_) { |
+ file_name_ = EscapeUtf8FileName(original_file_name_ + document_extension_); |
+ } else { |
+ GDataFileBase::UseOriginalFileName(); |
+ } |
+} |
+ |
GDataFileBase* GDataFile::FromDocumentEntry(GDataDirectory* parent, |
DocumentEntry* doc) { |
DCHECK(doc->is_hosted_document() || doc->is_file()); |
GDataFile* file = new GDataFile(parent); |
+ |
+ // For regular files, the 'filename' and 'title' attribute in the metadata |
+ // may be different (e.g. due to rename). To be consistent with the web |
+ // interface and other client to use the 'title' attribute, instead of |
+ // 'filename', as the file name in the local snapshot. |
+ file->original_file_name_ = UTF16ToUTF8(doc->title()); |
satorux1
2012/03/12 17:48:24
this looks like an important change. It'd be nicer
zel
2012/03/12 20:46:46
Is title required for regular (non-hosted) files t
Ben Chan
2012/03/13 00:29:21
Agree. Let me split the CL.
Ben Chan
2012/03/13 00:29:21
Yes, I noticed that both the web interface and the
|
+ |
// Check if this entry is a true file, or... |
if (doc->is_file()) { |
- file->original_file_name_ = UTF16ToUTF8(doc->filename()); |
- file->file_name_ = |
- GDataFileBase::EscapeUtf8FileName(file->original_file_name_); |
file->file_info_.size = doc->file_size(); |
file->file_md5_ = doc->file_md5(); |
} else { |
- DCHECK(doc->is_hosted_document()); |
// ... a hosted document. |
- file->original_file_name_ = UTF16ToUTF8(doc->title()); |
// Attach .g<something> extension to hosted documents so we can special |
// case their handling in UI. |
// TODO(zelidrag): Figure out better way how to pass entry info like kind |
// to UI through the File API stack. |
- file->file_name_ = GDataFileBase::EscapeUtf8FileName( |
- file->original_file_name_ + doc->GetHostedDocumentExtension()); |
+ file->document_extension_ = doc->GetHostedDocumentExtension(); |
// We don't know the size of hosted docs and it does not matter since |
// is has no effect on the quota. |
file->file_info_.size = 0; |
@@ -164,6 +177,9 @@ |
file->file_info_.last_accessed = doc->updated_time(); |
file->file_info_.creation_time = doc->published_time(); |
+ // UseOriginalFileName() must be called after |is_hosted_document_| is set. |
+ file->UseOriginalFileName(); |
+ |
const Link* thumbnail_link = doc->GetLinkByType(Link::THUMBNAIL); |
if (thumbnail_link) |
file->thumbnail_url_ = thumbnail_link->href(); |
@@ -201,14 +217,19 @@ |
DCHECK(doc->is_folder()); |
GDataDirectory* dir = new GDataDirectory(parent); |
dir->original_file_name_ = UTF16ToUTF8(doc->title()); |
- dir->file_name_ = GDataFileBase::EscapeUtf8FileName(dir->original_file_name_); |
+ dir->UseOriginalFileName(); |
dir->file_info_.last_modified = doc->updated_time(); |
dir->file_info_.last_accessed = doc->updated_time(); |
dir->file_info_.creation_time = doc->published_time(); |
// Extract feed link. |
dir->start_feed_url_ = doc->content_url(); |
+ dir->resource_id_ = doc->resource_id(); |
dir->content_url_ = doc->content_url(); |
+ const Link* self_link = doc->GetLinkByType(Link::SELF); |
+ if (self_link) |
+ dir->self_url_ = self_link->href(); |
+ |
const Link* upload_link = doc->GetLinkByType(Link::RESUMABLE_CREATE_MEDIA); |
if (upload_link) |
dir->upload_url_ = upload_link->href(); |
@@ -260,6 +281,27 @@ |
root_->AddFileToResourceMap(file); |
} |
+bool GDataDirectory::MoveFile(GDataFileBase* file, GDataDirectory* dir) { |
+ DCHECK(file); |
+ DCHECK(dir); |
+ DCHECK_EQ(this, file->parent()); |
+ |
+ GDataFileCollection::iterator iter = children_.find(file->file_name()); |
+ if (children_.find(file->file_name()) == children_.end()) |
+ return false; |
+ |
+ DCHECK(iter->second); |
+ children_.erase(iter); |
+ |
+ // The file name may have been changed due to prior de-duplication. |
+ // We need to first restore the original name of the file before going |
+ // through de-duplication again when it is added to another directory. |
+ file->UseOriginalFileName(); |
+ dir->AddFile(file); |
+ file->set_parent(dir); |
+ return true; |
+} |
+ |
bool GDataDirectory::RemoveFile(GDataFileBase* file) { |
GDataFileCollection::iterator iter = children_.find(file->file_name()); |
if (iter == children_.end()) |