Chromium Code Reviews| 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 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 727 | 727 |
| 728 // static | 728 // static |
| 729 scoped_ptr<GDataEntry> GDataEntry::FromProtoString( | 729 scoped_ptr<GDataEntry> GDataEntry::FromProtoString( |
| 730 const std::string& serialized_proto) { | 730 const std::string& serialized_proto) { |
| 731 // First try to parse as GDataDirectoryProto. Note that this can succeed for | 731 // First try to parse as GDataDirectoryProto. Note that this can succeed for |
| 732 // a serialized_proto that's really a GDataFileProto - we have to check | 732 // a serialized_proto that's really a GDataFileProto - we have to check |
| 733 // is_directory to be sure. | 733 // is_directory to be sure. |
| 734 GDataDirectoryProto dir_proto; | 734 GDataDirectoryProto dir_proto; |
| 735 bool ok = dir_proto.ParseFromString(serialized_proto); | 735 bool ok = dir_proto.ParseFromString(serialized_proto); |
| 736 if (ok && dir_proto.gdata_entry().file_info().is_directory()) { | 736 if (ok && dir_proto.gdata_entry().file_info().is_directory()) { |
| 737 GDataDirectory* dir = new GDataDirectory(NULL, NULL); | 737 scoped_ptr<GDataDirectory> dir(new GDataDirectory(NULL, NULL)); |
| 738 if (!dir->FromProto(dir_proto)) | 738 if (!dir->FromProto(dir_proto)) |
| 739 return scoped_ptr<GDataEntry>(NULL); | 739 return scoped_ptr<GDataEntry>(NULL); |
| 740 return scoped_ptr<GDataEntry>(dir); | 740 return scoped_ptr<GDataEntry>(dir.release()); |
|
achuithb
2012/07/10 23:09:02
I think you can return dir.Pass() in both cases, i
satorux1
2012/07/10 23:25:04
If FromProto() failed, we should return NULL.
Not
achuithb
2012/07/10 23:29:15
Ah, that's unfortunate. I believe there's a way to
| |
| 741 } | 741 } |
| 742 | 742 |
| 743 GDataFileProto file_proto; | 743 GDataFileProto file_proto; |
| 744 ok = file_proto.ParseFromString(serialized_proto); | 744 ok = file_proto.ParseFromString(serialized_proto); |
| 745 if (ok) { | 745 if (ok) { |
| 746 DCHECK(!file_proto.gdata_entry().file_info().is_directory()); | 746 DCHECK(!file_proto.gdata_entry().file_info().is_directory()); |
| 747 GDataFile* file = new GDataFile(NULL, NULL); | 747 scoped_ptr<GDataFile> file(new GDataFile(NULL, NULL)); |
| 748 if (!file->FromProto(file_proto)) | 748 if (!file->FromProto(file_proto)) |
| 749 return scoped_ptr<GDataEntry>(NULL); | 749 return scoped_ptr<GDataEntry>(NULL); |
| 750 return scoped_ptr<GDataEntry>(file); | 750 return scoped_ptr<GDataEntry>(file.release()); |
|
achuithb
2012/07/10 23:09:02
same
| |
| 751 } | 751 } |
| 752 return scoped_ptr<GDataEntry>(NULL); | 752 return scoped_ptr<GDataEntry>(NULL); |
| 753 } | 753 } |
| 754 | 754 |
| 755 void GDataRootDirectory::SerializeToString( | 755 void GDataRootDirectory::SerializeToString( |
| 756 std::string* serialized_proto) const { | 756 std::string* serialized_proto) const { |
| 757 GDataRootDirectoryProto proto; | 757 GDataRootDirectoryProto proto; |
| 758 ToProto(&proto); | 758 ToProto(&proto); |
| 759 const bool ok = proto.SerializeToString(serialized_proto); | 759 const bool ok = proto.SerializeToString(serialized_proto); |
| 760 DCHECK(ok); | 760 DCHECK(ok); |
| 761 } | 761 } |
| 762 | 762 |
| 763 bool GDataRootDirectory::ParseFromString(const std::string& serialized_proto) { | 763 bool GDataRootDirectory::ParseFromString(const std::string& serialized_proto) { |
| 764 GDataRootDirectoryProto proto; | 764 GDataRootDirectoryProto proto; |
| 765 if (!proto.ParseFromString(serialized_proto)) | 765 if (!proto.ParseFromString(serialized_proto)) |
| 766 return false; | 766 return false; |
| 767 | 767 |
| 768 if (!FromProto(proto)) | 768 if (!FromProto(proto)) |
| 769 return false; | 769 return false; |
| 770 | 770 |
| 771 set_origin(FROM_CACHE); | 771 set_origin(FROM_CACHE); |
| 772 return true; | 772 return true; |
| 773 } | 773 } |
| 774 | 774 |
| 775 } // namespace gdata | 775 } // namespace gdata |
| OLD | NEW |