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_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 Loading... | |
| 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 585 base::SequencedTaskRunner* blocking_task_runner, | 598 base::SequencedTaskRunner* blocking_task_runner, |
| 586 const base::Closure& request_task, | 599 const base::Closure& request_task, |
| 587 const base::Closure& reply_task) { | 600 const base::Closure& reply_task) { |
| 588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 601 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 589 | 602 |
| 590 const bool posted = blocking_task_runner->PostTaskAndReply( | 603 const bool posted = blocking_task_runner->PostTaskAndReply( |
| 591 from_here, request_task, reply_task); | 604 from_here, request_task, reply_task); |
| 592 DCHECK(posted); | 605 DCHECK(posted); |
| 593 } | 606 } |
| 594 | 607 |
| 608 // Helper function for binding |path| to GetEntryInfoWithFilePathCallback and | |
| 609 // create GetEntryInfoCallback. | |
| 610 void RunGetEntryInfoWithFilePathCallback( | |
|
satorux1
2012/07/25 19:07:14
this seems to be unused.
kinaba
2012/07/26 01:29:51
Right. Thanks.
| |
| 611 const GetEntryInfoWithFilePathCallback& callback, | |
| 612 const FilePath& path, | |
| 613 GDataFileError error, | |
| 614 scoped_ptr<GDataEntryProto> entry_proto) { | |
| 615 if (!callback.is_null()) | |
| 616 callback.Run(error, path, entry_proto.Pass()); | |
| 617 } | |
| 618 | |
| 595 } // namespace | 619 } // namespace |
| 596 | 620 |
| 597 // GDataFileSystem::GetDocumentsParams struct implementation. | 621 // GDataFileSystem::GetDocumentsParams struct implementation. |
| 598 struct GDataFileSystem::GetDocumentsParams { | 622 struct GDataFileSystem::GetDocumentsParams { |
| 599 GetDocumentsParams(int start_changestamp, | 623 GetDocumentsParams(int start_changestamp, |
| 600 int root_feed_changestamp, | 624 int root_feed_changestamp, |
| 601 std::vector<DocumentFeed*>* feed_list, | 625 std::vector<DocumentFeed*>* feed_list, |
| 602 bool should_fetch_multiple_feeds, | 626 bool should_fetch_multiple_feeds, |
| 603 const FilePath& search_file_path, | 627 const FilePath& search_file_path, |
| 604 const std::string& search_query, | 628 const std::string& search_query, |
| (...skipping 1890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2495 const std::string& md5, | 2519 const std::string& md5, |
| 2496 const FilePath& cache_file_path) { | 2520 const FilePath& cache_file_path) { |
| 2497 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2521 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2498 | 2522 |
| 2499 if (error != GDATA_FILE_OK) { | 2523 if (error != GDATA_FILE_OK) { |
| 2500 if (!callback.is_null()) | 2524 if (!callback.is_null()) |
| 2501 callback.Run(error); | 2525 callback.Run(error); |
| 2502 return; | 2526 return; |
| 2503 } | 2527 } |
| 2504 | 2528 |
| 2529 // Gets the size of the cache file. Since the file is locally modified, the | |
| 2530 // file size information stored in GDataEntry is not correct. | |
| 2531 GDataFileError* get_size_error = new GDataFileError(GDATA_FILE_ERROR_FAILED); | |
| 2532 int64* file_size = new int64(-1); | |
| 2533 PostBlockingPoolSequencedTaskAndReply( | |
| 2534 FROM_HERE, | |
| 2535 blocking_task_runner_, | |
| 2536 base::Bind(&GetLocalFileSizeOnBlockingPool, | |
| 2537 cache_file_path, | |
| 2538 get_size_error, | |
| 2539 file_size), | |
| 2540 base::Bind(&GDataFileSystem::OnGetFileSizeCompleteForUpdateFile, | |
| 2541 ui_weak_ptr_, | |
| 2542 callback, | |
| 2543 resource_id, | |
| 2544 md5, | |
| 2545 cache_file_path, | |
| 2546 base::Owned(get_size_error), | |
| 2547 base::Owned(file_size))); | |
| 2548 } | |
| 2549 | |
| 2550 void GDataFileSystem::OnGetFileSizeCompleteForUpdateFile( | |
| 2551 const FileOperationCallback& callback, | |
| 2552 const std::string& resource_id, | |
| 2553 const std::string& md5, | |
| 2554 const FilePath& cache_file_path, | |
| 2555 GDataFileError* error, | |
| 2556 int64* file_size) { | |
| 2557 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 2558 | |
| 2559 if (*error != GDATA_FILE_OK) { | |
| 2560 if (!callback.is_null()) | |
| 2561 callback.Run(*error); | |
| 2562 return; | |
| 2563 } | |
| 2564 | |
| 2505 directory_service_->GetEntryByResourceIdAsync(resource_id, | 2565 directory_service_->GetEntryByResourceIdAsync(resource_id, |
| 2506 base::Bind(&GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry, | 2566 base::Bind(&GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry, |
| 2507 ui_weak_ptr_, | 2567 ui_weak_ptr_, |
| 2508 callback, | 2568 callback, |
| 2509 md5, | 2569 md5, |
| 2570 *file_size, | |
| 2510 cache_file_path)); | 2571 cache_file_path)); |
| 2511 } | 2572 } |
| 2512 | 2573 |
| 2513 void GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry( | 2574 void GDataFileSystem::OnGetFileCompleteForUpdateFileByEntry( |
| 2514 const FileOperationCallback& callback, | 2575 const FileOperationCallback& callback, |
| 2515 const std::string& md5, | 2576 const std::string& md5, |
| 2577 int64 file_size, | |
| 2516 const FilePath& cache_file_path, | 2578 const FilePath& cache_file_path, |
| 2517 GDataEntry* entry) { | 2579 GDataEntry* entry) { |
| 2518 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2580 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 2519 | 2581 |
| 2520 if (!entry || !entry->AsGDataFile()) { | 2582 if (!entry || !entry->AsGDataFile()) { |
| 2521 if (!callback.is_null()) | 2583 if (!callback.is_null()) |
| 2522 callback.Run(GDATA_FILE_ERROR_NOT_FOUND); | 2584 callback.Run(GDATA_FILE_ERROR_NOT_FOUND); |
| 2523 return; | 2585 return; |
| 2524 } | 2586 } |
| 2525 GDataFile* file = entry->AsGDataFile(); | 2587 GDataFile* file = entry->AsGDataFile(); |
| 2526 | 2588 |
| 2527 uploader_->UploadExistingFile( | 2589 uploader_->UploadExistingFile( |
| 2528 file->upload_url(), | 2590 file->upload_url(), |
| 2529 file->GetFilePath(), | 2591 file->GetFilePath(), |
| 2530 cache_file_path, | 2592 cache_file_path, |
| 2531 file->file_info().size, | 2593 file_size, |
| 2532 file->content_mime_type(), | 2594 file->content_mime_type(), |
| 2533 base::Bind(&GDataFileSystem::OnUpdatedFileUploaded, | 2595 base::Bind(&GDataFileSystem::OnUpdatedFileUploaded, |
| 2534 ui_weak_ptr_, | 2596 ui_weak_ptr_, |
| 2535 callback)); | 2597 callback)); |
| 2536 } | 2598 } |
| 2537 | 2599 |
| 2538 void GDataFileSystem::OnUpdatedFileUploaded( | 2600 void GDataFileSystem::OnUpdatedFileUploaded( |
| 2539 const FileOperationCallback& callback, | 2601 const FileOperationCallback& callback, |
| 2540 GDataFileError error, | 2602 GDataFileError error, |
| 2541 scoped_ptr<UploadFileInfo> upload_file_info) { | 2603 scoped_ptr<UploadFileInfo> upload_file_info) { |
| (...skipping 1569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4111 // must go through here. Removes the |file_path| from the remembered set so | 4173 // must go through here. Removes the |file_path| from the remembered set so |
| 4112 // that subsequent operations can open the file again. | 4174 // that subsequent operations can open the file again. |
| 4113 open_files_.erase(file_path); | 4175 open_files_.erase(file_path); |
| 4114 | 4176 |
| 4115 // Then invokes the user-supplied callback function. | 4177 // Then invokes the user-supplied callback function. |
| 4116 if (!callback.is_null()) | 4178 if (!callback.is_null()) |
| 4117 callback.Run(result); | 4179 callback.Run(result); |
| 4118 } | 4180 } |
| 4119 | 4181 |
| 4120 } // namespace gdata | 4182 } // namespace gdata |
| OLD | NEW |