OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/gdata/gdata_files.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_files.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 // Post-increment the iterator to avoid iterator invalidation. | 625 // Post-increment the iterator to avoid iterator invalidation. |
626 cache_map_.erase(iter++); | 626 cache_map_.erase(iter++); |
627 } else { | 627 } else { |
628 ++iter; | 628 ++iter; |
629 } | 629 } |
630 } | 630 } |
631 } | 631 } |
632 | 632 |
633 // Convert to/from proto. | 633 // Convert to/from proto. |
634 | 634 |
| 635 // static |
| 636 void GDataEntry::ConvertProtoToPlatformFileInfo( |
| 637 const PlatformFileInfoProto& proto, |
| 638 base::PlatformFileInfo* file_info) { |
| 639 file_info->size = proto.size(); |
| 640 file_info->is_directory = proto.is_directory(); |
| 641 file_info->is_symbolic_link = proto.is_symbolic_link(); |
| 642 file_info->last_modified = base::Time::FromInternalValue( |
| 643 proto.last_modified()); |
| 644 file_info->last_accessed = base::Time::FromInternalValue( |
| 645 proto.last_accessed()); |
| 646 file_info->creation_time = base::Time::FromInternalValue( |
| 647 proto.creation_time()); |
| 648 } |
| 649 |
| 650 // static |
| 651 void GDataEntry::ConvertPlatformFileInfoToProto( |
| 652 const base::PlatformFileInfo& file_info, |
| 653 PlatformFileInfoProto* proto) { |
| 654 proto->set_size(file_info.size); |
| 655 proto->set_is_directory(file_info.is_directory); |
| 656 proto->set_is_symbolic_link(file_info.is_symbolic_link); |
| 657 proto->set_last_modified(file_info.last_modified.ToInternalValue()); |
| 658 proto->set_last_accessed(file_info.last_accessed.ToInternalValue()); |
| 659 proto->set_creation_time(file_info.creation_time.ToInternalValue()); |
| 660 } |
| 661 |
635 void GDataEntry::FromProto(const GDataEntryProto& proto) { | 662 void GDataEntry::FromProto(const GDataEntryProto& proto) { |
636 file_info_.size = proto.file_info().size(); | 663 ConvertProtoToPlatformFileInfo(proto.file_info(), &file_info_); |
637 file_info_.is_directory = proto.file_info().is_directory(); | |
638 file_info_.is_symbolic_link = proto.file_info().is_symbolic_link(); | |
639 file_info_.last_modified = base::Time::FromInternalValue( | |
640 proto.file_info().last_modified()); | |
641 file_info_.last_accessed = base::Time::FromInternalValue( | |
642 proto.file_info().last_accessed()); | |
643 file_info_.creation_time = base::Time::FromInternalValue( | |
644 proto.file_info().creation_time()); | |
645 | 664 |
646 // Don't copy from proto.file_name() as file_name_ is computed in | 665 // Don't copy from proto.file_name() as file_name_ is computed in |
647 // SetFileNameFromTitle(). | 666 // SetFileNameFromTitle(). |
648 title_ = proto.title(); | 667 title_ = proto.title(); |
649 resource_id_ = proto.resource_id(); | 668 resource_id_ = proto.resource_id(); |
650 parent_resource_id_ = proto.parent_resource_id(); | 669 parent_resource_id_ = proto.parent_resource_id(); |
651 edit_url_ = GURL(proto.edit_url()); | 670 edit_url_ = GURL(proto.edit_url()); |
652 content_url_ = GURL(proto.content_url()); | 671 content_url_ = GURL(proto.content_url()); |
653 SetFileNameFromTitle(); | 672 SetFileNameFromTitle(); |
654 } | 673 } |
655 | 674 |
656 void GDataEntry::ToProto(GDataEntryProto* proto) const { | 675 void GDataEntry::ToProto(GDataEntryProto* proto) const { |
657 PlatformFileInfoProto* proto_file_info = proto->mutable_file_info(); | 676 ConvertPlatformFileInfoToProto(file_info_, proto->mutable_file_info()); |
658 proto_file_info->set_size(file_info_.size); | |
659 proto_file_info->set_is_directory(file_info_.is_directory); | |
660 proto_file_info->set_is_symbolic_link(file_info_.is_symbolic_link); | |
661 proto_file_info->set_last_modified( | |
662 file_info_.last_modified.ToInternalValue()); | |
663 proto_file_info->set_last_accessed( | |
664 file_info_.last_accessed.ToInternalValue()); | |
665 proto_file_info->set_creation_time( | |
666 file_info_.creation_time.ToInternalValue()); | |
667 | 677 |
668 // The file_name field is used in GetFileInfoByPathAsync(). As shown in | 678 // The file_name field is used in GetFileInfoByPathAsync(). As shown in |
669 // FromProto(), the value is discarded when deserializing from proto. | 679 // FromProto(), the value is discarded when deserializing from proto. |
670 proto->set_file_name(file_name_); | 680 proto->set_file_name(file_name_); |
671 proto->set_title(title_); | 681 proto->set_title(title_); |
672 proto->set_resource_id(resource_id_); | 682 proto->set_resource_id(resource_id_); |
673 proto->set_parent_resource_id(parent_resource_id_); | 683 proto->set_parent_resource_id(parent_resource_id_); |
674 proto->set_edit_url(edit_url_.spec()); | 684 proto->set_edit_url(edit_url_.spec()); |
675 proto->set_content_url(content_url_.spec()); | 685 proto->set_content_url(content_url_.spec()); |
676 } | 686 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 bool ok = proto->ParseFromString(serialized_proto); | 822 bool ok = proto->ParseFromString(serialized_proto); |
813 if (ok) { | 823 if (ok) { |
814 FromProto(*proto.get()); | 824 FromProto(*proto.get()); |
815 set_origin(FROM_CACHE); | 825 set_origin(FROM_CACHE); |
816 set_refresh_time(base::Time::Now()); | 826 set_refresh_time(base::Time::Now()); |
817 } | 827 } |
818 return ok; | 828 return ok; |
819 } | 829 } |
820 | 830 |
821 } // namespace gdata | 831 } // namespace gdata |
OLD | NEW |