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/drive/drive_file_system.h" | 5 #include "chrome/browser/chromeos/drive/drive_file_system.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/json/json_file_value_serializer.h" | |
10 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
11 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
12 #include "base/platform_file.h" | 11 #include "base/platform_file.h" |
13 #include "base/prefs/pref_change_registrar.h" | 12 #include "base/prefs/pref_change_registrar.h" |
14 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
15 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
16 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
17 #include "base/values.h" | |
18 #include "chrome/browser/chromeos/drive/change_list_loader.h" | 16 #include "chrome/browser/chromeos/drive/change_list_loader.h" |
19 #include "chrome/browser/chromeos/drive/change_list_processor.h" | 17 #include "chrome/browser/chromeos/drive/change_list_processor.h" |
20 #include "chrome/browser/chromeos/drive/drive.pb.h" | 18 #include "chrome/browser/chromeos/drive/drive.pb.h" |
21 #include "chrome/browser/chromeos/drive/drive_cache.h" | 19 #include "chrome/browser/chromeos/drive/drive_cache.h" |
22 #include "chrome/browser/chromeos/drive/drive_file_system_observer.h" | 20 #include "chrome/browser/chromeos/drive/drive_file_system_observer.h" |
23 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" | 21 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" |
24 #include "chrome/browser/chromeos/drive/drive_scheduler.h" | 22 #include "chrome/browser/chromeos/drive/drive_scheduler.h" |
25 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" | 23 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" |
26 #include "chrome/browser/chromeos/drive/search_metadata.h" | 24 #include "chrome/browser/chromeos/drive/search_metadata.h" |
27 #include "chrome/browser/google_apis/drive_api_parser.h" | 25 #include "chrome/browser/google_apis/drive_api_parser.h" |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 } | 334 } |
337 DCHECK(entry_proto.get()); | 335 DCHECK(entry_proto.get()); |
338 | 336 |
339 CheckLocalModificationAndRun( | 337 CheckLocalModificationAndRun( |
340 entry_proto.Pass(), | 338 entry_proto.Pass(), |
341 base::Bind(&RunGetEntryInfoWithFilePathCallback, | 339 base::Bind(&RunGetEntryInfoWithFilePathCallback, |
342 callback, | 340 callback, |
343 file_path)); | 341 file_path)); |
344 } | 342 } |
345 | 343 |
346 void DriveFileSystem::LoadIfNeeded( | |
347 const DirectoryFetchInfo& directory_fetch_info, | |
348 const FileOperationCallback& callback) { | |
349 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
350 DCHECK(!callback.is_null()); | |
351 | |
352 change_list_loader_->LoadIfNeeded(directory_fetch_info, callback); | |
353 } | |
354 | |
355 void DriveFileSystem::TransferFileFromRemoteToLocal( | 344 void DriveFileSystem::TransferFileFromRemoteToLocal( |
356 const base::FilePath& remote_src_file_path, | 345 const base::FilePath& remote_src_file_path, |
357 const base::FilePath& local_dest_file_path, | 346 const base::FilePath& local_dest_file_path, |
358 const FileOperationCallback& callback) { | 347 const FileOperationCallback& callback) { |
359 | 348 |
360 drive_operations_.TransferFileFromRemoteToLocal(remote_src_file_path, | 349 drive_operations_.TransferFileFromRemoteToLocal(remote_src_file_path, |
361 local_dest_file_path, | 350 local_dest_file_path, |
362 callback); | 351 callback); |
363 } | 352 } |
364 | 353 |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 DCHECK(!callback.is_null()); | 621 DCHECK(!callback.is_null()); |
633 | 622 |
634 if (error == DRIVE_FILE_OK) { | 623 if (error == DRIVE_FILE_OK) { |
635 CheckLocalModificationAndRun(entry_proto.Pass(), callback); | 624 CheckLocalModificationAndRun(entry_proto.Pass(), callback); |
636 return; | 625 return; |
637 } | 626 } |
638 | 627 |
639 // Start loading if needed. Note that directory_fetch_info is empty here, | 628 // Start loading if needed. Note that directory_fetch_info is empty here, |
640 // as we don't need to fetch the contents of a directory when we just need | 629 // as we don't need to fetch the contents of a directory when we just need |
641 // to get an entry of the directory. | 630 // to get an entry of the directory. |
642 LoadIfNeeded(DirectoryFetchInfo(), | 631 change_list_loader_->LoadIfNeeded( |
643 base::Bind(&DriveFileSystem::GetEntryInfoByPathAfterLoad, | 632 DirectoryFetchInfo(), |
644 weak_ptr_factory_.GetWeakPtr(), | 633 base::Bind(&DriveFileSystem::GetEntryInfoByPathAfterLoad, |
645 file_path, | 634 weak_ptr_factory_.GetWeakPtr(), |
646 callback)); | 635 file_path, |
| 636 callback)); |
647 } | 637 } |
648 | 638 |
649 void DriveFileSystem::GetEntryInfoByPathAfterLoad( | 639 void DriveFileSystem::GetEntryInfoByPathAfterLoad( |
650 const base::FilePath& file_path, | 640 const base::FilePath& file_path, |
651 const GetEntryInfoCallback& callback, | 641 const GetEntryInfoCallback& callback, |
652 DriveFileError error) { | 642 DriveFileError error) { |
653 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 643 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
654 DCHECK(!callback.is_null()); | 644 DCHECK(!callback.is_null()); |
655 | 645 |
656 if (error != DRIVE_FILE_OK) { | 646 if (error != DRIVE_FILE_OK) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 void DriveFileSystem::ReadDirectoryByPathAfterGetEntry( | 691 void DriveFileSystem::ReadDirectoryByPathAfterGetEntry( |
702 const base::FilePath& directory_path, | 692 const base::FilePath& directory_path, |
703 const ReadDirectoryWithSettingCallback& callback, | 693 const ReadDirectoryWithSettingCallback& callback, |
704 DriveFileError error, | 694 DriveFileError error, |
705 scoped_ptr<DriveEntryProto> entry_proto) { | 695 scoped_ptr<DriveEntryProto> entry_proto) { |
706 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 696 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
707 DCHECK(!callback.is_null()); | 697 DCHECK(!callback.is_null()); |
708 | 698 |
709 if (error != DRIVE_FILE_OK) { | 699 if (error != DRIVE_FILE_OK) { |
710 // If we don't know about the directory, start loading. | 700 // If we don't know about the directory, start loading. |
711 LoadIfNeeded(DirectoryFetchInfo(), | 701 change_list_loader_->LoadIfNeeded( |
712 base::Bind(&DriveFileSystem::ReadDirectoryByPathAfterLoad, | 702 DirectoryFetchInfo(), |
713 weak_ptr_factory_.GetWeakPtr(), | 703 base::Bind(&DriveFileSystem::ReadDirectoryByPathAfterLoad, |
714 directory_path, | 704 weak_ptr_factory_.GetWeakPtr(), |
715 callback)); | 705 directory_path, |
| 706 callback)); |
716 return; | 707 return; |
717 } | 708 } |
718 | 709 |
719 if (!entry_proto->file_info().is_directory()) { | 710 if (!entry_proto->file_info().is_directory()) { |
720 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, | 711 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY, |
721 hide_hosted_docs_, | 712 hide_hosted_docs_, |
722 scoped_ptr<DriveEntryProtoVector>()); | 713 scoped_ptr<DriveEntryProtoVector>()); |
723 return; | 714 return; |
724 } | 715 } |
725 | 716 |
726 // Pass the directory fetch info so we can fetch the contents of the | 717 // Pass the directory fetch info so we can fetch the contents of the |
727 // directory before loading change lists. | 718 // directory before loading change lists. |
728 DirectoryFetchInfo directory_fetch_info( | 719 DirectoryFetchInfo directory_fetch_info( |
729 entry_proto->resource_id(), | 720 entry_proto->resource_id(), |
730 entry_proto->directory_specific_info().changestamp()); | 721 entry_proto->directory_specific_info().changestamp()); |
731 LoadIfNeeded(directory_fetch_info, | 722 change_list_loader_->LoadIfNeeded( |
732 base::Bind(&DriveFileSystem::ReadDirectoryByPathAfterLoad, | 723 directory_fetch_info, |
733 weak_ptr_factory_.GetWeakPtr(), | 724 base::Bind(&DriveFileSystem::ReadDirectoryByPathAfterLoad, |
734 directory_path, | 725 weak_ptr_factory_.GetWeakPtr(), |
735 callback)); | 726 directory_path, |
| 727 callback)); |
736 } | 728 } |
737 | 729 |
738 void DriveFileSystem::ReadDirectoryByPathAfterLoad( | 730 void DriveFileSystem::ReadDirectoryByPathAfterLoad( |
739 const base::FilePath& directory_path, | 731 const base::FilePath& directory_path, |
740 const ReadDirectoryWithSettingCallback& callback, | 732 const ReadDirectoryWithSettingCallback& callback, |
741 DriveFileError error) { | 733 DriveFileError error) { |
742 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 734 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
743 DCHECK(!callback.is_null()); | 735 DCHECK(!callback.is_null()); |
744 | 736 |
745 if (error != DRIVE_FILE_OK) { | 737 if (error != DRIVE_FILE_OK) { |
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1682 return; | 1674 return; |
1683 } | 1675 } |
1684 | 1676 |
1685 PlatformFileInfoProto entry_file_info; | 1677 PlatformFileInfoProto entry_file_info; |
1686 util::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 1678 util::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
1687 *entry_proto->mutable_file_info() = entry_file_info; | 1679 *entry_proto->mutable_file_info() = entry_file_info; |
1688 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); | 1680 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); |
1689 } | 1681 } |
1690 | 1682 |
1691 } // namespace drive | 1683 } // namespace drive |
OLD | NEW |