| 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_directory_service.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_directory_service.h" |
| 6 | 6 |
| 7 #include <leveldb/db.h> | 7 #include <leveldb/db.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 namespace gdata { | 22 namespace gdata { |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // m: prefix for filesystem metadata db keys, version and largest_changestamp. | 25 // m: prefix for filesystem metadata db keys, version and largest_changestamp. |
| 26 // r: prefix for resource id db keys. | 26 // r: prefix for resource id db keys. |
| 27 const char kDBKeyLargestChangestamp[] = "m:largest_changestamp"; | 27 const char kDBKeyLargestChangestamp[] = "m:largest_changestamp"; |
| 28 const char kDBKeyVersion[] = "m:version"; | 28 const char kDBKeyVersion[] = "m:version"; |
| 29 const char kDBKeyResourceIdPrefix[] = "r:"; | 29 const char kDBKeyResourceIdPrefix[] = "r:"; |
| 30 | 30 |
| 31 // Returns true if |proto| is a valid proto as the root directory. | |
| 32 // Used to reject incompatible proto. | |
| 33 bool IsValidRootDirectoryProto(const GDataDirectoryProto& proto) { | |
| 34 const GDataEntryProto& entry_proto = proto.gdata_entry(); | |
| 35 // The title field for the root directory was originally empty, then | |
| 36 // changed to "gdata", then changed to "drive". Discard the proto data if | |
| 37 // the older formats are detected. See crbug.com/128133 for details. | |
| 38 if (entry_proto.title() != "drive") { | |
| 39 LOG(ERROR) << "Incompatible proto detected (bad title): " | |
| 40 << entry_proto.title(); | |
| 41 return false; | |
| 42 } | |
| 43 // The title field for the root directory was originally empty. Discard | |
| 44 // the proto data if the older format is detected. | |
| 45 if (entry_proto.resource_id() != kGDataRootDirectoryResourceId) { | |
| 46 LOG(ERROR) << "Incompatible proto detected (bad resource ID): " | |
| 47 << entry_proto.resource_id(); | |
| 48 return false; | |
| 49 } | |
| 50 | |
| 51 return true; | |
| 52 } | |
| 53 | |
| 54 } // namespace | 31 } // namespace |
| 55 | 32 |
| 56 EntryInfoResult::EntryInfoResult() : error(GDATA_FILE_ERROR_FAILED) { | 33 EntryInfoResult::EntryInfoResult() : error(GDATA_FILE_ERROR_FAILED) { |
| 57 } | 34 } |
| 58 | 35 |
| 59 EntryInfoResult::~EntryInfoResult() { | 36 EntryInfoResult::~EntryInfoResult() { |
| 60 } | 37 } |
| 61 | 38 |
| 62 EntryInfoPairResult::EntryInfoPairResult() { | 39 EntryInfoPairResult::EntryInfoPairResult() { |
| 63 } | 40 } |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 GDataRootDirectoryProto proto; | 650 GDataRootDirectoryProto proto; |
| 674 if (!proto.ParseFromString(serialized_proto)) | 651 if (!proto.ParseFromString(serialized_proto)) |
| 675 return false; | 652 return false; |
| 676 | 653 |
| 677 if (proto.version() != kProtoVersion) { | 654 if (proto.version() != kProtoVersion) { |
| 678 LOG(ERROR) << "Incompatible proto detected (incompatible version): " | 655 LOG(ERROR) << "Incompatible proto detected (incompatible version): " |
| 679 << proto.version(); | 656 << proto.version(); |
| 680 return false; | 657 return false; |
| 681 } | 658 } |
| 682 | 659 |
| 683 if (!IsValidRootDirectoryProto(proto.gdata_directory())) | 660 root_->FromProto(proto.gdata_directory()); |
| 684 return false; | |
| 685 | |
| 686 if (!root_->FromProto(proto.gdata_directory())) | |
| 687 return false; | |
| 688 | 661 |
| 689 origin_ = FROM_CACHE; | 662 origin_ = FROM_CACHE; |
| 690 largest_changestamp_ = proto.largest_changestamp(); | 663 largest_changestamp_ = proto.largest_changestamp(); |
| 691 | 664 |
| 692 return true; | 665 return true; |
| 693 } | 666 } |
| 694 | 667 |
| 695 scoped_ptr<GDataEntry> GDataDirectoryService::FromProtoString( | 668 scoped_ptr<GDataEntry> GDataDirectoryService::FromProtoString( |
| 696 const std::string& serialized_proto) { | 669 const std::string& serialized_proto) { |
| 697 GDataEntryProto entry_proto; | 670 GDataEntryProto entry_proto; |
| 698 if (!entry_proto.ParseFromString(serialized_proto)) | 671 if (!entry_proto.ParseFromString(serialized_proto)) |
| 699 return scoped_ptr<GDataEntry>(); | 672 return scoped_ptr<GDataEntry>(); |
| 700 | 673 |
| 701 scoped_ptr<GDataEntry> entry; | 674 scoped_ptr<GDataEntry> entry; |
| 702 if (entry_proto.file_info().is_directory()) { | 675 if (entry_proto.file_info().is_directory()) { |
| 703 entry.reset(CreateGDataDirectory()); | 676 entry.reset(CreateGDataDirectory()); |
| 704 // Call GDataEntry::FromProto instead of GDataDirectory::FromProto because | 677 // Call GDataEntry::FromProto instead of GDataDirectory::FromProto because |
| 705 // the proto does not include children. | 678 // the proto does not include children. |
| 706 if (!entry->FromProto(entry_proto)) { | 679 entry->FromProto(entry_proto); |
| 707 NOTREACHED() << "FromProto (directory) failed"; | |
| 708 entry.reset(); | |
| 709 } | |
| 710 } else { | 680 } else { |
| 711 scoped_ptr<GDataFile> file(CreateGDataFile()); | 681 scoped_ptr<GDataFile> file(CreateGDataFile()); |
| 712 // Call GDataFile::FromProto. | 682 // Call GDataFile::FromProto. |
| 713 if (file->FromProto(entry_proto)) { | 683 file->FromProto(entry_proto); |
| 714 entry.reset(file.release()); | 684 entry.reset(file.release()); |
| 715 } else { | |
| 716 NOTREACHED() << "FromProto (file) failed"; | |
| 717 } | |
| 718 } | 685 } |
| 719 return entry.Pass(); | 686 return entry.Pass(); |
| 720 } | 687 } |
| 721 | 688 |
| 722 void GDataDirectoryService::GetEntryInfoPairByPathsAfterGetFirst( | 689 void GDataDirectoryService::GetEntryInfoPairByPathsAfterGetFirst( |
| 723 const FilePath& first_path, | 690 const FilePath& first_path, |
| 724 const FilePath& second_path, | 691 const FilePath& second_path, |
| 725 const GetEntryInfoPairCallback& callback, | 692 const GetEntryInfoPairCallback& callback, |
| 726 GDataFileError error, | 693 GDataFileError error, |
| 727 scoped_ptr<GDataEntryProto> entry_proto) { | 694 scoped_ptr<GDataEntryProto> entry_proto) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 DCHECK(result.get()); | 727 DCHECK(result.get()); |
| 761 | 728 |
| 762 result->second.path = second_path; | 729 result->second.path = second_path; |
| 763 result->second.error = error; | 730 result->second.error = error; |
| 764 result->second.proto = entry_proto.Pass(); | 731 result->second.proto = entry_proto.Pass(); |
| 765 | 732 |
| 766 callback.Run(result.Pass()); | 733 callback.Run(result.Pass()); |
| 767 } | 734 } |
| 768 | 735 |
| 769 } // namespace gdata | 736 } // namespace gdata |
| OLD | NEW |