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_file_system.h" | 5 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1060 | 1060 |
1061 documents_service_->CopyDocument(resource_id, new_name, | 1061 documents_service_->CopyDocument(resource_id, new_name, |
1062 base::Bind(&GDataFileSystem::OnCopyDocumentCompleted, | 1062 base::Bind(&GDataFileSystem::OnCopyDocumentCompleted, |
1063 ui_weak_ptr_, | 1063 ui_weak_ptr_, |
1064 dir_path, | 1064 dir_path, |
1065 callback)); | 1065 callback)); |
1066 } | 1066 } |
1067 | 1067 |
1068 void GDataFileSystem::Rename(const FilePath& file_path, | 1068 void GDataFileSystem::Rename(const FilePath& file_path, |
1069 const FilePath::StringType& new_name, | 1069 const FilePath::StringType& new_name, |
1070 const FilePathUpdateCallback& callback) { | 1070 const FileMoveCallback& callback) { |
1071 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1071 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1072 | 1072 |
1073 // It is a no-op if the file is renamed to the same name. | 1073 // It is a no-op if the file is renamed to the same name. |
1074 if (file_path.BaseName().value() == new_name) { | 1074 if (file_path.BaseName().value() == new_name) { |
1075 if (!callback.is_null()) { | 1075 if (!callback.is_null()) { |
1076 MessageLoop::current()->PostTask( | 1076 MessageLoop::current()->PostTask( |
1077 FROM_HERE, base::Bind(callback, GDATA_FILE_OK, file_path)); | 1077 FROM_HERE, base::Bind(callback, GDATA_FILE_OK, file_path)); |
1078 } | 1078 } |
1079 return; | 1079 return; |
1080 } | 1080 } |
1081 | 1081 |
1082 // Get the edit URL of an entry at |file_path|. | 1082 // Get the edit URL of an entry at |file_path|. |
1083 directory_service_->GetEntryInfoByPath( | 1083 directory_service_->GetEntryInfoByPath( |
1084 file_path, | 1084 file_path, |
1085 base::Bind( | 1085 base::Bind( |
1086 &GDataFileSystem::RenameAfterGetEntryInfo, | 1086 &GDataFileSystem::RenameAfterGetEntryInfo, |
1087 ui_weak_ptr_, | 1087 ui_weak_ptr_, |
1088 file_path, | 1088 file_path, |
1089 new_name, | 1089 new_name, |
1090 callback)); | 1090 callback)); |
1091 } | 1091 } |
1092 | 1092 |
1093 void GDataFileSystem::RenameAfterGetEntryInfo( | 1093 void GDataFileSystem::RenameAfterGetEntryInfo( |
1094 const FilePath& file_path, | 1094 const FilePath& file_path, |
1095 const FilePath::StringType& new_name, | 1095 const FilePath::StringType& new_name, |
1096 const FilePathUpdateCallback& callback, | 1096 const FileMoveCallback& callback, |
1097 GDataFileError error, | 1097 GDataFileError error, |
1098 scoped_ptr<GDataEntryProto> entry_proto) { | 1098 scoped_ptr<GDataEntryProto> entry_proto) { |
1099 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1099 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1100 | 1100 |
1101 if (error != GDATA_FILE_OK) { | 1101 if (error != GDATA_FILE_OK) { |
1102 if (!callback.is_null()) | 1102 if (!callback.is_null()) |
1103 callback.Run(error, file_path); | 1103 callback.Run(error, file_path); |
1104 return; | 1104 return; |
1105 } | 1105 } |
1106 DCHECK(entry_proto.get()); | 1106 DCHECK(entry_proto.get()); |
1107 | 1107 |
1108 // Drop the .g<something> extension from |new_name| if the file being | 1108 // Drop the .g<something> extension from |new_name| if the file being |
1109 // renamed is a hosted document and |new_name| has the same .g<something> | 1109 // renamed is a hosted document and |new_name| has the same .g<something> |
1110 // extension as the file. | 1110 // extension as the file. |
1111 FilePath::StringType file_name = new_name; | 1111 FilePath::StringType file_name = new_name; |
1112 if (entry_proto->has_file_specific_info() && | 1112 if (entry_proto->has_file_specific_info() && |
1113 entry_proto->file_specific_info().is_hosted_document()) { | 1113 entry_proto->file_specific_info().is_hosted_document()) { |
1114 FilePath new_file(file_name); | 1114 FilePath new_file(file_name); |
1115 if (new_file.Extension() == | 1115 if (new_file.Extension() == |
1116 entry_proto->file_specific_info().document_extension()) { | 1116 entry_proto->file_specific_info().document_extension()) { |
1117 file_name = new_file.RemoveExtension().value(); | 1117 file_name = new_file.RemoveExtension().value(); |
1118 } | 1118 } |
1119 } | 1119 } |
1120 | 1120 |
1121 documents_service_->RenameResource( | 1121 documents_service_->RenameResource( |
1122 GURL(entry_proto->edit_url()), | 1122 GURL(entry_proto->edit_url()), |
1123 file_name, | 1123 file_name, |
1124 base::Bind(&GDataFileSystem::OnRenameResourceCompleted, | 1124 base::Bind(&GDataFileSystem::RenameFileOnFileSystem, |
1125 ui_weak_ptr_, | 1125 ui_weak_ptr_, |
1126 file_path, | 1126 file_path, |
1127 file_name, | 1127 file_name, |
1128 callback)); | 1128 callback)); |
1129 } | 1129 } |
1130 | 1130 |
1131 void GDataFileSystem::Move(const FilePath& src_file_path, | 1131 void GDataFileSystem::Move(const FilePath& src_file_path, |
1132 const FilePath& dest_file_path, | 1132 const FilePath& dest_file_path, |
1133 const FileOperationCallback& callback) { | 1133 const FileOperationCallback& callback) { |
1134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
(...skipping 26 matching lines...) Expand all Loading... | |
1161 if (error != GDATA_FILE_OK) { | 1161 if (error != GDATA_FILE_OK) { |
1162 if (!callback.is_null()) { | 1162 if (!callback.is_null()) { |
1163 MessageLoop::current()->PostTask(FROM_HERE, | 1163 MessageLoop::current()->PostTask(FROM_HERE, |
1164 base::Bind(callback, error)); | 1164 base::Bind(callback, error)); |
1165 } | 1165 } |
1166 return; | 1166 return; |
1167 } | 1167 } |
1168 | 1168 |
1169 // If the file/directory is moved to the same directory, just rename it. | 1169 // If the file/directory is moved to the same directory, just rename it. |
1170 if (src_file_path.DirName() == dest_parent_path) { | 1170 if (src_file_path.DirName() == dest_parent_path) { |
1171 FilePathUpdateCallback final_file_path_update_callback = | 1171 FileMoveCallback final_file_path_update_callback = |
1172 base::Bind(&GDataFileSystem::OnFilePathUpdated, | 1172 base::Bind(&GDataFileSystem::OnFilePathUpdated, |
1173 ui_weak_ptr_, | 1173 ui_weak_ptr_, |
1174 callback); | 1174 callback); |
1175 | 1175 |
1176 Rename(src_file_path, dest_file_path.BaseName().value(), | 1176 Rename(src_file_path, dest_file_path.BaseName().value(), |
1177 final_file_path_update_callback); | 1177 final_file_path_update_callback); |
1178 return; | 1178 return; |
1179 } | 1179 } |
1180 | 1180 |
1181 // Otherwise, the move operation involves three steps: | 1181 // Otherwise, the move operation involves three steps: |
1182 // 1. Renames the file at |src_file_path| to basename(|dest_file_path|) | 1182 // 1. Renames the file at |src_file_path| to basename(|dest_file_path|) |
1183 // within the same directory. The rename operation is a no-op if | 1183 // within the same directory. The rename operation is a no-op if |
1184 // basename(|src_file_path|) equals to basename(|dest_file_path|). | 1184 // basename(|src_file_path|) equals to basename(|dest_file_path|). |
1185 // 2. Removes the file from its parent directory (the file is not deleted), | 1185 // 2. Removes the file from its parent directory (the file is not deleted), |
1186 // which effectively moves the file to the root directory. | 1186 // which effectively moves the file to the root directory. |
1187 // 3. Adds the file to the parent directory of |dest_file_path|, which | 1187 // 3. Adds the file to the parent directory of |dest_file_path|, which |
1188 // effectively moves the file from the root directory to the parent | 1188 // effectively moves the file from the root directory to the parent |
1189 // directory of |dest_file_path|. | 1189 // directory of |dest_file_path|. |
1190 FilePathUpdateCallback add_file_to_directory_callback = | 1190 FileMoveCallback add_file_to_directory_callback = |
1191 base::Bind(&GDataFileSystem::AddEntryToDirectory, | 1191 base::Bind(&GDataFileSystem::AddEntryToDirectory, |
1192 ui_weak_ptr_, | 1192 ui_weak_ptr_, |
1193 dest_file_path.DirName(), | 1193 dest_file_path.DirName(), |
1194 callback); | 1194 callback); |
1195 | 1195 |
1196 FilePathUpdateCallback remove_file_from_directory_callback = | 1196 FileMoveCallback remove_file_from_directory_callback = |
1197 base::Bind(&GDataFileSystem::RemoveEntryFromDirectory, | 1197 base::Bind(&GDataFileSystem::RemoveEntryFromDirectory, |
1198 ui_weak_ptr_, | 1198 ui_weak_ptr_, |
1199 src_file_path.DirName(), | 1199 src_file_path.DirName(), |
1200 add_file_to_directory_callback); | 1200 add_file_to_directory_callback); |
1201 | 1201 |
1202 Rename(src_file_path, dest_file_path.BaseName().value(), | 1202 Rename(src_file_path, dest_file_path.BaseName().value(), |
1203 remove_file_from_directory_callback); | 1203 remove_file_from_directory_callback); |
1204 } | 1204 } |
1205 | 1205 |
1206 void GDataFileSystem::AddEntryToDirectory( | 1206 void GDataFileSystem::AddEntryToDirectory( |
(...skipping 28 matching lines...) Expand all Loading... | |
1235 entry->edit_url(), | 1235 entry->edit_url(), |
1236 base::Bind(&GDataFileSystem::OnAddEntryToDirectoryCompleted, | 1236 base::Bind(&GDataFileSystem::OnAddEntryToDirectoryCompleted, |
1237 ui_weak_ptr_, | 1237 ui_weak_ptr_, |
1238 callback, | 1238 callback, |
1239 file_path, | 1239 file_path, |
1240 dir_path)); | 1240 dir_path)); |
1241 } | 1241 } |
1242 | 1242 |
1243 void GDataFileSystem::RemoveEntryFromDirectory( | 1243 void GDataFileSystem::RemoveEntryFromDirectory( |
1244 const FilePath& dir_path, | 1244 const FilePath& dir_path, |
1245 const FilePathUpdateCallback& callback, | 1245 const FileMoveCallback& callback, |
1246 GDataFileError error, | 1246 GDataFileError error, |
1247 const FilePath& file_path) { | 1247 const FilePath& file_path) { |
1248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1249 | 1249 |
1250 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); | 1250 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); |
1251 GDataEntry* dir = directory_service_->FindEntryByPathSync(dir_path); | 1251 GDataEntry* dir = directory_service_->FindEntryByPathSync(dir_path); |
1252 if (error == GDATA_FILE_OK) { | 1252 if (error == GDATA_FILE_OK) { |
1253 if (!entry || !dir) { | 1253 if (!entry || !dir) { |
1254 error = GDATA_FILE_ERROR_NOT_FOUND; | 1254 error = GDATA_FILE_ERROR_NOT_FOUND; |
1255 } else { | 1255 } else { |
1256 if (!dir->AsGDataDirectory()) | 1256 if (!dir->AsGDataDirectory()) |
1257 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; | 1257 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY; |
1258 } | 1258 } |
1259 } | 1259 } |
1260 | 1260 |
1261 // Returns if there is an error or |dir_path| is the root directory. | 1261 // Returns if there is an error or |dir_path| is the root directory. |
1262 if (error != GDATA_FILE_OK || | 1262 if (error != GDATA_FILE_OK || |
1263 dir->resource_id() == kGDataRootDirectoryResourceId) { | 1263 dir->resource_id() == kGDataRootDirectoryResourceId) { |
1264 if (!callback.is_null()) { | 1264 if (!callback.is_null()) { |
1265 MessageLoop::current()->PostTask(FROM_HERE, | 1265 MessageLoop::current()->PostTask(FROM_HERE, |
1266 base::Bind(callback, error, file_path)); | 1266 base::Bind(callback, error, file_path)); |
1267 } | 1267 } |
1268 return; | 1268 return; |
1269 } | 1269 } |
1270 | 1270 |
1271 documents_service_->RemoveResourceFromDirectory( | 1271 documents_service_->RemoveResourceFromDirectory( |
1272 dir->content_url(), | 1272 dir->content_url(), |
1273 entry->edit_url(), | 1273 entry->edit_url(), |
1274 entry->resource_id(), | 1274 entry->resource_id(), |
1275 base::Bind(&GDataFileSystem::OnRemoveEntryFromDirectoryCompleted, | 1275 base::Bind(&GDataFileSystem::RemoveEntryFromDirectoryOnFileSystem, |
1276 ui_weak_ptr_, | 1276 ui_weak_ptr_, |
1277 callback, | 1277 callback, |
1278 file_path, | 1278 file_path, |
1279 dir_path)); | 1279 dir_path)); |
1280 } | 1280 } |
1281 | 1281 |
1282 void GDataFileSystem::Remove(const FilePath& file_path, | 1282 void GDataFileSystem::Remove(const FilePath& file_path, |
1283 bool is_recursive, | 1283 bool is_recursive, |
1284 const FileOperationCallback& callback) { | 1284 const FileOperationCallback& callback) { |
1285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1996 scoped_ptr<GDataEntry> entry(it->second); | 1996 scoped_ptr<GDataEntry> entry(it->second); |
1997 // Skip if it's not a file (i.e. directory). | 1997 // Skip if it's not a file (i.e. directory). |
1998 if (!entry->AsGDataFile()) | 1998 if (!entry->AsGDataFile()) |
1999 continue; | 1999 continue; |
2000 directory->AddEntry(entry.release()); | 2000 directory->AddEntry(entry.release()); |
2001 } | 2001 } |
2002 | 2002 |
2003 // Note that there may be no change in the directory, but it's expensive to | 2003 // Note that there may be no change in the directory, but it's expensive to |
2004 // check if the new metadata matches the existing one, so we just always | 2004 // check if the new metadata matches the existing one, so we just always |
2005 // notify that the directory is changed. | 2005 // notify that the directory is changed. |
2006 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, | 2006 OnDirectoryChanged(directory_path); |
2007 observers_, OnDirectoryChanged(directory_path)); | |
2008 DVLOG(1) << "Directory refreshed: " << directory_path.value(); | 2007 DVLOG(1) << "Directory refreshed: " << directory_path.value(); |
2009 } | 2008 } |
2010 | 2009 |
2011 void GDataFileSystem::UpdateFileByResourceId( | 2010 void GDataFileSystem::UpdateFileByResourceId( |
2012 const std::string& resource_id, | 2011 const std::string& resource_id, |
2013 const FileOperationCallback& callback) { | 2012 const FileOperationCallback& callback) { |
2014 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2013 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
2015 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2014 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2016 RunTaskOnUIThread( | 2015 RunTaskOnUIThread( |
2017 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread, | 2016 base::Bind(&GDataFileSystem::UpdateFileByResourceIdOnUIThread, |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2388 int root_feed_changestamp) { | 2387 int root_feed_changestamp) { |
2389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2388 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2390 | 2389 |
2391 return feed_loader_->UpdateFromFeed(feed_list, | 2390 return feed_loader_->UpdateFromFeed(feed_list, |
2392 start_changestamp, | 2391 start_changestamp, |
2393 root_feed_changestamp); | 2392 root_feed_changestamp); |
2394 } | 2393 } |
2395 | 2394 |
2396 void GDataFileSystem::OnFilePathUpdated(const FileOperationCallback& callback, | 2395 void GDataFileSystem::OnFilePathUpdated(const FileOperationCallback& callback, |
2397 GDataFileError error, | 2396 GDataFileError error, |
2398 const FilePath& file_path) { | 2397 const FilePath& /* file_path */) { |
2399 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2400 if (!callback.is_null()) | 2399 if (!callback.is_null()) |
2401 callback.Run(error); | 2400 callback.Run(error); |
2402 } | 2401 } |
2403 | 2402 |
2404 void GDataFileSystem::OnRenameResourceCompleted( | |
2405 const FilePath& file_path, | |
2406 const FilePath::StringType& new_name, | |
2407 const FilePathUpdateCallback& callback, | |
2408 GDataErrorCode status, | |
2409 const GURL& document_url) { | |
2410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
2411 | |
2412 FilePath updated_file_path; | |
2413 GDataFileError error = util::GDataToGDataFileError(status); | |
2414 if (error == GDATA_FILE_OK) | |
2415 error = RenameFileOnFilesystem(file_path, new_name, &updated_file_path); | |
2416 | |
2417 if (!callback.is_null()) | |
2418 callback.Run(error, updated_file_path); | |
2419 } | |
2420 | |
2421 void GDataFileSystem::OnCopyDocumentCompleted( | 2403 void GDataFileSystem::OnCopyDocumentCompleted( |
2422 const FilePath& dir_path, | 2404 const FilePath& dir_path, |
2423 const FileOperationCallback& callback, | 2405 const FileOperationCallback& callback, |
2424 GDataErrorCode status, | 2406 GDataErrorCode status, |
2425 scoped_ptr<base::Value> data) { | 2407 scoped_ptr<base::Value> data) { |
2426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2408 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2427 | 2409 |
2428 GDataFileError error = util::GDataToGDataFileError(status); | 2410 GDataFileError error = util::GDataToGDataFileError(status); |
2429 if (error != GDATA_FILE_OK) { | 2411 if (error != GDATA_FILE_OK) { |
2430 if (!callback.is_null()) | 2412 if (!callback.is_null()) |
2431 callback.Run(error); | 2413 callback.Run(error); |
2432 | 2414 |
2433 return; | 2415 return; |
2434 } | 2416 } |
2435 | 2417 |
2436 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); | 2418 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); |
2437 if (!doc_entry.get()) { | 2419 if (!doc_entry.get()) { |
2438 if (!callback.is_null()) | 2420 if (!callback.is_null()) |
2439 callback.Run(GDATA_FILE_ERROR_FAILED); | 2421 callback.Run(GDATA_FILE_ERROR_FAILED); |
2440 | 2422 |
2441 return; | 2423 return; |
2442 } | 2424 } |
2443 | 2425 |
2444 GDataEntry* entry = GDataEntry::FromDocumentEntry( | 2426 GDataEntry* entry = GDataEntry::FromDocumentEntry( |
2445 directory_service_->root(), doc_entry.get(), directory_service_.get()); | 2427 NULL, doc_entry.get(), directory_service_.get()); |
2446 if (!entry) { | 2428 if (!entry) { |
2447 if (!callback.is_null()) | 2429 if (!callback.is_null()) |
2448 callback.Run(GDATA_FILE_ERROR_FAILED); | 2430 callback.Run(GDATA_FILE_ERROR_FAILED); |
2449 | 2431 |
2450 return; | 2432 return; |
2451 } | 2433 } |
2452 | 2434 |
2453 // |entry| was added in the root directory on the server, so we should | 2435 // |entry| was added in the root directory on the server, so we should |
2454 // first add it to |root_| to mirror the state and then move it to the | 2436 // first add it to |root_| to mirror the state and then move it to the |
2455 // destination directory by AddEntryToDirectory(). | 2437 // destination directory by AddEntryToDirectory(). |
2456 directory_service_->root()->AddEntry(entry); | 2438 directory_service_->root()->AddEntry(entry); |
2457 AddEntryToDirectory(dir_path, callback, GDATA_FILE_OK, entry->GetFilePath()); | 2439 AddEntryToDirectory(dir_path, callback, GDATA_FILE_OK, entry->GetFilePath()); |
2458 } | 2440 } |
2459 | 2441 |
2460 void GDataFileSystem::OnAddEntryToDirectoryCompleted( | 2442 void GDataFileSystem::OnAddEntryToDirectoryCompleted( |
2461 const FileOperationCallback& callback, | 2443 const FileOperationCallback& callback, |
2462 const FilePath& file_path, | 2444 const FilePath& file_path, |
2463 const FilePath& dir_path, | 2445 const FilePath& dir_path, |
2464 GDataErrorCode status, | 2446 GDataErrorCode status, |
2465 const GURL& document_url) { | 2447 const GURL& document_url) { |
2466 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2448 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2467 | 2449 |
2468 GDataFileError error = util::GDataToGDataFileError(status); | 2450 GDataFileError error = util::GDataToGDataFileError(status); |
2469 if (error == GDATA_FILE_OK) { | 2451 if (error == GDATA_FILE_OK) { |
2470 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); | 2452 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); |
2471 if (entry) { | 2453 if (entry) { |
2472 DCHECK_EQ(directory_service_->root(), entry->parent()); | 2454 DCHECK_EQ(directory_service_->root(), entry->parent()); |
2473 error = AddEntryToDirectoryOnFilesystem(entry, dir_path); | 2455 directory_service_->MoveEntryToDirectory(dir_path, entry, |
2456 base::Bind( | |
2457 &GDataFileSystem::OnMoveEntryToDirectoryWithFileOperationCallback, | |
2458 ui_weak_ptr_, | |
2459 callback)); | |
2460 return; | |
2474 } else { | 2461 } else { |
2475 error = GDATA_FILE_ERROR_NOT_FOUND; | 2462 error = GDATA_FILE_ERROR_NOT_FOUND; |
2476 } | 2463 } |
2477 } | 2464 } |
2478 | 2465 |
2479 if (!callback.is_null()) | 2466 if (!callback.is_null()) |
2480 callback.Run(error); | 2467 callback.Run(error); |
2481 } | 2468 } |
2482 | 2469 |
2483 void GDataFileSystem::OnRemoveEntryFromDirectoryCompleted( | |
2484 const FilePathUpdateCallback& callback, | |
2485 const FilePath& file_path, | |
2486 const FilePath& dir_path, | |
2487 GDataErrorCode status, | |
2488 const GURL& document_url) { | |
2489 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
2490 | |
2491 FilePath updated_file_path = file_path; | |
2492 GDataFileError error = util::GDataToGDataFileError(status); | |
2493 if (error == GDATA_FILE_OK) | |
2494 error = RemoveEntryFromDirectoryOnFilesystem(file_path, dir_path, | |
2495 &updated_file_path); | |
2496 | |
2497 if (!callback.is_null()) | |
2498 callback.Run(error, updated_file_path); | |
2499 } | |
2500 | |
2501 void GDataFileSystem::OnRemovedDocument( | 2470 void GDataFileSystem::OnRemovedDocument( |
2502 const FileOperationCallback& callback, | 2471 const FileOperationCallback& callback, |
2503 const FilePath& file_path, | 2472 const FilePath& file_path, |
2504 GDataErrorCode status, | 2473 GDataErrorCode status, |
2505 const GURL& document_url) { | 2474 const GURL& document_url) { |
2506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2475 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2507 | 2476 |
2508 GDataFileError error = util::GDataToGDataFileError(status); | 2477 GDataFileError error = util::GDataToGDataFileError(status); |
2509 | 2478 |
2510 if (error == GDATA_FILE_OK) | 2479 if (error == GDATA_FILE_OK) |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2614 } | 2583 } |
2615 } | 2584 } |
2616 | 2585 |
2617 void GDataFileSystem::OnDownloadStoredToCache(GDataFileError error, | 2586 void GDataFileSystem::OnDownloadStoredToCache(GDataFileError error, |
2618 const std::string& resource_id, | 2587 const std::string& resource_id, |
2619 const std::string& md5) { | 2588 const std::string& md5) { |
2620 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2589 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2621 // Nothing much to do here for now. | 2590 // Nothing much to do here for now. |
2622 } | 2591 } |
2623 | 2592 |
2624 GDataFileError GDataFileSystem::RenameFileOnFilesystem( | 2593 void GDataFileSystem::RenameFileOnFileSystem( |
2625 const FilePath& file_path, | 2594 const FilePath& file_path, |
2626 const FilePath::StringType& new_name, | 2595 const FilePath::StringType& new_name, |
2627 FilePath* updated_file_path) { | 2596 const FileMoveCallback& callback, |
2597 GDataErrorCode status, | |
2598 const GURL& document_url) { | |
2628 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2599 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2629 DCHECK(updated_file_path); | 2600 |
2601 const GDataFileError error = util::GDataToGDataFileError(status); | |
2602 if (error != GDATA_FILE_OK) { | |
2603 if (!callback.is_null()) | |
2604 callback.Run(error, FilePath()); | |
2605 return; | |
2606 } | |
2630 | 2607 |
2631 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); | 2608 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); |
2632 if (!entry) | 2609 if (!entry) { |
2633 return GDATA_FILE_ERROR_NOT_FOUND; | 2610 if (!callback.is_null()) |
2611 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath()); | |
2612 return; | |
2613 } | |
2634 | 2614 |
2635 DCHECK(entry->parent()); | 2615 DCHECK(entry->parent()); |
2636 entry->set_title(new_name); | 2616 entry->set_title(new_name); |
2637 // After changing the title of the entry, call TakeFile() to remove the | 2617 // After changing the title of the entry, call MoveEntryToDirectory() to |
2638 // entry from its parent directory and then add it back in order to go | 2618 // remove the entry from its parent directory and then add it back in order to |
2639 // through the file name de-duplication. | 2619 // go through the file name de-duplication. |
2640 // TODO(achuith/satorux/zel): This code is fragile. The title has been | 2620 // TODO(achuith/satorux/zel): This code is fragile. The title has been |
2641 // changed, but not the file_name. TakeEntry removes the child based on the | 2621 // changed, but not the file_name. MoveEntryToDirectory calls RemoveChild to |
2642 // old file_name, and then re-adds the child by first assigning the new title | 2622 // remove the child based on the old file_name, and then re-adds the child by |
2643 // to file_name. http://crbug.com/30157 | 2623 // first assigning the new title to file_name. http://crbug.com/30157 |
2644 if (!entry->parent()->TakeEntry(entry)) | 2624 directory_service_->MoveEntryToDirectory( |
2645 return GDATA_FILE_ERROR_FAILED; | 2625 entry->parent()->GetFilePath(), |
2646 | 2626 entry, |
2647 *updated_file_path = entry->GetFilePath(); | 2627 base::Bind(&GDataFileSystem::OnMoveEntryToDirectoryWithFileMoveCallback, |
2648 | 2628 ui_weak_ptr_, |
2649 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2629 callback)); |
2650 OnDirectoryChanged(updated_file_path->DirName())); | |
2651 return GDATA_FILE_OK; | |
2652 } | 2630 } |
2653 | 2631 |
2654 GDataFileError GDataFileSystem::AddEntryToDirectoryOnFilesystem( | 2632 void GDataFileSystem::RemoveEntryFromDirectoryOnFileSystem( |
2655 GDataEntry* entry, const FilePath& dir_path) { | 2633 const FileMoveCallback& callback, |
2634 const FilePath& file_path, | |
2635 const FilePath& dir_path, | |
2636 GDataErrorCode status, | |
2637 const GURL& document_url) { | |
2656 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2638 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2657 DCHECK(entry); | |
2658 | 2639 |
2659 GDataEntry* dir_entry = directory_service_->FindEntryByPathSync(dir_path); | 2640 const GDataFileError error = util::GDataToGDataFileError(status); |
2660 if (!dir_entry) | 2641 if (error != GDATA_FILE_OK) { |
2661 return GDATA_FILE_ERROR_NOT_FOUND; | 2642 if (!callback.is_null()) |
2643 callback.Run(error, FilePath()); | |
2644 return; | |
2645 } | |
2662 | 2646 |
2663 GDataDirectory* dir = dir_entry->AsGDataDirectory(); | 2647 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); |
2664 if (!dir) | 2648 if (!entry) { |
2665 return GDATA_FILE_ERROR_NOT_A_DIRECTORY; | 2649 if (!callback.is_null()) |
2650 callback.Run(GDATA_FILE_ERROR_NOT_FOUND, FilePath()); | |
2651 return; | |
2652 } | |
2666 | 2653 |
2667 if (!dir->TakeEntry(entry)) | 2654 directory_service_->MoveEntryToDirectory( |
2668 return GDATA_FILE_ERROR_FAILED; | 2655 directory_service_->root()->GetFilePath(), |
2669 | 2656 entry, |
2670 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2657 base::Bind(&GDataFileSystem::OnMoveEntryToDirectoryWithFileMoveCallback, |
2671 OnDirectoryChanged(dir_path)); | 2658 ui_weak_ptr_, |
2672 return GDATA_FILE_OK; | 2659 callback)); |
2673 } | 2660 } |
2674 | 2661 |
2675 GDataFileError GDataFileSystem::RemoveEntryFromDirectoryOnFilesystem( | 2662 void GDataFileSystem::OnMoveEntryToDirectoryWithFileMoveCallback( |
2676 const FilePath& file_path, const FilePath& dir_path, | 2663 const FileMoveCallback& callback, |
2677 FilePath* updated_file_path) { | 2664 GDataFileError error, |
2678 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2665 const FilePath& moved_file_path) { |
2679 DCHECK(updated_file_path); | 2666 if (error == GDATA_FILE_OK) |
2667 OnDirectoryChanged(moved_file_path.DirName()); | |
2680 | 2668 |
2681 GDataEntry* entry = directory_service_->FindEntryByPathSync(file_path); | 2669 if (!callback.is_null()) |
2682 if (!entry) | 2670 callback.Run(error, moved_file_path); |
2683 return GDATA_FILE_ERROR_NOT_FOUND; | 2671 } |
2684 | 2672 |
2685 GDataEntry* dir = directory_service_->FindEntryByPathSync(dir_path); | 2673 void GDataFileSystem::OnMoveEntryToDirectoryWithFileOperationCallback( |
satorux1
2012/08/10 21:04:16
The two callers of FindEntryByPathSync() were remo
| |
2686 if (!dir) | 2674 const FileOperationCallback& callback, |
2687 return GDATA_FILE_ERROR_NOT_FOUND; | 2675 GDataFileError error, |
2676 const FilePath& moved_file_path) { | |
2677 if (error == GDATA_FILE_OK) | |
2678 OnDirectoryChanged(moved_file_path.DirName()); | |
2688 | 2679 |
2689 if (!dir->AsGDataDirectory()) | 2680 if (!callback.is_null()) |
2690 return GDATA_FILE_ERROR_NOT_A_DIRECTORY; | 2681 callback.Run(error); |
2691 | |
2692 DCHECK_EQ(dir->AsGDataDirectory(), entry->parent()); | |
2693 | |
2694 if (!directory_service_->root()->TakeEntry(entry)) | |
2695 return GDATA_FILE_ERROR_FAILED; | |
2696 | |
2697 *updated_file_path = entry->GetFilePath(); | |
2698 | |
2699 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | |
2700 OnDirectoryChanged(updated_file_path->DirName())); | |
2701 return GDATA_FILE_OK; | |
2702 } | 2682 } |
2703 | 2683 |
2704 GDataFileError GDataFileSystem::RemoveEntryFromFileSystem( | 2684 GDataFileError GDataFileSystem::RemoveEntryFromFileSystem( |
2705 const FilePath& file_path) { | 2685 const FilePath& file_path) { |
2706 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2686 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2707 | 2687 |
2708 std::string resource_id; | 2688 std::string resource_id; |
2709 GDataFileError error = RemoveEntryFromGData(file_path, &resource_id); | 2689 GDataFileError error = RemoveEntryFromGData(file_path, &resource_id); |
2710 if (error != GDATA_FILE_OK) | 2690 if (error != GDATA_FILE_OK) |
2711 return error; | 2691 return error; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2782 return GDATA_FILE_ERROR_FAILED; | 2762 return GDATA_FILE_ERROR_FAILED; |
2783 | 2763 |
2784 // Check if parent is a directory since in theory since this is a callback | 2764 // Check if parent is a directory since in theory since this is a callback |
2785 // something could in the meantime have nuked the parent dir and created a | 2765 // something could in the meantime have nuked the parent dir and created a |
2786 // file with the exact same name. | 2766 // file with the exact same name. |
2787 GDataDirectory* parent_dir = entry->AsGDataDirectory(); | 2767 GDataDirectory* parent_dir = entry->AsGDataDirectory(); |
2788 if (!parent_dir) | 2768 if (!parent_dir) |
2789 return GDATA_FILE_ERROR_FAILED; | 2769 return GDATA_FILE_ERROR_FAILED; |
2790 | 2770 |
2791 GDataEntry* new_entry = GDataEntry::FromDocumentEntry( | 2771 GDataEntry* new_entry = GDataEntry::FromDocumentEntry( |
2792 parent_dir, doc_entry.get(), directory_service_.get()); | 2772 NULL, doc_entry.get(), directory_service_.get()); |
2793 if (!new_entry) | 2773 if (!new_entry) |
2794 return GDATA_FILE_ERROR_FAILED; | 2774 return GDATA_FILE_ERROR_FAILED; |
2795 | 2775 |
2796 parent_dir->AddEntry(new_entry); | 2776 parent_dir->AddEntry(new_entry); |
2797 | 2777 |
2798 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2778 OnDirectoryChanged(directory_path); |
2799 OnDirectoryChanged(directory_path)); | |
2800 return GDATA_FILE_OK; | 2779 return GDATA_FILE_OK; |
2801 } | 2780 } |
2802 | 2781 |
2803 GDataFileSystem::FindMissingDirectoryResult | 2782 GDataFileSystem::FindMissingDirectoryResult |
2804 GDataFileSystem::FindFirstMissingParentDirectory( | 2783 GDataFileSystem::FindFirstMissingParentDirectory( |
2805 const FilePath& directory_path, | 2784 const FilePath& directory_path, |
2806 GURL* last_dir_content_url, | 2785 GURL* last_dir_content_url, |
2807 FilePath* first_missing_parent_path) { | 2786 FilePath* first_missing_parent_path) { |
2808 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2787 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2809 | 2788 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2850 return GDATA_FILE_ERROR_ACCESS_DENIED; | 2829 return GDATA_FILE_ERROR_ACCESS_DENIED; |
2851 | 2830 |
2852 // If it's a file (only files have resource id), get its resource id so that | 2831 // If it's a file (only files have resource id), get its resource id so that |
2853 // we can remove it after releasing the auto lock. | 2832 // we can remove it after releasing the auto lock. |
2854 if (entry->AsGDataFile()) | 2833 if (entry->AsGDataFile()) |
2855 *resource_id = entry->AsGDataFile()->resource_id(); | 2834 *resource_id = entry->AsGDataFile()->resource_id(); |
2856 | 2835 |
2857 GDataDirectory* parent_dir = entry->parent(); | 2836 GDataDirectory* parent_dir = entry->parent(); |
2858 parent_dir->RemoveEntry(entry); | 2837 parent_dir->RemoveEntry(entry); |
2859 | 2838 |
2860 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2839 OnDirectoryChanged(parent_dir->GetFilePath()); |
2861 OnDirectoryChanged(parent_dir->GetFilePath())); | |
2862 return GDATA_FILE_OK; | 2840 return GDATA_FILE_OK; |
2863 } | 2841 } |
2864 | 2842 |
2865 void GDataFileSystem::AddUploadedFile( | 2843 void GDataFileSystem::AddUploadedFile( |
2866 UploadMode upload_mode, | 2844 UploadMode upload_mode, |
2867 const FilePath& virtual_dir_path, | 2845 const FilePath& virtual_dir_path, |
2868 scoped_ptr<DocumentEntry> entry, | 2846 scoped_ptr<DocumentEntry> entry, |
2869 const FilePath& file_content_path, | 2847 const FilePath& file_content_path, |
2870 GDataCache::FileOperationType cache_operation, | 2848 GDataCache::FileOperationType cache_operation, |
2871 const base::Closure& callback) { | 2849 const base::Closure& callback) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2907 virtual_dir_path); | 2885 virtual_dir_path); |
2908 if (!dir_entry) | 2886 if (!dir_entry) |
2909 return; | 2887 return; |
2910 | 2888 |
2911 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); | 2889 GDataDirectory* parent_dir = dir_entry->AsGDataDirectory(); |
2912 if (!parent_dir) | 2890 if (!parent_dir) |
2913 return; | 2891 return; |
2914 | 2892 |
2915 scoped_ptr<GDataEntry> new_entry( | 2893 scoped_ptr<GDataEntry> new_entry( |
2916 GDataEntry::FromDocumentEntry( | 2894 GDataEntry::FromDocumentEntry( |
2917 parent_dir, entry.get(), directory_service_.get())); | 2895 NULL, entry.get(), directory_service_.get())); |
2918 if (!new_entry.get()) | 2896 if (!new_entry.get()) |
2919 return; | 2897 return; |
2920 | 2898 |
2921 if (upload_mode == UPLOAD_EXISTING_FILE) { | 2899 if (upload_mode == UPLOAD_EXISTING_FILE) { |
2922 // Remove an existing entry, which should be present. | 2900 // Remove an existing entry, which should be present. |
2923 const std::string& resource_id = new_entry->resource_id(); | 2901 const std::string& resource_id = new_entry->resource_id(); |
2924 directory_service_->GetEntryByResourceIdAsync(resource_id, | 2902 directory_service_->GetEntryByResourceIdAsync(resource_id, |
2925 base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir)); | 2903 base::Bind(&RemoveStaleEntryOnUpload, resource_id, parent_dir)); |
2926 } | 2904 } |
2927 | 2905 |
2928 GDataFile* file = new_entry->AsGDataFile(); | 2906 GDataFile* file = new_entry->AsGDataFile(); |
2929 DCHECK(file); | 2907 DCHECK(file); |
2930 const std::string& resource_id = file->resource_id(); | 2908 const std::string& resource_id = file->resource_id(); |
2931 const std::string& md5 = file->file_md5(); | 2909 const std::string& md5 = file->file_md5(); |
2932 parent_dir->AddEntry(new_entry.release()); | 2910 parent_dir->AddEntry(new_entry.release()); |
2933 | 2911 |
2934 FOR_EACH_OBSERVER(GDataFileSystemInterface::Observer, observers_, | 2912 OnDirectoryChanged(virtual_dir_path); |
2935 OnDirectoryChanged(virtual_dir_path)); | |
2936 | 2913 |
2937 if (upload_mode == UPLOAD_NEW_FILE) { | 2914 if (upload_mode == UPLOAD_NEW_FILE) { |
2938 // Add the file to the cache if we have uploaded a new file. | 2915 // Add the file to the cache if we have uploaded a new file. |
2939 cache_->StoreOnUIThread(resource_id, | 2916 cache_->StoreOnUIThread(resource_id, |
2940 md5, | 2917 md5, |
2941 file_content_path, | 2918 file_content_path, |
2942 cache_operation, | 2919 cache_operation, |
2943 base::Bind(&OnCacheUpdatedForAddUploadedFile, | 2920 base::Bind(&OnCacheUpdatedForAddUploadedFile, |
2944 callback_runner.Release())); | 2921 callback_runner.Release())); |
2945 } else if (upload_mode == UPLOAD_EXISTING_FILE) { | 2922 } else if (upload_mode == UPLOAD_EXISTING_FILE) { |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3413 } | 3390 } |
3414 | 3391 |
3415 PlatformFileInfoProto entry_file_info; | 3392 PlatformFileInfoProto entry_file_info; |
3416 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3393 GDataEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
3417 *entry_proto->mutable_file_info() = entry_file_info; | 3394 *entry_proto->mutable_file_info() = entry_file_info; |
3418 if (!callback.is_null()) | 3395 if (!callback.is_null()) |
3419 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); | 3396 callback.Run(GDATA_FILE_OK, entry_proto.Pass()); |
3420 } | 3397 } |
3421 | 3398 |
3422 } // namespace gdata | 3399 } // namespace gdata |
OLD | NEW |