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

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

Issue 10832002: gdata: Upload locally modified file in the correct size. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove an unused function. 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 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 LOG(WARNING) << "GData metadata file can't be stored at " 308 LOG(WARNING) << "GData metadata file can't be stored at "
309 << file_path.value(); 309 << file_path.value();
310 if (!file_util::Delete(file_path, true)) { 310 if (!file_util::Delete(file_path, true)) {
311 LOG(WARNING) << "GData metadata file can't be deleted at " 311 LOG(WARNING) << "GData metadata file can't be deleted at "
312 << file_path.value(); 312 << file_path.value();
313 return; 313 return;
314 } 314 }
315 } 315 }
316 } 316 }
317 317
318 // Gets the file size of |local_file|.
319 void GetLocalFileSizeOnBlockingPool(const FilePath& local_file,
320 GDataFileError* error,
321 int64* file_size) {
322 DCHECK(error);
323 DCHECK(file_size);
324
325 *file_size = 0;
326 *error = file_util::GetFileSize(local_file, file_size) ?
327 GDATA_FILE_OK :
328 GDATA_FILE_ERROR_NOT_FOUND;
329 }
330
318 // Gets the file size and the content type of |local_file|. 331 // Gets the file size and the content type of |local_file|.
319 void GetLocalFileInfoOnBlockingPool( 332 void GetLocalFileInfoOnBlockingPool(
320 const FilePath& local_file, 333 const FilePath& local_file,
321 GDataFileError* error, 334 GDataFileError* error,
322 int64* file_size, 335 int64* file_size,
323 std::string* content_type) { 336 std::string* content_type) {
324 DCHECK(error); 337 DCHECK(error);
325 DCHECK(file_size); 338 DCHECK(file_size);
326 DCHECK(content_type); 339 DCHECK(content_type);
327 340
(...skipping 2167 matching lines...) Expand 10 before | Expand all | Expand 10 after
2495 const std::string& md5, 2508 const std::string& md5,
2496 const FilePath& cache_file_path) { 2509 const FilePath& cache_file_path) {
2497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2510 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2498 2511
2499 if (error != GDATA_FILE_OK) { 2512 if (error != GDATA_FILE_OK) {
2500 if (!callback.is_null()) 2513 if (!callback.is_null())
2501 callback.Run(error); 2514 callback.Run(error);
2502 return; 2515 return;
2503 } 2516 }
2504 2517
2518 // Gets the size of the cache file. Since the file is locally modified, the
2519 // file size information stored in GDataEntry is not correct.
2520 GDataFileError* get_size_error = new GDataFileError(GDATA_FILE_ERROR_FAILED);
2521 int64* file_size = new int64(-1);
2522 PostBlockingPoolSequencedTaskAndReply(
2523 FROM_HERE,
2524 blocking_task_runner_,
2525 base::Bind(&GetLocalFileSizeOnBlockingPool,
2526 cache_file_path,
2527 get_size_error,
2528 file_size),
2529 base::Bind(&GDataFileSystem::OnGetFileSizeCompleteForUpdateFile,
2530 ui_weak_ptr_,
2531 callback,
2532 resource_id,
2533 md5,
2534 cache_file_path,
2535 base::Owned(get_size_error),
2536 base::Owned(file_size)));
2537 }
2538
2539 void GDataFileSystem::OnGetFileSizeCompleteForUpdateFile(
2540 const FileOperationCallback& callback,
2541 const std::string& resource_id,
2542 const std::string& md5,
2543 const FilePath& cache_file_path,
2544 GDataFileError* error,
2545 int64* file_size) {
2546 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2547
2548 if (*error != GDATA_FILE_OK) {
2549 if (!callback.is_null())
2550 callback.Run(*error);
2551 return;
2552 }
2553
2505 directory_service_->GetEntryByResourceIdAsync(resource_id, 2554 directory_service_->GetEntryByResourceIdAsync(resource_id,
2506 base::Bind(&GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry, 2555 base::Bind(&GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry,
2507 ui_weak_ptr_, 2556 ui_weak_ptr_,
2508 callback, 2557 callback,
2509 md5, 2558 md5,
2559 *file_size,
2510 cache_file_path)); 2560 cache_file_path));
2511 } 2561 }
2512 2562
2513 void GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry( 2563 void GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry(
2514 const FileOperationCallback& callback, 2564 const FileOperationCallback& callback,
2515 const std::string& md5, 2565 const std::string& md5,
2566 int64 file_size,
2516 const FilePath& cache_file_path, 2567 const FilePath& cache_file_path,
2517 GDataEntry* entry) { 2568 GDataEntry* entry) {
2518 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 2569 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
2519 2570
2520 if (!entry || !entry->AsGDataFile()) { 2571 if (!entry || !entry->AsGDataFile()) {
2521 if (!callback.is_null()) 2572 if (!callback.is_null())
2522 callback.Run(GDATA_FILE_ERROR_NOT_FOUND); 2573 callback.Run(GDATA_FILE_ERROR_NOT_FOUND);
2523 return; 2574 return;
2524 } 2575 }
2525 GDataFile* file = entry->AsGDataFile(); 2576 GDataFile* file = entry->AsGDataFile();
2526 2577
2527 uploader_->UploadExistingFile( 2578 uploader_->UploadExistingFile(
2528 file->upload_url(), 2579 file->upload_url(),
2529 file->GetFilePath(), 2580 file->GetFilePath(),
2530 cache_file_path, 2581 cache_file_path,
2531 file->file_info().size, 2582 file_size,
2532 file->content_mime_type(), 2583 file->content_mime_type(),
2533 base::Bind(&GDataFileSystem::OnUpdatedFileUploaded, 2584 base::Bind(&GDataFileSystem::OnUpdatedFileUploaded,
2534 ui_weak_ptr_, 2585 ui_weak_ptr_,
2535 callback)); 2586 callback));
2536 } 2587 }
2537 2588
2538 void GDataFileSystem::OnUpdatedFileUploaded( 2589 void GDataFileSystem::OnUpdatedFileUploaded(
2539 const FileOperationCallback& callback, 2590 const FileOperationCallback& callback,
2540 GDataFileError error, 2591 GDataFileError error,
2541 scoped_ptr<UploadFileInfo> upload_file_info) { 2592 scoped_ptr<UploadFileInfo> upload_file_info) {
(...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after
4111 // must go through here. Removes the |file_path| from the remembered set so 4162 // must go through here. Removes the |file_path| from the remembered set so
4112 // that subsequent operations can open the file again. 4163 // that subsequent operations can open the file again.
4113 open_files_.erase(file_path); 4164 open_files_.erase(file_path);
4114 4165
4115 // Then invokes the user-supplied callback function. 4166 // Then invokes the user-supplied callback function.
4116 if (!callback.is_null()) 4167 if (!callback.is_null())
4117 callback.Run(result); 4168 callback.Run(result);
4118 } 4169 }
4119 4170
4120 } // namespace gdata 4171 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.h ('k') | chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698