Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system.cc

Issue 10809054: gdata: Remove use of GetGDataEntryByPath() from StartFileUploadOnUIThread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 FeedToFileResourceMapUmaStats() 746 FeedToFileResourceMapUmaStats()
747 : num_regular_files(0), 747 : num_regular_files(0),
748 num_hosted_documents(0) {} 748 num_hosted_documents(0) {}
749 749
750 typedef std::map<DocumentEntry::EntryKind, int> EntryKindToCountMap; 750 typedef std::map<DocumentEntry::EntryKind, int> EntryKindToCountMap;
751 int num_regular_files; 751 int num_regular_files;
752 int num_hosted_documents; 752 int num_hosted_documents;
753 EntryKindToCountMap num_files_with_entry_kind; 753 EntryKindToCountMap num_files_with_entry_kind;
754 }; 754 };
755 755
756 // GDataFileSystem::StartFileUploadParams implementation.
757 struct GDataFileSystem::StartFileUploadParams {
758 StartFileUploadParams(const FilePath& in_local_file_path,
759 const FilePath& in_remote_file_path,
760 const FileOperationCallback& in_callback)
761 : local_file_path(in_local_file_path),
762 remote_file_path(in_remote_file_path),
763 callback(in_callback) {}
764
765 const FilePath local_file_path;
766 const FilePath remote_file_path;
767 const FileOperationCallback callback;
768 };
756 769
757 // GDataFileSystem class implementation. 770 // GDataFileSystem class implementation.
758 771
759 GDataFileSystem::GDataFileSystem( 772 GDataFileSystem::GDataFileSystem(
760 Profile* profile, 773 Profile* profile,
761 GDataCache* cache, 774 GDataCache* cache,
762 DocumentsServiceInterface* documents_service, 775 DocumentsServiceInterface* documents_service,
763 GDataUploaderInterface* uploader, 776 GDataUploaderInterface* uploader,
764 DriveWebAppsRegistryInterface* webapps_registry, 777 DriveWebAppsRegistryInterface* webapps_registry,
765 base::SequencedTaskRunner* blocking_task_runner) 778 base::SequencedTaskRunner* blocking_task_runner)
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 PostBlockingPoolSequencedTaskAndReply( 1235 PostBlockingPoolSequencedTaskAndReply(
1223 FROM_HERE, 1236 FROM_HERE,
1224 blocking_task_runner_, 1237 blocking_task_runner_,
1225 base::Bind(&GetLocalFileInfoOnBlockingPool, 1238 base::Bind(&GetLocalFileInfoOnBlockingPool,
1226 local_file_path, 1239 local_file_path,
1227 error, 1240 error,
1228 file_size, 1241 file_size,
1229 content_type), 1242 content_type),
1230 base::Bind(&GDataFileSystem::StartFileUploadOnUIThread, 1243 base::Bind(&GDataFileSystem::StartFileUploadOnUIThread,
1231 ui_weak_ptr_, 1244 ui_weak_ptr_,
1232 local_file_path, 1245 StartFileUploadParams(local_file_path,
1233 remote_dest_file_path, 1246 remote_dest_file_path,
1234 callback, 1247 callback),
1235 base::Owned(error), 1248 base::Owned(error),
1236 base::Owned(file_size), 1249 base::Owned(file_size),
1237 base::Owned(content_type))); 1250 base::Owned(content_type)));
1238 } 1251 }
1239 1252
1240 void GDataFileSystem::StartFileUploadOnUIThread( 1253 void GDataFileSystem::StartFileUploadOnUIThread(
1241 const FilePath& local_file, 1254 const StartFileUploadParams& params,
1242 const FilePath& remote_dest_file,
1243 const FileOperationCallback& callback,
1244 GDataFileError* error, 1255 GDataFileError* error,
1245 int64* file_size, 1256 int64* file_size,
1246 std::string* content_type) { 1257 std::string* content_type) {
1247 // This method needs to run on the UI thread as required by 1258 // This method needs to run on the UI thread as required by
1248 // GDataUploader::UploadNewFile(). 1259 // GDataUploader::UploadNewFile().
1249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1250 DCHECK(error); 1261 DCHECK(error);
1251 DCHECK(file_size); 1262 DCHECK(file_size);
1252 DCHECK(content_type); 1263 DCHECK(content_type);
1253 1264
1254 if (*error != GDATA_FILE_OK) { 1265 if (*error != GDATA_FILE_OK) {
1255 if (!callback.is_null()) 1266 if (!params.callback.is_null())
1256 callback.Run(*error); 1267 params.callback.Run(*error);
1257 1268
1258 return; 1269 return;
1259 } 1270 }
1260 1271
1261 // Make sure the destination directory exists. 1272 // Make sure the destination directory exists.
1262 GDataEntry* dest_dir = GetGDataEntryByPath(remote_dest_file.DirName()); 1273 GetEntryInfoByPath(
1263 if (!dest_dir || !dest_dir->AsGDataDirectory()) { 1274 params.remote_file_path.DirName(),
1264 if (!callback.is_null()) 1275 base::Bind(
1265 callback.Run(GDATA_FILE_ERROR_NOT_FOUND); 1276 &GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo,
1266 NOTREACHED(); 1277 ui_weak_ptr_,
1278 params,
1279 *file_size,
1280 *content_type));
1281 }
1282
1283 void GDataFileSystem::StartFileUploadOnUIThreadAfterGetEntryInfo(
1284 const StartFileUploadParams& params,
1285 int64 file_size,
1286 std::string content_type,
1287 GDataFileError error,
1288 scoped_ptr<GDataEntryProto> entry_proto) {
1289 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1290
1291 if (entry_proto.get() && !entry_proto->file_info().is_directory())
1292 error = GDATA_FILE_ERROR_NOT_A_DIRECTORY;
1293
1294 if (error != GDATA_FILE_OK) {
1295 if (!params.callback.is_null())
1296 params.callback.Run(error);
1267 return; 1297 return;
1268 } 1298 }
1299 DCHECK(entry_proto.get());
1269 1300
1270 // Fill in values of UploadFileInfo. 1301 // Fill in values of UploadFileInfo.
1271 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo); 1302 scoped_ptr<UploadFileInfo> upload_file_info(new UploadFileInfo);
1272 upload_file_info->file_path = local_file; 1303 upload_file_info->file_path = params.local_file_path;
1273 upload_file_info->file_size = *file_size; 1304 upload_file_info->file_size = file_size;
1274 upload_file_info->gdata_path = remote_dest_file; 1305 upload_file_info->gdata_path = params.remote_file_path;
1275 // Use the file name as the title. 1306 // Use the file name as the title.
1276 upload_file_info->title = remote_dest_file.BaseName().value(); 1307 upload_file_info->title = params.remote_file_path.BaseName().value();
1277 upload_file_info->content_length = *file_size; 1308 upload_file_info->content_length = file_size;
1278 upload_file_info->all_bytes_present = true; 1309 upload_file_info->all_bytes_present = true;
1279 upload_file_info->content_type = *content_type; 1310 upload_file_info->content_type = content_type;
1280 upload_file_info->initial_upload_location = 1311 upload_file_info->initial_upload_location = GURL(entry_proto->upload_url());
1281 dest_dir->AsGDataDirectory()->upload_url();
1282 1312
1283 upload_file_info->completion_callback = 1313 upload_file_info->completion_callback =
1284 base::Bind(&GDataFileSystem::OnTransferCompleted, 1314 base::Bind(&GDataFileSystem::OnTransferCompleted,
1285 ui_weak_ptr_, 1315 ui_weak_ptr_,
1286 callback); 1316 params.callback);
1287 1317
1288 uploader_->UploadNewFile(upload_file_info.Pass()); 1318 uploader_->UploadNewFile(upload_file_info.Pass());
1289 } 1319 }
1290 1320
1291 void GDataFileSystem::OnTransferCompleted( 1321 void GDataFileSystem::OnTransferCompleted(
1292 const FileOperationCallback& callback, 1322 const FileOperationCallback& callback,
1293 GDataFileError error, 1323 GDataFileError error,
1294 scoped_ptr<UploadFileInfo> upload_file_info) { 1324 scoped_ptr<UploadFileInfo> upload_file_info) {
1295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 1325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1296 DCHECK(upload_file_info.get()); 1326 DCHECK(upload_file_info.get());
(...skipping 2766 matching lines...) Expand 10 before | Expand all | Expand 10 after
4063 // must go through here. Removes the |file_path| from the remembered set so 4093 // must go through here. Removes the |file_path| from the remembered set so
4064 // that subsequent operations can open the file again. 4094 // that subsequent operations can open the file again.
4065 open_files_.erase(file_path); 4095 open_files_.erase(file_path);
4066 4096
4067 // Then invokes the user-supplied callback function. 4097 // Then invokes the user-supplied callback function.
4068 if (!callback.is_null()) 4098 if (!callback.is_null())
4069 callback.Run(result); 4099 callback.Run(result);
4070 } 4100 }
4071 4101
4072 } // namespace gdata 4102 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698