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 <leveldb/db.h> | 7 #include <leveldb/db.h> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 LOG(ERROR) << "Incompatible proto detected (bad resource ID): " | 59 LOG(ERROR) << "Incompatible proto detected (bad resource ID): " |
60 << entry_proto.resource_id(); | 60 << entry_proto.resource_id(); |
61 return false; | 61 return false; |
62 } | 62 } |
63 | 63 |
64 return true; | 64 return true; |
65 } | 65 } |
66 | 66 |
67 } // namespace | 67 } // namespace |
68 | 68 |
| 69 EntryInfoResult::EntryInfoResult() : error(GDATA_FILE_ERROR_FAILED) { |
| 70 } |
| 71 |
| 72 EntryInfoResult::~EntryInfoResult() { |
| 73 } |
| 74 |
| 75 EntryInfoPairResult::EntryInfoPairResult() { |
| 76 } |
| 77 |
| 78 EntryInfoPairResult::~EntryInfoPairResult() { |
| 79 } |
| 80 |
69 // GDataEntry class. | 81 // GDataEntry class. |
70 | 82 |
71 GDataEntry::GDataEntry(GDataDirectory* parent, | 83 GDataEntry::GDataEntry(GDataDirectory* parent, |
72 GDataDirectoryService* directory_service) | 84 GDataDirectoryService* directory_service) |
73 : directory_service_(directory_service), | 85 : directory_service_(directory_service), |
74 deleted_(false) { | 86 deleted_(false) { |
75 SetParent(parent); | 87 SetParent(parent); |
76 } | 88 } |
77 | 89 |
78 GDataEntry::~GDataEntry() { | 90 GDataEntry::~GDataEntry() { |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; | 703 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; |
692 } else { | 704 } else { |
693 error = GDATA_FILE_ERROR_NOT_FOUND; | 705 error = GDATA_FILE_ERROR_NOT_FOUND; |
694 } | 706 } |
695 | 707 |
696 base::MessageLoopProxy::current()->PostTask( | 708 base::MessageLoopProxy::current()->PostTask( |
697 FROM_HERE, | 709 FROM_HERE, |
698 base::Bind(callback, error, base::Passed(&entries))); | 710 base::Bind(callback, error, base::Passed(&entries))); |
699 } | 711 } |
700 | 712 |
| 713 void GDataDirectoryService::GetEntryInfoPairByPaths( |
| 714 const FilePath& first_path, |
| 715 const FilePath& second_path, |
| 716 const GetEntryInfoPairCallback& callback) { |
| 717 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 718 DCHECK(!callback.is_null()); |
| 719 |
| 720 // Get the first entry. |
| 721 GetEntryInfoByPath( |
| 722 first_path, |
| 723 base::Bind(&GDataDirectoryService::GetEntryInfoPairByPathsAfterGetFirst, |
| 724 weak_ptr_factory_.GetWeakPtr(), |
| 725 first_path, |
| 726 second_path, |
| 727 callback)); |
| 728 } |
| 729 |
701 void GDataDirectoryService::RefreshFile(scoped_ptr<GDataFile> fresh_file) { | 730 void GDataDirectoryService::RefreshFile(scoped_ptr<GDataFile> fresh_file) { |
702 DCHECK(fresh_file.get()); | 731 DCHECK(fresh_file.get()); |
703 | 732 |
704 // Need to get a reference here because Passed() could get evaluated first. | 733 // Need to get a reference here because Passed() could get evaluated first. |
705 const std::string& resource_id = fresh_file->resource_id(); | 734 const std::string& resource_id = fresh_file->resource_id(); |
706 GetEntryByResourceIdAsync( | 735 GetEntryByResourceIdAsync( |
707 resource_id, | 736 resource_id, |
708 base::Bind(&GDataDirectoryService::RefreshFileInternal, | 737 base::Bind(&GDataDirectoryService::RefreshFileInternal, |
709 base::Passed(&fresh_file))); | 738 base::Passed(&fresh_file))); |
710 } | 739 } |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 // Call GDataFile::FromProto. | 1166 // Call GDataFile::FromProto. |
1138 if (file->FromProto(entry_proto)) { | 1167 if (file->FromProto(entry_proto)) { |
1139 entry.reset(file.release()); | 1168 entry.reset(file.release()); |
1140 } else { | 1169 } else { |
1141 NOTREACHED() << "FromProto (file) failed"; | 1170 NOTREACHED() << "FromProto (file) failed"; |
1142 } | 1171 } |
1143 } | 1172 } |
1144 return entry.Pass(); | 1173 return entry.Pass(); |
1145 } | 1174 } |
1146 | 1175 |
| 1176 void GDataDirectoryService::GetEntryInfoPairByPathsAfterGetFirst( |
| 1177 const FilePath& first_path, |
| 1178 const FilePath& second_path, |
| 1179 const GetEntryInfoPairCallback& callback, |
| 1180 GDataFileError error, |
| 1181 scoped_ptr<GDataEntryProto> entry_proto) { |
| 1182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1183 DCHECK(!callback.is_null()); |
| 1184 |
| 1185 scoped_ptr<EntryInfoPairResult> result(new EntryInfoPairResult); |
| 1186 result->first.path = first_path; |
| 1187 result->first.error = error; |
| 1188 result->first.proto = entry_proto.Pass(); |
| 1189 |
| 1190 // If the first one is not found, don't continue. |
| 1191 if (error != GDATA_FILE_OK) { |
| 1192 callback.Run(result.Pass()); |
| 1193 return; |
| 1194 } |
| 1195 |
| 1196 // Get the second entry. |
| 1197 GetEntryInfoByPath( |
| 1198 second_path, |
| 1199 base::Bind(&GDataDirectoryService::GetEntryInfoPairByPathsAfterGetSecond, |
| 1200 weak_ptr_factory_.GetWeakPtr(), |
| 1201 second_path, |
| 1202 callback, |
| 1203 base::Passed(&result))); |
| 1204 } |
| 1205 |
| 1206 void GDataDirectoryService::GetEntryInfoPairByPathsAfterGetSecond( |
| 1207 const FilePath& second_path, |
| 1208 const GetEntryInfoPairCallback& callback, |
| 1209 scoped_ptr<EntryInfoPairResult> result, |
| 1210 GDataFileError error, |
| 1211 scoped_ptr<GDataEntryProto> entry_proto) { |
| 1212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1213 DCHECK(!callback.is_null()); |
| 1214 DCHECK(result.get()); |
| 1215 |
| 1216 result->second.path = second_path; |
| 1217 result->second.error = error; |
| 1218 result->second.proto = entry_proto.Pass(); |
| 1219 |
| 1220 callback.Run(result.Pass()); |
| 1221 } |
| 1222 |
1147 } // namespace gdata | 1223 } // namespace gdata |
OLD | NEW |