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" | 9 #include "base/json/json_file_value_serializer.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 #include "chrome/browser/prefs/pref_service.h" | 31 #include "chrome/browser/prefs/pref_service.h" |
32 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
33 #include "chrome/common/chrome_notification_types.h" | 33 #include "chrome/common/chrome_notification_types.h" |
34 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
35 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
36 #include "content/public/browser/notification_details.h" | 36 #include "content/public/browser/notification_details.h" |
37 #include "net/base/mime_util.h" | 37 #include "net/base/mime_util.h" |
38 | 38 |
39 using content::BrowserThread; | 39 using content::BrowserThread; |
40 | 40 |
41 namespace gdata { | 41 namespace drive { |
42 namespace { | 42 namespace { |
43 | 43 |
44 const char kMimeTypeJson[] = "application/json"; | 44 const char kMimeTypeJson[] = "application/json"; |
45 const char kMimeTypeOctetStream[] = "application/octet-stream"; | 45 const char kMimeTypeOctetStream[] = "application/octet-stream"; |
46 | 46 |
47 const char kEmptyFilePath[] = "/dev/null"; | 47 const char kEmptyFilePath[] = "/dev/null"; |
48 | 48 |
49 // Drive update check interval (in seconds). | 49 // Drive update check interval (in seconds). |
50 #ifndef NDEBUG | 50 #ifndef NDEBUG |
51 const int kDriveUpdateCheckIntervalInSec = 5; | 51 const int kDriveUpdateCheckIntervalInSec = 5; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 } | 188 } |
189 | 189 |
190 // Checks if a local file at |local_file_path| is a JSON file referencing a | 190 // Checks if a local file at |local_file_path| is a JSON file referencing a |
191 // hosted document on blocking pool, and if so, gets the resource ID of the | 191 // hosted document on blocking pool, and if so, gets the resource ID of the |
192 // document. | 192 // document. |
193 void GetDocumentResourceIdOnBlockingPool( | 193 void GetDocumentResourceIdOnBlockingPool( |
194 const FilePath& local_file_path, | 194 const FilePath& local_file_path, |
195 std::string* resource_id) { | 195 std::string* resource_id) { |
196 DCHECK(resource_id); | 196 DCHECK(resource_id); |
197 | 197 |
198 if (DocumentEntry::HasHostedDocumentExtension(local_file_path)) { | 198 if (gdata::DocumentEntry::HasHostedDocumentExtension(local_file_path)) { |
199 std::string error; | 199 std::string error; |
200 DictionaryValue* dict_value = NULL; | 200 DictionaryValue* dict_value = NULL; |
201 JSONFileValueSerializer serializer(local_file_path); | 201 JSONFileValueSerializer serializer(local_file_path); |
202 scoped_ptr<Value> value(serializer.Deserialize(NULL, &error)); | 202 scoped_ptr<Value> value(serializer.Deserialize(NULL, &error)); |
203 if (value.get() && value->GetAsDictionary(&dict_value)) | 203 if (value.get() && value->GetAsDictionary(&dict_value)) |
204 dict_value->GetString("resource_id", resource_id); | 204 dict_value->GetString("resource_id", resource_id); |
205 } | 205 } |
206 } | 206 } |
207 | 207 |
208 // Creates a temporary JSON file representing a document with |edit_url| | 208 // Creates a temporary JSON file representing a document with |edit_url| |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
348 // DriveFileSystem::GetFileFromCacheParams struct implementation. | 348 // DriveFileSystem::GetFileFromCacheParams struct implementation. |
349 struct DriveFileSystem::GetFileFromCacheParams { | 349 struct DriveFileSystem::GetFileFromCacheParams { |
350 GetFileFromCacheParams( | 350 GetFileFromCacheParams( |
351 const FilePath& virtual_file_path, | 351 const FilePath& virtual_file_path, |
352 const FilePath& local_tmp_path, | 352 const FilePath& local_tmp_path, |
353 const GURL& content_url, | 353 const GURL& content_url, |
354 const std::string& resource_id, | 354 const std::string& resource_id, |
355 const std::string& md5, | 355 const std::string& md5, |
356 const std::string& mime_type, | 356 const std::string& mime_type, |
357 const GetFileCallback& get_file_callback, | 357 const GetFileCallback& get_file_callback, |
358 const GetContentCallback& get_content_callback) | 358 const gdata::GetContentCallback& get_content_callback) |
359 : virtual_file_path(virtual_file_path), | 359 : virtual_file_path(virtual_file_path), |
360 local_tmp_path(local_tmp_path), | 360 local_tmp_path(local_tmp_path), |
361 content_url(content_url), | 361 content_url(content_url), |
362 resource_id(resource_id), | 362 resource_id(resource_id), |
363 md5(md5), | 363 md5(md5), |
364 mime_type(mime_type), | 364 mime_type(mime_type), |
365 get_file_callback(get_file_callback), | 365 get_file_callback(get_file_callback), |
366 get_content_callback(get_content_callback) { | 366 get_content_callback(get_content_callback) { |
367 } | 367 } |
368 | 368 |
369 FilePath virtual_file_path; | 369 FilePath virtual_file_path; |
370 FilePath local_tmp_path; | 370 FilePath local_tmp_path; |
371 FilePath cache_file_path; | 371 FilePath cache_file_path; |
372 GURL content_url; | 372 GURL content_url; |
373 std::string resource_id; | 373 std::string resource_id; |
374 std::string md5; | 374 std::string md5; |
375 std::string mime_type; | 375 std::string mime_type; |
376 GetFileCallback get_file_callback; | 376 GetFileCallback get_file_callback; |
377 GetContentCallback get_content_callback; | 377 gdata::GetContentCallback get_content_callback; |
378 }; | 378 }; |
379 | 379 |
380 // DriveFileSystem::StartFileUploadParams implementation. | 380 // DriveFileSystem::StartFileUploadParams implementation. |
381 struct DriveFileSystem::StartFileUploadParams { | 381 struct DriveFileSystem::StartFileUploadParams { |
382 StartFileUploadParams(const FilePath& in_local_file_path, | 382 StartFileUploadParams(const FilePath& in_local_file_path, |
383 const FilePath& in_remote_file_path, | 383 const FilePath& in_remote_file_path, |
384 const FileOperationCallback& in_callback) | 384 const FileOperationCallback& in_callback) |
385 : local_file_path(in_local_file_path), | 385 : local_file_path(in_local_file_path), |
386 remote_file_path(in_remote_file_path), | 386 remote_file_path(in_remote_file_path), |
387 callback(in_callback) {} | 387 callback(in_callback) {} |
388 | 388 |
389 const FilePath local_file_path; | 389 const FilePath local_file_path; |
390 const FilePath remote_file_path; | 390 const FilePath remote_file_path; |
391 const FileOperationCallback callback; | 391 const FileOperationCallback callback; |
392 }; | 392 }; |
393 | 393 |
394 // DriveFileSystem::AddUploadedFileParams implementation. | 394 // DriveFileSystem::AddUploadedFileParams implementation. |
395 struct DriveFileSystem::AddUploadedFileParams { | 395 struct DriveFileSystem::AddUploadedFileParams { |
396 AddUploadedFileParams(UploadMode upload_mode, | 396 AddUploadedFileParams(gdata::UploadMode upload_mode, |
397 const FilePath& directory_path, | 397 const FilePath& directory_path, |
398 scoped_ptr<DocumentEntry> doc_entry, | 398 scoped_ptr<gdata::DocumentEntry> doc_entry, |
399 const FilePath& file_content_path, | 399 const FilePath& file_content_path, |
400 DriveCache::FileOperationType cache_operation, | 400 DriveCache::FileOperationType cache_operation, |
401 const base::Closure& callback) | 401 const base::Closure& callback) |
402 : upload_mode(upload_mode), | 402 : upload_mode(upload_mode), |
403 directory_path(directory_path), | 403 directory_path(directory_path), |
404 doc_entry(doc_entry.Pass()), | 404 doc_entry(doc_entry.Pass()), |
405 file_content_path(file_content_path), | 405 file_content_path(file_content_path), |
406 cache_operation(cache_operation), | 406 cache_operation(cache_operation), |
407 callback(callback) { | 407 callback(callback) { |
408 } | 408 } |
409 | 409 |
410 UploadMode upload_mode; | 410 gdata::UploadMode upload_mode; |
411 FilePath directory_path; | 411 FilePath directory_path; |
412 scoped_ptr<DocumentEntry> doc_entry; | 412 scoped_ptr<gdata::DocumentEntry> doc_entry; |
413 FilePath file_content_path; | 413 FilePath file_content_path; |
414 DriveCache::FileOperationType cache_operation; | 414 DriveCache::FileOperationType cache_operation; |
415 base::Closure callback; | 415 base::Closure callback; |
416 std::string resource_id; | 416 std::string resource_id; |
417 std::string md5; | 417 std::string md5; |
418 }; | 418 }; |
419 | 419 |
420 // DriveFileSystem::UpdateEntryParams implementation. | 420 // DriveFileSystem::UpdateEntryParams implementation. |
421 struct DriveFileSystem::UpdateEntryParams { | 421 struct DriveFileSystem::UpdateEntryParams { |
422 UpdateEntryParams(const std::string& resource_id, | 422 UpdateEntryParams(const std::string& resource_id, |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
568 update_timer_.Stop(); | 568 update_timer_.Stop(); |
569 } | 569 } |
570 | 570 |
571 void DriveFileSystem::GetEntryInfoByResourceId( | 571 void DriveFileSystem::GetEntryInfoByResourceId( |
572 const std::string& resource_id, | 572 const std::string& resource_id, |
573 const GetEntryInfoWithFilePathCallback& callback) { | 573 const GetEntryInfoWithFilePathCallback& callback) { |
574 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 574 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
575 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 575 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
576 DCHECK(!callback.is_null()); | 576 DCHECK(!callback.is_null()); |
577 | 577 |
578 RunTaskOnUIThread( | 578 gdata::RunTaskOnUIThread( |
579 base::Bind(&DriveFileSystem::GetEntryInfoByResourceIdOnUIThread, | 579 base::Bind(&DriveFileSystem::GetEntryInfoByResourceIdOnUIThread, |
580 ui_weak_ptr_, | 580 ui_weak_ptr_, |
581 resource_id, | 581 resource_id, |
582 CreateRelayCallback(callback))); | 582 gdata::CreateRelayCallback(callback))); |
583 } | 583 } |
584 | 584 |
585 void DriveFileSystem::GetEntryInfoByResourceIdOnUIThread( | 585 void DriveFileSystem::GetEntryInfoByResourceIdOnUIThread( |
586 const std::string& resource_id, | 586 const std::string& resource_id, |
587 const GetEntryInfoWithFilePathCallback& callback) { | 587 const GetEntryInfoWithFilePathCallback& callback) { |
588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 588 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
589 DCHECK(!callback.is_null()); | 589 DCHECK(!callback.is_null()); |
590 | 590 |
591 resource_metadata_->GetEntryInfoByResourceId( | 591 resource_metadata_->GetEntryInfoByResourceId( |
592 resource_id, | 592 resource_id, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
652 const FilePath& local_dest_file_path, | 652 const FilePath& local_dest_file_path, |
653 const FileOperationCallback& callback) { | 653 const FileOperationCallback& callback) { |
654 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 654 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
655 DCHECK(!callback.is_null()); | 655 DCHECK(!callback.is_null()); |
656 | 656 |
657 GetFileByPath(remote_src_file_path, | 657 GetFileByPath(remote_src_file_path, |
658 base::Bind(&DriveFileSystem::OnGetFileCompleteForTransferFile, | 658 base::Bind(&DriveFileSystem::OnGetFileCompleteForTransferFile, |
659 ui_weak_ptr_, | 659 ui_weak_ptr_, |
660 local_dest_file_path, | 660 local_dest_file_path, |
661 callback), | 661 callback), |
662 GetContentCallback()); | 662 gdata::GetContentCallback()); |
663 } | 663 } |
664 | 664 |
665 void DriveFileSystem::TransferFileFromLocalToRemote( | 665 void DriveFileSystem::TransferFileFromLocalToRemote( |
666 const FilePath& local_src_file_path, | 666 const FilePath& local_src_file_path, |
667 const FilePath& remote_dest_file_path, | 667 const FilePath& remote_dest_file_path, |
668 const FileOperationCallback& callback) { | 668 const FileOperationCallback& callback) { |
669 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 669 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
670 DCHECK(!callback.is_null()); | 670 DCHECK(!callback.is_null()); |
671 | 671 |
672 // Make sure the destination directory exists. | 672 // Make sure the destination directory exists. |
(...skipping 22 matching lines...) Expand all Loading... | |
695 } | 695 } |
696 | 696 |
697 DCHECK(entry_proto.get()); | 697 DCHECK(entry_proto.get()); |
698 if (!entry_proto->file_info().is_directory()) { | 698 if (!entry_proto->file_info().is_directory()) { |
699 // The parent of |remote_dest_file_path| is not a directory. | 699 // The parent of |remote_dest_file_path| is not a directory. |
700 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY); | 700 callback.Run(DRIVE_FILE_ERROR_NOT_A_DIRECTORY); |
701 return; | 701 return; |
702 } | 702 } |
703 | 703 |
704 std::string* resource_id = new std::string; | 704 std::string* resource_id = new std::string; |
705 util::PostBlockingPoolSequencedTaskAndReply( | 705 gdata::util::PostBlockingPoolSequencedTaskAndReply( |
706 FROM_HERE, | 706 FROM_HERE, |
707 blocking_task_runner_, | 707 blocking_task_runner_, |
708 base::Bind(&GetDocumentResourceIdOnBlockingPool, | 708 base::Bind(&GetDocumentResourceIdOnBlockingPool, |
709 local_src_file_path, | 709 local_src_file_path, |
710 resource_id), | 710 resource_id), |
711 base::Bind(&DriveFileSystem::TransferFileForResourceId, | 711 base::Bind(&DriveFileSystem::TransferFileForResourceId, |
712 ui_weak_ptr_, | 712 ui_weak_ptr_, |
713 local_src_file_path, | 713 local_src_file_path, |
714 remote_dest_file_path, | 714 remote_dest_file_path, |
715 callback, | 715 callback, |
(...skipping 29 matching lines...) Expand all Loading... | |
745 void DriveFileSystem::TransferRegularFile( | 745 void DriveFileSystem::TransferRegularFile( |
746 const FilePath& local_file_path, | 746 const FilePath& local_file_path, |
747 const FilePath& remote_dest_file_path, | 747 const FilePath& remote_dest_file_path, |
748 const FileOperationCallback& callback) { | 748 const FileOperationCallback& callback) { |
749 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 749 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
750 | 750 |
751 DriveFileError* error = | 751 DriveFileError* error = |
752 new DriveFileError(DRIVE_FILE_OK); | 752 new DriveFileError(DRIVE_FILE_OK); |
753 int64* file_size = new int64; | 753 int64* file_size = new int64; |
754 std::string* content_type = new std::string; | 754 std::string* content_type = new std::string; |
755 util::PostBlockingPoolSequencedTaskAndReply( | 755 gdata::util::PostBlockingPoolSequencedTaskAndReply( |
756 FROM_HERE, | 756 FROM_HERE, |
757 blocking_task_runner_, | 757 blocking_task_runner_, |
758 base::Bind(&GetLocalFileInfoOnBlockingPool, | 758 base::Bind(&GetLocalFileInfoOnBlockingPool, |
759 local_file_path, | 759 local_file_path, |
760 error, | 760 error, |
761 file_size, | 761 file_size, |
762 content_type), | 762 content_type), |
763 base::Bind(&DriveFileSystem::StartFileUploadOnUIThread, | 763 base::Bind(&DriveFileSystem::StartFileUploadOnUIThread, |
764 ui_weak_ptr_, | 764 ui_weak_ptr_, |
765 StartFileUploadParams(local_file_path, | 765 StartFileUploadParams(local_file_path, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
829 ui_weak_ptr_, | 829 ui_weak_ptr_, |
830 params.callback), | 830 params.callback), |
831 UploaderReadyCallback()); | 831 UploaderReadyCallback()); |
832 } | 832 } |
833 | 833 |
834 void DriveFileSystem::OnTransferCompleted( | 834 void DriveFileSystem::OnTransferCompleted( |
835 const FileOperationCallback& callback, | 835 const FileOperationCallback& callback, |
836 DriveFileError error, | 836 DriveFileError error, |
837 const FilePath& drive_path, | 837 const FilePath& drive_path, |
838 const FilePath& file_path, | 838 const FilePath& file_path, |
839 scoped_ptr<DocumentEntry> document_entry) { | 839 scoped_ptr<gdata::DocumentEntry> document_entry) { |
840 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 840 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
841 | 841 |
842 if (error == DRIVE_FILE_OK && document_entry.get()) { | 842 if (error == DRIVE_FILE_OK && document_entry.get()) { |
843 AddUploadedFile(UPLOAD_NEW_FILE, | 843 AddUploadedFile(gdata::UPLOAD_NEW_FILE, |
844 drive_path.DirName(), | 844 drive_path.DirName(), |
845 document_entry.Pass(), | 845 document_entry.Pass(), |
846 file_path, | 846 file_path, |
847 DriveCache::FILE_OPERATION_COPY, | 847 DriveCache::FILE_OPERATION_COPY, |
848 base::Bind(&OnAddUploadFileCompleted, callback, error)); | 848 base::Bind(&OnAddUploadFileCompleted, callback, error)); |
849 } else if (!callback.is_null()) { | 849 } else if (!callback.is_null()) { |
850 callback.Run(error); | 850 callback.Run(error); |
851 } | 851 } |
852 } | 852 } |
853 | 853 |
854 void DriveFileSystem::Copy(const FilePath& src_file_path, | 854 void DriveFileSystem::Copy(const FilePath& src_file_path, |
855 const FilePath& dest_file_path, | 855 const FilePath& dest_file_path, |
856 const FileOperationCallback& callback) { | 856 const FileOperationCallback& callback) { |
857 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 857 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
858 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 858 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
859 DCHECK(!callback.is_null()); | 859 DCHECK(!callback.is_null()); |
860 | 860 |
861 RunTaskOnUIThread(base::Bind(&DriveFileSystem::CopyOnUIThread, | 861 gdata::RunTaskOnUIThread(base::Bind(&DriveFileSystem::CopyOnUIThread, |
satorux1
2012/10/12 05:32:56
fixed the indent, and elsewhere in the file.
| |
862 ui_weak_ptr_, | 862 ui_weak_ptr_, |
863 src_file_path, | 863 src_file_path, |
864 dest_file_path, | 864 dest_file_path, |
865 CreateRelayCallback(callback))); | 865 gdata::CreateRelayCallback(callback))); |
866 } | 866 } |
867 | 867 |
868 void DriveFileSystem::CopyOnUIThread(const FilePath& src_file_path, | 868 void DriveFileSystem::CopyOnUIThread(const FilePath& src_file_path, |
869 const FilePath& dest_file_path, | 869 const FilePath& dest_file_path, |
870 const FileOperationCallback& callback) { | 870 const FileOperationCallback& callback) { |
871 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 871 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
872 DCHECK(!callback.is_null()); | 872 DCHECK(!callback.is_null()); |
873 | 873 |
874 resource_metadata_->GetEntryInfoPairByPaths( | 874 resource_metadata_->GetEntryInfoPairByPaths( |
875 src_file_path, | 875 src_file_path, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
921 } | 921 } |
922 | 922 |
923 // TODO(kochi): Reimplement this once the server API supports | 923 // TODO(kochi): Reimplement this once the server API supports |
924 // copying of regular files directly on the server side. crbug.com/138273 | 924 // copying of regular files directly on the server side. crbug.com/138273 |
925 const FilePath& src_file_path = result->first.path; | 925 const FilePath& src_file_path = result->first.path; |
926 GetFileByPath(src_file_path, | 926 GetFileByPath(src_file_path, |
927 base::Bind(&DriveFileSystem::OnGetFileCompleteForCopy, | 927 base::Bind(&DriveFileSystem::OnGetFileCompleteForCopy, |
928 ui_weak_ptr_, | 928 ui_weak_ptr_, |
929 dest_file_path, | 929 dest_file_path, |
930 callback), | 930 callback), |
931 GetContentCallback()); | 931 gdata::GetContentCallback()); |
932 } | 932 } |
933 | 933 |
934 void DriveFileSystem::OnGetFileCompleteForCopy( | 934 void DriveFileSystem::OnGetFileCompleteForCopy( |
935 const FilePath& remote_dest_file_path, | 935 const FilePath& remote_dest_file_path, |
936 const FileOperationCallback& callback, | 936 const FileOperationCallback& callback, |
937 DriveFileError error, | 937 DriveFileError error, |
938 const FilePath& local_file_path, | 938 const FilePath& local_file_path, |
939 const std::string& unused_mime_type, | 939 const std::string& unused_mime_type, |
940 DriveFileType file_type) { | 940 DriveFileType file_type) { |
941 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 941 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 22 matching lines...) Expand all Loading... | |
964 if (error != DRIVE_FILE_OK) { | 964 if (error != DRIVE_FILE_OK) { |
965 callback.Run(error); | 965 callback.Run(error); |
966 return; | 966 return; |
967 } | 967 } |
968 | 968 |
969 // GetFileByPath downloads the file from Drive to a local cache, which is then | 969 // GetFileByPath downloads the file from Drive to a local cache, which is then |
970 // copied to the actual destination path on the local file system using | 970 // copied to the actual destination path on the local file system using |
971 // CopyLocalFileOnBlockingPool. | 971 // CopyLocalFileOnBlockingPool. |
972 DriveFileError* copy_file_error = | 972 DriveFileError* copy_file_error = |
973 new DriveFileError(DRIVE_FILE_OK); | 973 new DriveFileError(DRIVE_FILE_OK); |
974 util::PostBlockingPoolSequencedTaskAndReply( | 974 gdata::util::PostBlockingPoolSequencedTaskAndReply( |
975 FROM_HERE, | 975 FROM_HERE, |
976 blocking_task_runner_, | 976 blocking_task_runner_, |
977 base::Bind(&CopyLocalFileOnBlockingPool, | 977 base::Bind(&CopyLocalFileOnBlockingPool, |
978 local_file_path, | 978 local_file_path, |
979 local_dest_file_path, | 979 local_dest_file_path, |
980 copy_file_error), | 980 copy_file_error), |
981 base::Bind(&RunFileOperationCallbackHelper, | 981 base::Bind(&RunFileOperationCallbackHelper, |
982 callback, | 982 callback, |
983 base::Owned(copy_file_error))); | 983 base::Owned(copy_file_error))); |
984 } | 984 } |
(...skipping 13 matching lines...) Expand all Loading... | |
998 callback)); | 998 callback)); |
999 } | 999 } |
1000 | 1000 |
1001 void DriveFileSystem::Move(const FilePath& src_file_path, | 1001 void DriveFileSystem::Move(const FilePath& src_file_path, |
1002 const FilePath& dest_file_path, | 1002 const FilePath& dest_file_path, |
1003 const FileOperationCallback& callback) { | 1003 const FileOperationCallback& callback) { |
1004 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1004 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1005 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1005 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1006 DCHECK(!callback.is_null()); | 1006 DCHECK(!callback.is_null()); |
1007 | 1007 |
1008 RunTaskOnUIThread(base::Bind(&DriveFileSystem::MoveOnUIThread, | 1008 gdata::RunTaskOnUIThread(base::Bind(&DriveFileSystem::MoveOnUIThread, |
1009 ui_weak_ptr_, | 1009 ui_weak_ptr_, |
1010 src_file_path, | 1010 src_file_path, |
1011 dest_file_path, | 1011 dest_file_path, |
1012 CreateRelayCallback(callback))); | 1012 gdata::CreateRelayCallback(callback))); |
1013 } | 1013 } |
1014 | 1014 |
1015 void DriveFileSystem::MoveOnUIThread(const FilePath& src_file_path, | 1015 void DriveFileSystem::MoveOnUIThread(const FilePath& src_file_path, |
1016 const FilePath& dest_file_path, | 1016 const FilePath& dest_file_path, |
1017 const FileOperationCallback& callback) { | 1017 const FileOperationCallback& callback) { |
1018 move_operation_->Move(src_file_path, dest_file_path, callback); | 1018 move_operation_->Move(src_file_path, dest_file_path, callback); |
1019 } | 1019 } |
1020 | 1020 |
1021 void DriveFileSystem::MoveEntryFromRootDirectory( | 1021 void DriveFileSystem::MoveEntryFromRootDirectory( |
1022 const FilePath& directory_path, | 1022 const FilePath& directory_path, |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1080 callback))); | 1080 callback))); |
1081 } | 1081 } |
1082 | 1082 |
1083 void DriveFileSystem::Remove(const FilePath& file_path, | 1083 void DriveFileSystem::Remove(const FilePath& file_path, |
1084 bool is_recursive, | 1084 bool is_recursive, |
1085 const FileOperationCallback& callback) { | 1085 const FileOperationCallback& callback) { |
1086 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1086 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1087 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1087 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1088 DCHECK(!callback.is_null()); | 1088 DCHECK(!callback.is_null()); |
1089 | 1089 |
1090 RunTaskOnUIThread(base::Bind(&DriveFileSystem::RemoveOnUIThread, | 1090 gdata::RunTaskOnUIThread(base::Bind(&DriveFileSystem::RemoveOnUIThread, |
1091 ui_weak_ptr_, | 1091 ui_weak_ptr_, |
1092 file_path, | 1092 file_path, |
1093 is_recursive, | 1093 is_recursive, |
1094 CreateRelayCallback(callback))); | 1094 gdata::CreateRelayCallback(callback))); |
1095 } | 1095 } |
1096 | 1096 |
1097 void DriveFileSystem::RemoveOnUIThread( | 1097 void DriveFileSystem::RemoveOnUIThread( |
1098 const FilePath& file_path, | 1098 const FilePath& file_path, |
1099 bool is_recursive, | 1099 bool is_recursive, |
1100 const FileOperationCallback& callback) { | 1100 const FileOperationCallback& callback) { |
1101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1101 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1102 DCHECK(!callback.is_null()); | 1102 DCHECK(!callback.is_null()); |
1103 | 1103 |
1104 scheduler_->Remove(file_path, is_recursive, callback); | 1104 scheduler_->Remove(file_path, is_recursive, callback); |
1105 } | 1105 } |
1106 | 1106 |
1107 void DriveFileSystem::CreateDirectory( | 1107 void DriveFileSystem::CreateDirectory( |
1108 const FilePath& directory_path, | 1108 const FilePath& directory_path, |
1109 bool is_exclusive, | 1109 bool is_exclusive, |
1110 bool is_recursive, | 1110 bool is_recursive, |
1111 const FileOperationCallback& callback) { | 1111 const FileOperationCallback& callback) { |
1112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1112 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1113 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1113 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1114 DCHECK(!callback.is_null()); | 1114 DCHECK(!callback.is_null()); |
1115 | 1115 |
1116 RunTaskOnUIThread(base::Bind(&DriveFileSystem::CreateDirectoryOnUIThread, | 1116 gdata::RunTaskOnUIThread( |
1117 ui_weak_ptr_, | 1117 base::Bind(&DriveFileSystem::CreateDirectoryOnUIThread, |
1118 directory_path, | 1118 ui_weak_ptr_, |
1119 is_exclusive, | 1119 directory_path, |
1120 is_recursive, | 1120 is_exclusive, |
1121 CreateRelayCallback(callback))); | 1121 is_recursive, |
1122 gdata::CreateRelayCallback(callback))); | |
1122 } | 1123 } |
1123 | 1124 |
1124 void DriveFileSystem::CreateDirectoryOnUIThread( | 1125 void DriveFileSystem::CreateDirectoryOnUIThread( |
1125 const FilePath& directory_path, | 1126 const FilePath& directory_path, |
1126 bool is_exclusive, | 1127 bool is_exclusive, |
1127 bool is_recursive, | 1128 bool is_recursive, |
1128 const FileOperationCallback& callback) { | 1129 const FileOperationCallback& callback) { |
1129 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1130 DCHECK(!callback.is_null()); | 1131 DCHECK(!callback.is_null()); |
1131 | 1132 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1188 callback))); | 1189 callback))); |
1189 } | 1190 } |
1190 | 1191 |
1191 void DriveFileSystem::CreateFile(const FilePath& file_path, | 1192 void DriveFileSystem::CreateFile(const FilePath& file_path, |
1192 bool is_exclusive, | 1193 bool is_exclusive, |
1193 const FileOperationCallback& callback) { | 1194 const FileOperationCallback& callback) { |
1194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1195 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1196 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1196 DCHECK(!callback.is_null()); | 1197 DCHECK(!callback.is_null()); |
1197 | 1198 |
1198 RunTaskOnUIThread(base::Bind(&DriveFileSystem::CreateFileOnUIThread, | 1199 gdata::RunTaskOnUIThread(base::Bind(&DriveFileSystem::CreateFileOnUIThread, |
1199 ui_weak_ptr_, | 1200 ui_weak_ptr_, |
1200 file_path, | 1201 file_path, |
1201 is_exclusive, | 1202 is_exclusive, |
1202 CreateRelayCallback(callback))); | 1203 gdata::CreateRelayCallback(callback))); |
1203 } | 1204 } |
1204 | 1205 |
1205 void DriveFileSystem::CreateFileOnUIThread( | 1206 void DriveFileSystem::CreateFileOnUIThread( |
1206 const FilePath& file_path, | 1207 const FilePath& file_path, |
1207 bool is_exclusive, | 1208 bool is_exclusive, |
1208 const FileOperationCallback& callback) { | 1209 const FileOperationCallback& callback) { |
1209 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1210 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1210 DCHECK(!callback.is_null()); | 1211 DCHECK(!callback.is_null()); |
1211 | 1212 |
1212 // First, checks the existence of a file at |file_path|. | 1213 // First, checks the existence of a file at |file_path|. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1254 | 1255 |
1255 // No entry found at |file_path|. Let's create a brand new file. | 1256 // No entry found at |file_path|. Let's create a brand new file. |
1256 // For now, it is implemented by uploading an empty file (/dev/null). | 1257 // For now, it is implemented by uploading an empty file (/dev/null). |
1257 // TODO(kinaba): http://crbug.com/135143. Implement in a nicer way. | 1258 // TODO(kinaba): http://crbug.com/135143. Implement in a nicer way. |
1258 TransferRegularFile(FilePath(kEmptyFilePath), file_path, callback); | 1259 TransferRegularFile(FilePath(kEmptyFilePath), file_path, callback); |
1259 } | 1260 } |
1260 | 1261 |
1261 void DriveFileSystem::GetFileByPath( | 1262 void DriveFileSystem::GetFileByPath( |
1262 const FilePath& file_path, | 1263 const FilePath& file_path, |
1263 const GetFileCallback& get_file_callback, | 1264 const GetFileCallback& get_file_callback, |
1264 const GetContentCallback& get_content_callback) { | 1265 const gdata::GetContentCallback& get_content_callback) { |
1265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1266 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1267 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1267 DCHECK(!get_file_callback.is_null()); | 1268 DCHECK(!get_file_callback.is_null()); |
1268 | 1269 |
1269 RunTaskOnUIThread( | 1270 gdata::RunTaskOnUIThread( |
1270 base::Bind(&DriveFileSystem::GetFileByPathOnUIThread, | 1271 base::Bind(&DriveFileSystem::GetFileByPathOnUIThread, |
1271 ui_weak_ptr_, | 1272 ui_weak_ptr_, |
1272 file_path, | 1273 file_path, |
1273 CreateRelayCallback(get_file_callback), | 1274 gdata::CreateRelayCallback(get_file_callback), |
1274 CreateRelayCallback(get_content_callback))); | 1275 gdata::CreateRelayCallback(get_content_callback))); |
1275 } | 1276 } |
1276 | 1277 |
1277 void DriveFileSystem::GetFileByPathOnUIThread( | 1278 void DriveFileSystem::GetFileByPathOnUIThread( |
1278 const FilePath& file_path, | 1279 const FilePath& file_path, |
1279 const GetFileCallback& get_file_callback, | 1280 const GetFileCallback& get_file_callback, |
1280 const GetContentCallback& get_content_callback) { | 1281 const gdata::GetContentCallback& get_content_callback) { |
1281 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1282 DCHECK(!get_file_callback.is_null()); | 1283 DCHECK(!get_file_callback.is_null()); |
1283 | 1284 |
1284 resource_metadata_->GetEntryInfoByPath( | 1285 resource_metadata_->GetEntryInfoByPath( |
1285 file_path, | 1286 file_path, |
1286 base::Bind(&DriveFileSystem::OnGetEntryInfoCompleteForGetFileByPath, | 1287 base::Bind(&DriveFileSystem::OnGetEntryInfoCompleteForGetFileByPath, |
1287 ui_weak_ptr_, | 1288 ui_weak_ptr_, |
1288 file_path, | 1289 file_path, |
1289 CreateRelayCallback(get_file_callback), | 1290 gdata::CreateRelayCallback(get_file_callback), |
1290 CreateRelayCallback(get_content_callback))); | 1291 gdata::CreateRelayCallback(get_content_callback))); |
1291 } | 1292 } |
1292 | 1293 |
1293 void DriveFileSystem::OnGetEntryInfoCompleteForGetFileByPath( | 1294 void DriveFileSystem::OnGetEntryInfoCompleteForGetFileByPath( |
1294 const FilePath& file_path, | 1295 const FilePath& file_path, |
1295 const GetFileCallback& get_file_callback, | 1296 const GetFileCallback& get_file_callback, |
1296 const GetContentCallback& get_content_callback, | 1297 const gdata::GetContentCallback& get_content_callback, |
1297 DriveFileError error, | 1298 DriveFileError error, |
1298 scoped_ptr<DriveEntryProto> entry_proto) { | 1299 scoped_ptr<DriveEntryProto> entry_proto) { |
1299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1300 DCHECK(!get_file_callback.is_null()); | 1301 DCHECK(!get_file_callback.is_null()); |
1301 | 1302 |
1302 if (error != DRIVE_FILE_OK) { | 1303 if (error != DRIVE_FILE_OK) { |
1303 get_file_callback.Run(error, FilePath(), std::string(), REGULAR_FILE); | 1304 get_file_callback.Run(error, FilePath(), std::string(), REGULAR_FILE); |
1304 return; | 1305 return; |
1305 } | 1306 } |
1306 DCHECK(entry_proto.get()); | 1307 DCHECK(entry_proto.get()); |
1307 | 1308 |
1308 GetResolvedFileByPath(file_path, | 1309 GetResolvedFileByPath(file_path, |
1309 get_file_callback, | 1310 get_file_callback, |
1310 get_content_callback, | 1311 get_content_callback, |
1311 entry_proto.Pass()); | 1312 entry_proto.Pass()); |
1312 } | 1313 } |
1313 | 1314 |
1314 void DriveFileSystem::GetResolvedFileByPath( | 1315 void DriveFileSystem::GetResolvedFileByPath( |
1315 const FilePath& file_path, | 1316 const FilePath& file_path, |
1316 const GetFileCallback& get_file_callback, | 1317 const GetFileCallback& get_file_callback, |
1317 const GetContentCallback& get_content_callback, | 1318 const gdata::GetContentCallback& get_content_callback, |
1318 scoped_ptr<DriveEntryProto> entry_proto) { | 1319 scoped_ptr<DriveEntryProto> entry_proto) { |
1319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1320 DCHECK(!get_file_callback.is_null()); | 1321 DCHECK(!get_file_callback.is_null()); |
1321 DCHECK(entry_proto.get()); | 1322 DCHECK(entry_proto.get()); |
1322 | 1323 |
1323 if (!entry_proto->has_file_specific_info()) { | 1324 if (!entry_proto->has_file_specific_info()) { |
1324 get_file_callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, | 1325 get_file_callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, |
1325 FilePath(), | 1326 FilePath(), |
1326 std::string(), | 1327 std::string(), |
1327 REGULAR_FILE); | 1328 REGULAR_FILE); |
1328 return; | 1329 return; |
1329 } | 1330 } |
1330 | 1331 |
1331 // For a hosted document, we create a special JSON file to represent the | 1332 // For a hosted document, we create a special JSON file to represent the |
1332 // document instead of fetching the document content in one of the exported | 1333 // document instead of fetching the document content in one of the exported |
1333 // formats. The JSON file contains the edit URL and resource ID of the | 1334 // formats. The JSON file contains the edit URL and resource ID of the |
1334 // document. | 1335 // document. |
1335 if (entry_proto->file_specific_info().is_hosted_document()) { | 1336 if (entry_proto->file_specific_info().is_hosted_document()) { |
1336 DriveFileError* error = | 1337 DriveFileError* error = |
1337 new DriveFileError(DRIVE_FILE_OK); | 1338 new DriveFileError(DRIVE_FILE_OK); |
1338 FilePath* temp_file_path = new FilePath; | 1339 FilePath* temp_file_path = new FilePath; |
1339 std::string* mime_type = new std::string; | 1340 std::string* mime_type = new std::string; |
1340 DriveFileType* file_type = new DriveFileType(REGULAR_FILE); | 1341 DriveFileType* file_type = new DriveFileType(REGULAR_FILE); |
1341 util::PostBlockingPoolSequencedTaskAndReply( | 1342 gdata::util::PostBlockingPoolSequencedTaskAndReply( |
1342 FROM_HERE, | 1343 FROM_HERE, |
1343 blocking_task_runner_, | 1344 blocking_task_runner_, |
1344 base::Bind(&CreateDocumentJsonFileOnBlockingPool, | 1345 base::Bind(&CreateDocumentJsonFileOnBlockingPool, |
1345 cache_->GetCacheDirectoryPath( | 1346 cache_->GetCacheDirectoryPath( |
1346 DriveCache::CACHE_TYPE_TMP_DOCUMENTS), | 1347 DriveCache::CACHE_TYPE_TMP_DOCUMENTS), |
1347 GURL(entry_proto->file_specific_info().alternate_url()), | 1348 GURL(entry_proto->file_specific_info().alternate_url()), |
1348 entry_proto->resource_id(), | 1349 entry_proto->resource_id(), |
1349 error, | 1350 error, |
1350 temp_file_path, | 1351 temp_file_path, |
1351 mime_type, | 1352 mime_type, |
(...skipping 26 matching lines...) Expand all Loading... | |
1378 entry_proto->resource_id(), | 1379 entry_proto->resource_id(), |
1379 entry_proto->file_specific_info().file_md5(), | 1380 entry_proto->file_specific_info().file_md5(), |
1380 entry_proto->file_specific_info().content_mime_type(), | 1381 entry_proto->file_specific_info().content_mime_type(), |
1381 get_file_callback, | 1382 get_file_callback, |
1382 get_content_callback))); | 1383 get_content_callback))); |
1383 } | 1384 } |
1384 | 1385 |
1385 void DriveFileSystem::GetFileByResourceId( | 1386 void DriveFileSystem::GetFileByResourceId( |
1386 const std::string& resource_id, | 1387 const std::string& resource_id, |
1387 const GetFileCallback& get_file_callback, | 1388 const GetFileCallback& get_file_callback, |
1388 const GetContentCallback& get_content_callback) { | 1389 const gdata::GetContentCallback& get_content_callback) { |
1389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1390 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1390 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1391 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1391 RunTaskOnUIThread( | 1392 gdata::RunTaskOnUIThread( |
1392 base::Bind(&DriveFileSystem::GetFileByResourceIdOnUIThread, | 1393 base::Bind(&DriveFileSystem::GetFileByResourceIdOnUIThread, |
1393 ui_weak_ptr_, | 1394 ui_weak_ptr_, |
1394 resource_id, | 1395 resource_id, |
1395 CreateRelayCallback(get_file_callback), | 1396 gdata::CreateRelayCallback(get_file_callback), |
1396 CreateRelayCallback(get_content_callback))); | 1397 gdata::CreateRelayCallback(get_content_callback))); |
1397 } | 1398 } |
1398 | 1399 |
1399 void DriveFileSystem::GetFileByResourceIdOnUIThread( | 1400 void DriveFileSystem::GetFileByResourceIdOnUIThread( |
1400 const std::string& resource_id, | 1401 const std::string& resource_id, |
1401 const GetFileCallback& get_file_callback, | 1402 const GetFileCallback& get_file_callback, |
1402 const GetContentCallback& get_content_callback) { | 1403 const gdata::GetContentCallback& get_content_callback) { |
1403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1404 DCHECK(!get_file_callback.is_null()); | 1405 DCHECK(!get_file_callback.is_null()); |
1405 | 1406 |
1406 resource_metadata_->GetEntryInfoByResourceId( | 1407 resource_metadata_->GetEntryInfoByResourceId( |
1407 resource_id, | 1408 resource_id, |
1408 base::Bind(&DriveFileSystem::GetFileByResourceIdAfterGetEntry, | 1409 base::Bind(&DriveFileSystem::GetFileByResourceIdAfterGetEntry, |
1409 ui_weak_ptr_, | 1410 ui_weak_ptr_, |
1410 get_file_callback, | 1411 get_file_callback, |
1411 get_content_callback)); | 1412 get_content_callback)); |
1412 } | 1413 } |
1413 | 1414 |
1414 void DriveFileSystem::GetFileByResourceIdAfterGetEntry( | 1415 void DriveFileSystem::GetFileByResourceIdAfterGetEntry( |
1415 const GetFileCallback& get_file_callback, | 1416 const GetFileCallback& get_file_callback, |
1416 const GetContentCallback& get_content_callback, | 1417 const gdata::GetContentCallback& get_content_callback, |
1417 DriveFileError error, | 1418 DriveFileError error, |
1418 const FilePath& file_path, | 1419 const FilePath& file_path, |
1419 scoped_ptr<DriveEntryProto> entry_proto) { | 1420 scoped_ptr<DriveEntryProto> entry_proto) { |
1420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1421 DCHECK(!get_file_callback.is_null()); | 1422 DCHECK(!get_file_callback.is_null()); |
1422 | 1423 |
1423 if (error != DRIVE_FILE_OK) { | 1424 if (error != DRIVE_FILE_OK) { |
1424 get_file_callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, | 1425 get_file_callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, |
1425 FilePath(), | 1426 FilePath(), |
1426 std::string(), | 1427 std::string(), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1464 GetFileFromCacheParams params(in_params); | 1465 GetFileFromCacheParams params(in_params); |
1465 params.cache_file_path = cache_file_path; | 1466 params.cache_file_path = cache_file_path; |
1466 drive_service_->GetDocumentEntry( | 1467 drive_service_->GetDocumentEntry( |
1467 params.resource_id, | 1468 params.resource_id, |
1468 base::Bind(&DriveFileSystem::OnGetDocumentEntry, | 1469 base::Bind(&DriveFileSystem::OnGetDocumentEntry, |
1469 ui_weak_ptr_, | 1470 ui_weak_ptr_, |
1470 params)); | 1471 params)); |
1471 } | 1472 } |
1472 | 1473 |
1473 void DriveFileSystem::OnGetDocumentEntry(const GetFileFromCacheParams& params, | 1474 void DriveFileSystem::OnGetDocumentEntry(const GetFileFromCacheParams& params, |
1474 GDataErrorCode status, | 1475 gdata::GDataErrorCode status, |
1475 scoped_ptr<base::Value> data) { | 1476 scoped_ptr<base::Value> data) { |
1476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1477 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1477 DCHECK(!params.get_file_callback.is_null()); | 1478 DCHECK(!params.get_file_callback.is_null()); |
1478 | 1479 |
1479 const DriveFileError error = util::GDataToDriveFileError(status); | 1480 const DriveFileError error = util::GDataToDriveFileError(status); |
1480 if (error != DRIVE_FILE_OK) { | 1481 if (error != DRIVE_FILE_OK) { |
1481 params.get_file_callback.Run(error, | 1482 params.get_file_callback.Run(error, |
1482 params.cache_file_path, | 1483 params.cache_file_path, |
1483 params.mime_type, | 1484 params.mime_type, |
1484 REGULAR_FILE); | 1485 REGULAR_FILE); |
1485 return; | 1486 return; |
1486 } | 1487 } |
1487 | 1488 |
1488 scoped_ptr<DocumentEntry> doc_entry(DocumentEntry::ExtractAndParse(*data)); | 1489 scoped_ptr<gdata::DocumentEntry> doc_entry( |
1490 gdata::DocumentEntry::ExtractAndParse(*data)); | |
1489 GURL content_url = doc_entry->content_url(); | 1491 GURL content_url = doc_entry->content_url(); |
1490 int64 file_size = doc_entry->file_size(); | 1492 int64 file_size = doc_entry->file_size(); |
1491 | 1493 |
1492 DCHECK(!content_url.is_empty()); | 1494 DCHECK(!content_url.is_empty()); |
1493 DCHECK_EQ(params.resource_id, doc_entry->resource_id()); | 1495 DCHECK_EQ(params.resource_id, doc_entry->resource_id()); |
1494 resource_metadata_->RefreshFile( | 1496 resource_metadata_->RefreshFile( |
1495 doc_entry.Pass(), | 1497 doc_entry.Pass(), |
1496 base::Bind(&DriveFileSystem::CheckForSpaceBeforeDownload, | 1498 base::Bind(&DriveFileSystem::CheckForSpaceBeforeDownload, |
1497 ui_weak_ptr_, | 1499 ui_weak_ptr_, |
1498 params, | 1500 params, |
(...skipping 13 matching lines...) Expand all Loading... | |
1512 | 1514 |
1513 if (error != DRIVE_FILE_OK) { | 1515 if (error != DRIVE_FILE_OK) { |
1514 params.get_file_callback.Run(error, | 1516 params.get_file_callback.Run(error, |
1515 params.cache_file_path, | 1517 params.cache_file_path, |
1516 params.mime_type, | 1518 params.mime_type, |
1517 REGULAR_FILE); | 1519 REGULAR_FILE); |
1518 return; | 1520 return; |
1519 } | 1521 } |
1520 | 1522 |
1521 bool* has_enough_space = new bool(false); | 1523 bool* has_enough_space = new bool(false); |
1522 util::PostBlockingPoolSequencedTaskAndReply( | 1524 gdata::util::PostBlockingPoolSequencedTaskAndReply( |
1523 FROM_HERE, | 1525 FROM_HERE, |
1524 blocking_task_runner_, | 1526 blocking_task_runner_, |
1525 base::Bind(&DriveCache::FreeDiskSpaceIfNeededFor, | 1527 base::Bind(&DriveCache::FreeDiskSpaceIfNeededFor, |
1526 base::Unretained(cache_), | 1528 base::Unretained(cache_), |
1527 file_size, | 1529 file_size, |
1528 has_enough_space), | 1530 has_enough_space), |
1529 base::Bind(&DriveFileSystem::StartDownloadFileIfEnoughSpace, | 1531 base::Bind(&DriveFileSystem::StartDownloadFileIfEnoughSpace, |
1530 ui_weak_ptr_, | 1532 ui_weak_ptr_, |
1531 params, | 1533 params, |
1532 content_url, | 1534 content_url, |
(...skipping 28 matching lines...) Expand all Loading... | |
1561 params), | 1563 params), |
1562 params.get_content_callback); | 1564 params.get_content_callback); |
1563 } | 1565 } |
1564 | 1566 |
1565 void DriveFileSystem::GetEntryInfoByPath(const FilePath& file_path, | 1567 void DriveFileSystem::GetEntryInfoByPath(const FilePath& file_path, |
1566 const GetEntryInfoCallback& callback) { | 1568 const GetEntryInfoCallback& callback) { |
1567 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1569 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1568 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1570 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1569 DCHECK(!callback.is_null()); | 1571 DCHECK(!callback.is_null()); |
1570 | 1572 |
1571 RunTaskOnUIThread( | 1573 gdata::RunTaskOnUIThread( |
1572 base::Bind(&DriveFileSystem::GetEntryInfoByPathOnUIThread, | 1574 base::Bind(&DriveFileSystem::GetEntryInfoByPathOnUIThread, |
1573 ui_weak_ptr_, | 1575 ui_weak_ptr_, |
1574 file_path, | 1576 file_path, |
1575 CreateRelayCallback(callback))); | 1577 gdata::CreateRelayCallback(callback))); |
1576 } | 1578 } |
1577 | 1579 |
1578 void DriveFileSystem::GetEntryInfoByPathOnUIThread( | 1580 void DriveFileSystem::GetEntryInfoByPathOnUIThread( |
1579 const FilePath& file_path, | 1581 const FilePath& file_path, |
1580 const GetEntryInfoCallback& callback) { | 1582 const GetEntryInfoCallback& callback) { |
1581 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1583 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1582 DCHECK(!callback.is_null()); | 1584 DCHECK(!callback.is_null()); |
1583 | 1585 |
1584 LoadFeedIfNeeded( | 1586 LoadFeedIfNeeded( |
1585 base::Bind(&DriveFileSystem::GetEntryInfoByPathOnUIThreadAfterLoad, | 1587 base::Bind(&DriveFileSystem::GetEntryInfoByPathOnUIThreadAfterLoad, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1623 CheckLocalModificationAndRun(entry_proto.Pass(), callback); | 1625 CheckLocalModificationAndRun(entry_proto.Pass(), callback); |
1624 } | 1626 } |
1625 | 1627 |
1626 void DriveFileSystem::ReadDirectoryByPath( | 1628 void DriveFileSystem::ReadDirectoryByPath( |
1627 const FilePath& directory_path, | 1629 const FilePath& directory_path, |
1628 const ReadDirectoryWithSettingCallback& callback) { | 1630 const ReadDirectoryWithSettingCallback& callback) { |
1629 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1631 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1630 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1632 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1631 DCHECK(!callback.is_null()); | 1633 DCHECK(!callback.is_null()); |
1632 | 1634 |
1633 RunTaskOnUIThread( | 1635 gdata::RunTaskOnUIThread( |
1634 base::Bind(&DriveFileSystem::ReadDirectoryByPathOnUIThread, | 1636 base::Bind(&DriveFileSystem::ReadDirectoryByPathOnUIThread, |
1635 ui_weak_ptr_, | 1637 ui_weak_ptr_, |
1636 directory_path, | 1638 directory_path, |
1637 CreateRelayCallback(callback))); | 1639 gdata::CreateRelayCallback(callback))); |
1638 } | 1640 } |
1639 | 1641 |
1640 void DriveFileSystem::ReadDirectoryByPathOnUIThread( | 1642 void DriveFileSystem::ReadDirectoryByPathOnUIThread( |
1641 const FilePath& directory_path, | 1643 const FilePath& directory_path, |
1642 const ReadDirectoryWithSettingCallback& callback) { | 1644 const ReadDirectoryWithSettingCallback& callback) { |
1643 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1645 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1644 DCHECK(!callback.is_null()); | 1646 DCHECK(!callback.is_null()); |
1645 | 1647 |
1646 LoadFeedIfNeeded( | 1648 LoadFeedIfNeeded( |
1647 base::Bind(&DriveFileSystem::ReadDirectoryByPathOnUIThreadAfterLoad, | 1649 base::Bind(&DriveFileSystem::ReadDirectoryByPathOnUIThreadAfterLoad, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1685 return; | 1687 return; |
1686 } | 1688 } |
1687 DCHECK(entries.get()); // This is valid for emptry directories too. | 1689 DCHECK(entries.get()); // This is valid for emptry directories too. |
1688 | 1690 |
1689 callback.Run(DRIVE_FILE_OK, hide_hosted_docs_, entries.Pass()); | 1691 callback.Run(DRIVE_FILE_OK, hide_hosted_docs_, entries.Pass()); |
1690 } | 1692 } |
1691 | 1693 |
1692 void DriveFileSystem::RequestDirectoryRefresh(const FilePath& directory_path) { | 1694 void DriveFileSystem::RequestDirectoryRefresh(const FilePath& directory_path) { |
1693 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1695 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1694 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1696 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1695 RunTaskOnUIThread( | 1697 gdata::RunTaskOnUIThread( |
1696 base::Bind(&DriveFileSystem::RequestDirectoryRefreshOnUIThread, | 1698 base::Bind(&DriveFileSystem::RequestDirectoryRefreshOnUIThread, |
1697 ui_weak_ptr_, | 1699 ui_weak_ptr_, |
1698 directory_path)); | 1700 directory_path)); |
1699 } | 1701 } |
1700 | 1702 |
1701 void DriveFileSystem::RequestDirectoryRefreshOnUIThread( | 1703 void DriveFileSystem::RequestDirectoryRefreshOnUIThread( |
1702 const FilePath& directory_path) { | 1704 const FilePath& directory_path) { |
1703 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1705 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1704 | 1706 |
1705 // Make sure the destination directory exists. | 1707 // Make sure the destination directory exists. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1767 FileOperationCallback())); | 1769 FileOperationCallback())); |
1768 } | 1770 } |
1769 | 1771 |
1770 void DriveFileSystem::UpdateFileByResourceId( | 1772 void DriveFileSystem::UpdateFileByResourceId( |
1771 const std::string& resource_id, | 1773 const std::string& resource_id, |
1772 const FileOperationCallback& callback) { | 1774 const FileOperationCallback& callback) { |
1773 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1775 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1774 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1776 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1775 DCHECK(!callback.is_null()); | 1777 DCHECK(!callback.is_null()); |
1776 | 1778 |
1777 RunTaskOnUIThread( | 1779 gdata::RunTaskOnUIThread( |
1778 base::Bind(&DriveFileSystem::UpdateFileByResourceIdOnUIThread, | 1780 base::Bind(&DriveFileSystem::UpdateFileByResourceIdOnUIThread, |
1779 ui_weak_ptr_, | 1781 ui_weak_ptr_, |
1780 resource_id, | 1782 resource_id, |
1781 CreateRelayCallback(callback))); | 1783 gdata::CreateRelayCallback(callback))); |
1782 } | 1784 } |
1783 | 1785 |
1784 void DriveFileSystem::UpdateFileByResourceIdOnUIThread( | 1786 void DriveFileSystem::UpdateFileByResourceIdOnUIThread( |
1785 const std::string& resource_id, | 1787 const std::string& resource_id, |
1786 const FileOperationCallback& callback) { | 1788 const FileOperationCallback& callback) { |
1787 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1789 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1788 DCHECK(!callback.is_null()); | 1790 DCHECK(!callback.is_null()); |
1789 | 1791 |
1790 // TODO(satorux): GetEntryInfoByResourceId() is called twice for | 1792 // TODO(satorux): GetEntryInfoByResourceId() is called twice for |
1791 // UpdateFileByResourceIdOnUIThread(). crbug.com/143873 | 1793 // UpdateFileByResourceIdOnUIThread(). crbug.com/143873 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1838 | 1840 |
1839 if (error != DRIVE_FILE_OK) { | 1841 if (error != DRIVE_FILE_OK) { |
1840 callback.Run(error); | 1842 callback.Run(error); |
1841 return; | 1843 return; |
1842 } | 1844 } |
1843 | 1845 |
1844 // Gets the size of the cache file. Since the file is locally modified, the | 1846 // Gets the size of the cache file. Since the file is locally modified, the |
1845 // file size information stored in DriveEntry is not correct. | 1847 // file size information stored in DriveEntry is not correct. |
1846 DriveFileError* get_size_error = new DriveFileError(DRIVE_FILE_ERROR_FAILED); | 1848 DriveFileError* get_size_error = new DriveFileError(DRIVE_FILE_ERROR_FAILED); |
1847 int64* file_size = new int64(-1); | 1849 int64* file_size = new int64(-1); |
1848 util::PostBlockingPoolSequencedTaskAndReply( | 1850 gdata::util::PostBlockingPoolSequencedTaskAndReply( |
1849 FROM_HERE, | 1851 FROM_HERE, |
1850 blocking_task_runner_, | 1852 blocking_task_runner_, |
1851 base::Bind(&GetLocalFileSizeOnBlockingPool, | 1853 base::Bind(&GetLocalFileSizeOnBlockingPool, |
1852 cache_file_path, | 1854 cache_file_path, |
1853 get_size_error, | 1855 get_size_error, |
1854 file_size), | 1856 file_size), |
1855 base::Bind(&DriveFileSystem::OnGetFileSizeCompleteForUpdateFile, | 1857 base::Bind(&DriveFileSystem::OnGetFileSizeCompleteForUpdateFile, |
1856 ui_weak_ptr_, | 1858 ui_weak_ptr_, |
1857 callback, | 1859 callback, |
1858 drive_file_path, | 1860 drive_file_path, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1890 ui_weak_ptr_, | 1892 ui_weak_ptr_, |
1891 callback), | 1893 callback), |
1892 UploaderReadyCallback()); | 1894 UploaderReadyCallback()); |
1893 } | 1895 } |
1894 | 1896 |
1895 void DriveFileSystem::OnUpdatedFileUploaded( | 1897 void DriveFileSystem::OnUpdatedFileUploaded( |
1896 const FileOperationCallback& callback, | 1898 const FileOperationCallback& callback, |
1897 DriveFileError error, | 1899 DriveFileError error, |
1898 const FilePath& drive_path, | 1900 const FilePath& drive_path, |
1899 const FilePath& file_path, | 1901 const FilePath& file_path, |
1900 scoped_ptr<DocumentEntry> document_entry) { | 1902 scoped_ptr<gdata::DocumentEntry> document_entry) { |
1901 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1903 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1902 | 1904 |
1903 if (error != DRIVE_FILE_OK) { | 1905 if (error != DRIVE_FILE_OK) { |
1904 if (!callback.is_null()) | 1906 if (!callback.is_null()) |
1905 callback.Run(error); | 1907 callback.Run(error); |
1906 return; | 1908 return; |
1907 } | 1909 } |
1908 | 1910 |
1909 AddUploadedFile(UPLOAD_EXISTING_FILE, | 1911 AddUploadedFile(gdata::UPLOAD_EXISTING_FILE, |
1910 drive_path.DirName(), | 1912 drive_path.DirName(), |
1911 document_entry.Pass(), | 1913 document_entry.Pass(), |
1912 file_path, | 1914 file_path, |
1913 DriveCache::FILE_OPERATION_MOVE, | 1915 DriveCache::FILE_OPERATION_MOVE, |
1914 base::Bind(&OnAddUploadFileCompleted, callback, error)); | 1916 base::Bind(&OnAddUploadFileCompleted, callback, error)); |
1915 } | 1917 } |
1916 | 1918 |
1917 void DriveFileSystem::GetAvailableSpace( | 1919 void DriveFileSystem::GetAvailableSpace( |
1918 const GetAvailableSpaceCallback& callback) { | 1920 const GetAvailableSpaceCallback& callback) { |
1919 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 1921 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
1920 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 1922 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
1921 RunTaskOnUIThread(base::Bind(&DriveFileSystem::GetAvailableSpaceOnUIThread, | 1923 gdata::RunTaskOnUIThread( |
1922 ui_weak_ptr_, | 1924 base::Bind(&DriveFileSystem::GetAvailableSpaceOnUIThread, |
1923 CreateRelayCallback(callback))); | 1925 ui_weak_ptr_, |
1926 gdata::CreateRelayCallback(callback))); | |
1924 } | 1927 } |
1925 | 1928 |
1926 void DriveFileSystem::GetAvailableSpaceOnUIThread( | 1929 void DriveFileSystem::GetAvailableSpaceOnUIThread( |
1927 const GetAvailableSpaceCallback& callback) { | 1930 const GetAvailableSpaceCallback& callback) { |
1928 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1931 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1929 DCHECK(!callback.is_null()); | 1932 DCHECK(!callback.is_null()); |
1930 | 1933 |
1931 drive_service_->GetAccountMetadata( | 1934 drive_service_->GetAccountMetadata( |
1932 gdata::util::IsDriveV2ApiEnabled() ? | 1935 gdata::util::IsDriveV2ApiEnabled() ? |
1933 base::Bind(&DriveFileSystem::OnGetAboutResource, | 1936 base::Bind(&DriveFileSystem::OnGetAboutResource, |
1934 ui_weak_ptr_, | 1937 ui_weak_ptr_, |
1935 callback) : | 1938 callback) : |
1936 base::Bind(&DriveFileSystem::OnGetAvailableSpace, | 1939 base::Bind(&DriveFileSystem::OnGetAvailableSpace, |
1937 ui_weak_ptr_, | 1940 ui_weak_ptr_, |
1938 callback)); | 1941 callback)); |
1939 } | 1942 } |
1940 | 1943 |
1941 void DriveFileSystem::OnGetAvailableSpace( | 1944 void DriveFileSystem::OnGetAvailableSpace( |
1942 const GetAvailableSpaceCallback& callback, | 1945 const GetAvailableSpaceCallback& callback, |
1943 GDataErrorCode status, | 1946 gdata::GDataErrorCode status, |
1944 scoped_ptr<base::Value> data) { | 1947 scoped_ptr<base::Value> data) { |
1945 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1948 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1946 DCHECK(!callback.is_null()); | 1949 DCHECK(!callback.is_null()); |
1947 | 1950 |
1948 DriveFileError error = util::GDataToDriveFileError(status); | 1951 DriveFileError error = util::GDataToDriveFileError(status); |
1949 if (error != DRIVE_FILE_OK) { | 1952 if (error != DRIVE_FILE_OK) { |
1950 callback.Run(error, -1, -1); | 1953 callback.Run(error, -1, -1); |
1951 return; | 1954 return; |
1952 } | 1955 } |
1953 | 1956 |
1954 scoped_ptr<AccountMetadataFeed> feed; | 1957 scoped_ptr<gdata::AccountMetadataFeed> feed; |
1955 if (data.get()) | 1958 if (data.get()) |
1956 feed = AccountMetadataFeed::CreateFrom(*data); | 1959 feed = gdata::AccountMetadataFeed::CreateFrom(*data); |
1957 if (!feed.get()) { | 1960 if (!feed.get()) { |
1958 callback.Run(DRIVE_FILE_ERROR_FAILED, -1, -1); | 1961 callback.Run(DRIVE_FILE_ERROR_FAILED, -1, -1); |
1959 return; | 1962 return; |
1960 } | 1963 } |
1961 | 1964 |
1962 callback.Run(DRIVE_FILE_OK, | 1965 callback.Run(DRIVE_FILE_OK, |
1963 feed->quota_bytes_total(), | 1966 feed->quota_bytes_total(), |
1964 feed->quota_bytes_used()); | 1967 feed->quota_bytes_used()); |
1965 } | 1968 } |
1966 | 1969 |
1967 void DriveFileSystem::OnGetAboutResource( | 1970 void DriveFileSystem::OnGetAboutResource( |
1968 const GetAvailableSpaceCallback& callback, | 1971 const GetAvailableSpaceCallback& callback, |
1969 GDataErrorCode status, | 1972 gdata::GDataErrorCode status, |
1970 scoped_ptr<base::Value> resource_json) { | 1973 scoped_ptr<base::Value> resource_json) { |
1971 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1974 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1972 DCHECK(!callback.is_null()); | 1975 DCHECK(!callback.is_null()); |
1973 | 1976 |
1974 DriveFileError error = util::GDataToDriveFileError(status); | 1977 DriveFileError error = util::GDataToDriveFileError(status); |
1975 if (error != DRIVE_FILE_OK) { | 1978 if (error != DRIVE_FILE_OK) { |
1976 callback.Run(error, -1, -1); | 1979 callback.Run(error, -1, -1); |
1977 return; | 1980 return; |
1978 } | 1981 } |
1979 | 1982 |
1980 scoped_ptr<AboutResource> about; | 1983 scoped_ptr<gdata::AboutResource> about; |
1981 if (resource_json.get()) | 1984 if (resource_json.get()) |
1982 about = AboutResource::CreateFrom(*resource_json); | 1985 about = gdata::AboutResource::CreateFrom(*resource_json); |
1983 | 1986 |
1984 if (!about.get()) { | 1987 if (!about.get()) { |
1985 callback.Run(DRIVE_FILE_ERROR_FAILED, -1, -1); | 1988 callback.Run(DRIVE_FILE_ERROR_FAILED, -1, -1); |
1986 return; | 1989 return; |
1987 } | 1990 } |
1988 | 1991 |
1989 callback.Run(DRIVE_FILE_OK, | 1992 callback.Run(DRIVE_FILE_OK, |
1990 about->quota_bytes_total(), | 1993 about->quota_bytes_total(), |
1991 about->quota_bytes_used()); | 1994 about->quota_bytes_used()); |
1992 } | 1995 } |
1993 | 1996 |
1994 void DriveFileSystem::AddNewDirectory( | 1997 void DriveFileSystem::AddNewDirectory( |
1995 const CreateDirectoryParams& params, | 1998 const CreateDirectoryParams& params, |
1996 GDataErrorCode status, | 1999 gdata::GDataErrorCode status, |
1997 scoped_ptr<base::Value> data) { | 2000 scoped_ptr<base::Value> data) { |
1998 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2001 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
1999 DCHECK(!params.callback.is_null()); | 2002 DCHECK(!params.callback.is_null()); |
2000 | 2003 |
2001 DriveFileError error = util::GDataToDriveFileError(status); | 2004 DriveFileError error = util::GDataToDriveFileError(status); |
2002 if (error != DRIVE_FILE_OK) { | 2005 if (error != DRIVE_FILE_OK) { |
2003 params.callback.Run(error); | 2006 params.callback.Run(error); |
2004 return; | 2007 return; |
2005 } | 2008 } |
2006 | 2009 |
2007 resource_metadata_->AddEntryToDirectory( | 2010 resource_metadata_->AddEntryToDirectory( |
2008 params.created_directory_path.DirName(), | 2011 params.created_directory_path.DirName(), |
2009 scoped_ptr<DocumentEntry>(DocumentEntry::ExtractAndParse(*data)), | 2012 scoped_ptr<gdata::DocumentEntry>( |
2013 gdata::DocumentEntry::ExtractAndParse(*data)), | |
2010 base::Bind(&DriveFileSystem::ContinueCreateDirectory, | 2014 base::Bind(&DriveFileSystem::ContinueCreateDirectory, |
2011 ui_weak_ptr_, | 2015 ui_weak_ptr_, |
2012 params)); | 2016 params)); |
2013 } | 2017 } |
2014 | 2018 |
2015 void DriveFileSystem::ContinueCreateDirectory( | 2019 void DriveFileSystem::ContinueCreateDirectory( |
2016 const CreateDirectoryParams& params, | 2020 const CreateDirectoryParams& params, |
2017 DriveFileError error, | 2021 DriveFileError error, |
2018 const FilePath& moved_file_path) { | 2022 const FilePath& moved_file_path) { |
2019 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2023 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2053 return; | 2057 return; |
2054 } | 2058 } |
2055 | 2059 |
2056 // The search results will be returned using virtual directory. | 2060 // The search results will be returned using virtual directory. |
2057 // The directory is not really part of the file system, so it has no parent or | 2061 // The directory is not really part of the file system, so it has no parent or |
2058 // root. | 2062 // root. |
2059 std::vector<SearchResultInfo>* results(new std::vector<SearchResultInfo>()); | 2063 std::vector<SearchResultInfo>* results(new std::vector<SearchResultInfo>()); |
2060 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results); | 2064 scoped_ptr<std::vector<SearchResultInfo> > result_vec(results); |
2061 | 2065 |
2062 DCHECK_EQ(1u, params->feed_list.size()); | 2066 DCHECK_EQ(1u, params->feed_list.size()); |
2063 DocumentFeed* feed = params->feed_list[0]; | 2067 gdata::DocumentFeed* feed = params->feed_list[0]; |
2064 | 2068 |
2065 // TODO(tbarzic): Limit total number of returned results for the query. | 2069 // TODO(tbarzic): Limit total number of returned results for the query. |
2066 GURL next_feed; | 2070 GURL next_feed; |
2067 feed->GetNextFeedURL(&next_feed); | 2071 feed->GetNextFeedURL(&next_feed); |
2068 | 2072 |
2069 const base::Closure callback = base::Bind( | 2073 const base::Closure callback = base::Bind( |
2070 search_callback, DRIVE_FILE_OK, next_feed, base::Passed(&result_vec)); | 2074 search_callback, DRIVE_FILE_OK, next_feed, base::Passed(&result_vec)); |
2071 | 2075 |
2072 std::vector<DocumentEntry*> entries; | 2076 std::vector<gdata::DocumentEntry*> entries; |
2073 feed->ReleaseEntries(&entries); | 2077 feed->ReleaseEntries(&entries); |
2074 if (entries.empty()) { | 2078 if (entries.empty()) { |
2075 callback.Run(); | 2079 callback.Run(); |
2076 return; | 2080 return; |
2077 } | 2081 } |
2078 | 2082 |
2079 DVLOG(1) << "OnSearch number of entries=" << entries.size(); | 2083 DVLOG(1) << "OnSearch number of entries=" << entries.size(); |
2080 // Go through all entries generated by the feed and add them to the search | 2084 // Go through all entries generated by the feed and add them to the search |
2081 // result directory. | 2085 // result directory. |
2082 for (size_t i = 0; i < entries.size(); ++i) { | 2086 for (size_t i = 0; i < entries.size(); ++i) { |
2083 // Run the callback if this is the last iteration of the loop. | 2087 // Run the callback if this is the last iteration of the loop. |
2084 const bool should_run_callback = (i+1 == entries.size()); | 2088 const bool should_run_callback = (i+1 == entries.size()); |
2085 resource_metadata_->RefreshFile( | 2089 resource_metadata_->RefreshFile( |
2086 scoped_ptr<DocumentEntry>(entries[i]), | 2090 scoped_ptr<gdata::DocumentEntry>(entries[i]), |
2087 base::Bind(&DriveFileSystem::AddToSearchResults, | 2091 base::Bind(&DriveFileSystem::AddToSearchResults, |
2088 ui_weak_ptr_, | 2092 ui_weak_ptr_, |
2089 results, | 2093 results, |
2090 should_run_callback ? callback : base::Closure())); | 2094 should_run_callback ? callback : base::Closure())); |
2091 } | 2095 } |
2092 } | 2096 } |
2093 | 2097 |
2094 void DriveFileSystem::AddToSearchResults( | 2098 void DriveFileSystem::AddToSearchResults( |
2095 std::vector<SearchResultInfo>* results, | 2099 std::vector<SearchResultInfo>* results, |
2096 const base::Closure& callback, | 2100 const base::Closure& callback, |
(...skipping 21 matching lines...) Expand all Loading... | |
2118 callback.Run(); | 2122 callback.Run(); |
2119 } | 2123 } |
2120 | 2124 |
2121 void DriveFileSystem::Search(const std::string& search_query, | 2125 void DriveFileSystem::Search(const std::string& search_query, |
2122 const GURL& next_feed, | 2126 const GURL& next_feed, |
2123 const SearchCallback& callback) { | 2127 const SearchCallback& callback) { |
2124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
2125 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2129 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2126 DCHECK(!callback.is_null()); | 2130 DCHECK(!callback.is_null()); |
2127 | 2131 |
2128 RunTaskOnUIThread(base::Bind(&DriveFileSystem::SearchAsyncOnUIThread, | 2132 gdata::RunTaskOnUIThread(base::Bind(&DriveFileSystem::SearchAsyncOnUIThread, |
2129 ui_weak_ptr_, | 2133 ui_weak_ptr_, |
2130 search_query, | 2134 search_query, |
2131 next_feed, | 2135 next_feed, |
2132 CreateRelayCallback(callback))); | 2136 gdata::CreateRelayCallback(callback))); |
2133 } | 2137 } |
2134 | 2138 |
2135 void DriveFileSystem::SearchAsyncOnUIThread( | 2139 void DriveFileSystem::SearchAsyncOnUIThread( |
2136 const std::string& search_query, | 2140 const std::string& search_query, |
2137 const GURL& next_feed, | 2141 const GURL& next_feed, |
2138 const SearchCallback& callback) { | 2142 const SearchCallback& callback) { |
2139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2140 DCHECK(!callback.is_null()); | 2144 DCHECK(!callback.is_null()); |
2141 | 2145 |
2142 feed_loader_->SearchFromServer( | 2146 feed_loader_->SearchFromServer( |
(...skipping 26 matching lines...) Expand all Loading... | |
2169 | 2173 |
2170 void DriveFileSystem::LoadRootFeedFromCacheForTesting() { | 2174 void DriveFileSystem::LoadRootFeedFromCacheForTesting() { |
2171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2172 | 2176 |
2173 feed_loader_->LoadFromCache( | 2177 feed_loader_->LoadFromCache( |
2174 false, // should_load_from_server. | 2178 false, // should_load_from_server. |
2175 FileOperationCallback()); | 2179 FileOperationCallback()); |
2176 } | 2180 } |
2177 | 2181 |
2178 DriveFileError DriveFileSystem::UpdateFromFeedForTesting( | 2182 DriveFileError DriveFileSystem::UpdateFromFeedForTesting( |
2179 const ScopedVector<DocumentFeed>& feed_list, | 2183 const ScopedVector<gdata::DocumentFeed>& feed_list, |
2180 int64 start_changestamp, | 2184 int64 start_changestamp, |
2181 int64 root_feed_changestamp) { | 2185 int64 root_feed_changestamp) { |
2182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2186 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2183 | 2187 |
2184 return feed_loader_->UpdateFromFeed(feed_list, | 2188 return feed_loader_->UpdateFromFeed(feed_list, |
2185 start_changestamp, | 2189 start_changestamp, |
2186 root_feed_changestamp); | 2190 root_feed_changestamp); |
2187 } | 2191 } |
2188 | 2192 |
2189 void DriveFileSystem::OnCopyDocumentCompleted( | 2193 void DriveFileSystem::OnCopyDocumentCompleted( |
2190 const FilePath& dir_path, | 2194 const FilePath& dir_path, |
2191 const FileOperationCallback& callback, | 2195 const FileOperationCallback& callback, |
2192 GDataErrorCode status, | 2196 gdata::GDataErrorCode status, |
2193 scoped_ptr<base::Value> data) { | 2197 scoped_ptr<base::Value> data) { |
2194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2195 DCHECK(!callback.is_null()); | 2199 DCHECK(!callback.is_null()); |
2196 | 2200 |
2197 DriveFileError error = util::GDataToDriveFileError(status); | 2201 DriveFileError error = util::GDataToDriveFileError(status); |
2198 if (error != DRIVE_FILE_OK) { | 2202 if (error != DRIVE_FILE_OK) { |
2199 callback.Run(error); | 2203 callback.Run(error); |
2200 return; | 2204 return; |
2201 } | 2205 } |
2202 | 2206 |
2203 // |entry| was added in the root directory on the server, so we should | 2207 // |entry| was added in the root directory on the server, so we should |
2204 // first add it to |root_| to mirror the state and then move it to the | 2208 // first add it to |root_| to mirror the state and then move it to the |
2205 // destination directory by MoveEntryFromRootDirectory(). | 2209 // destination directory by MoveEntryFromRootDirectory(). |
2206 resource_metadata_->AddEntryToDirectory( | 2210 resource_metadata_->AddEntryToDirectory( |
2207 resource_metadata_->root()->GetFilePath(), | 2211 resource_metadata_->root()->GetFilePath(), |
2208 scoped_ptr<DocumentEntry>(DocumentEntry::ExtractAndParse(*data)), | 2212 scoped_ptr<gdata::DocumentEntry>( |
2213 gdata::DocumentEntry::ExtractAndParse(*data)), | |
2209 base::Bind(&DriveFileSystem::MoveEntryFromRootDirectory, | 2214 base::Bind(&DriveFileSystem::MoveEntryFromRootDirectory, |
2210 ui_weak_ptr_, | 2215 ui_weak_ptr_, |
2211 dir_path, | 2216 dir_path, |
2212 callback)); | 2217 callback)); |
2213 } | 2218 } |
2214 | 2219 |
2215 void DriveFileSystem::OnFileDownloaded( | 2220 void DriveFileSystem::OnFileDownloaded( |
2216 const GetFileFromCacheParams& params, | 2221 const GetFileFromCacheParams& params, |
2217 GDataErrorCode status, | 2222 gdata::GDataErrorCode status, |
2218 const GURL& content_url, | 2223 const GURL& content_url, |
2219 const FilePath& downloaded_file_path) { | 2224 const FilePath& downloaded_file_path) { |
2220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2225 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2221 DCHECK(!params.get_file_callback.is_null()); | 2226 DCHECK(!params.get_file_callback.is_null()); |
2222 | 2227 |
2223 // If user cancels download of a pinned-but-not-fetched file, mark file as | 2228 // If user cancels download of a pinned-but-not-fetched file, mark file as |
2224 // unpinned so that we do not sync the file again. | 2229 // unpinned so that we do not sync the file again. |
2225 if (status == GDATA_CANCELLED) { | 2230 if (status == gdata::GDATA_CANCELLED) { |
2226 cache_->GetCacheEntryOnUIThread( | 2231 cache_->GetCacheEntryOnUIThread( |
2227 params.resource_id, | 2232 params.resource_id, |
2228 params.md5, | 2233 params.md5, |
2229 base::Bind(&DriveFileSystem::UnpinIfPinned, | 2234 base::Bind(&DriveFileSystem::UnpinIfPinned, |
2230 ui_weak_ptr_, | 2235 ui_weak_ptr_, |
2231 params.resource_id, | 2236 params.resource_id, |
2232 params.md5)); | 2237 params.md5)); |
2233 } | 2238 } |
2234 | 2239 |
2235 // At this point, the disk can be full or nearly full for several reasons: | 2240 // At this point, the disk can be full or nearly full for several reasons: |
2236 // - The expected file size was incorrect and the file was larger | 2241 // - The expected file size was incorrect and the file was larger |
2237 // - There was an in-flight download operation and it used up space | 2242 // - There was an in-flight download operation and it used up space |
2238 // - The disk became full for some user actions we cannot control | 2243 // - The disk became full for some user actions we cannot control |
2239 // (ex. the user might have downloaded a large file from a regular web site) | 2244 // (ex. the user might have downloaded a large file from a regular web site) |
2240 // | 2245 // |
2241 // If we don't have enough space, we return PLATFORM_FILE_ERROR_NO_SPACE, | 2246 // If we don't have enough space, we return PLATFORM_FILE_ERROR_NO_SPACE, |
2242 // and try to free up space, even if the file was downloaded successfully. | 2247 // and try to free up space, even if the file was downloaded successfully. |
2243 bool* has_enough_space = new bool(false); | 2248 bool* has_enough_space = new bool(false); |
2244 util::PostBlockingPoolSequencedTaskAndReply( | 2249 gdata::util::PostBlockingPoolSequencedTaskAndReply( |
2245 FROM_HERE, | 2250 FROM_HERE, |
2246 blocking_task_runner_, | 2251 blocking_task_runner_, |
2247 base::Bind(&DriveCache::FreeDiskSpaceIfNeededFor, | 2252 base::Bind(&DriveCache::FreeDiskSpaceIfNeededFor, |
2248 base::Unretained(cache_), | 2253 base::Unretained(cache_), |
2249 0, | 2254 0, |
2250 has_enough_space), | 2255 has_enough_space), |
2251 base::Bind(&DriveFileSystem::OnFileDownloadedAndSpaceChecked, | 2256 base::Bind(&DriveFileSystem::OnFileDownloadedAndSpaceChecked, |
2252 ui_weak_ptr_, | 2257 ui_weak_ptr_, |
2253 params, | 2258 params, |
2254 status, | 2259 status, |
2255 content_url, | 2260 content_url, |
2256 downloaded_file_path, | 2261 downloaded_file_path, |
2257 base::Owned(has_enough_space))); | 2262 base::Owned(has_enough_space))); |
2258 } | 2263 } |
2259 | 2264 |
2260 void DriveFileSystem::UnpinIfPinned( | 2265 void DriveFileSystem::UnpinIfPinned( |
2261 const std::string& resource_id, | 2266 const std::string& resource_id, |
2262 const std::string& md5, | 2267 const std::string& md5, |
2263 bool success, | 2268 bool success, |
2264 const DriveCacheEntry& cache_entry) { | 2269 const DriveCacheEntry& cache_entry) { |
2265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2266 // TODO(hshi): http://crbug.com/127138 notify when file properties change. | 2271 // TODO(hshi): http://crbug.com/127138 notify when file properties change. |
2267 // This allows file manager to clear the "Available offline" checkbox. | 2272 // This allows file manager to clear the "Available offline" checkbox. |
2268 if (success && cache_entry.is_pinned()) | 2273 if (success && cache_entry.is_pinned()) |
2269 cache_->UnpinOnUIThread(resource_id, md5, CacheOperationCallback()); | 2274 cache_->UnpinOnUIThread(resource_id, md5, CacheOperationCallback()); |
2270 } | 2275 } |
2271 | 2276 |
2272 void DriveFileSystem::OnFileDownloadedAndSpaceChecked( | 2277 void DriveFileSystem::OnFileDownloadedAndSpaceChecked( |
2273 const GetFileFromCacheParams& params, | 2278 const GetFileFromCacheParams& params, |
2274 GDataErrorCode status, | 2279 gdata::GDataErrorCode status, |
2275 const GURL& content_url, | 2280 const GURL& content_url, |
2276 const FilePath& downloaded_file_path, | 2281 const FilePath& downloaded_file_path, |
2277 bool* has_enough_space) { | 2282 bool* has_enough_space) { |
2278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2279 DCHECK(!params.get_file_callback.is_null()); | 2284 DCHECK(!params.get_file_callback.is_null()); |
2280 | 2285 |
2281 DriveFileError error = util::GDataToDriveFileError(status); | 2286 DriveFileError error = util::GDataToDriveFileError(status); |
2282 | 2287 |
2283 // Make sure that downloaded file is properly stored in cache. We don't have | 2288 // Make sure that downloaded file is properly stored in cache. We don't have |
2284 // to wait for this operation to finish since the user can already use the | 2289 // to wait for this operation to finish since the user can already use the |
2285 // downloaded file. | 2290 // downloaded file. |
2286 if (error == DRIVE_FILE_OK) { | 2291 if (error == DRIVE_FILE_OK) { |
2287 if (*has_enough_space) { | 2292 if (*has_enough_space) { |
2288 cache_->StoreOnUIThread( | 2293 cache_->StoreOnUIThread( |
2289 params.resource_id, | 2294 params.resource_id, |
2290 params.md5, | 2295 params.md5, |
2291 downloaded_file_path, | 2296 downloaded_file_path, |
2292 DriveCache::FILE_OPERATION_MOVE, | 2297 DriveCache::FILE_OPERATION_MOVE, |
2293 base::Bind(&DriveFileSystem::OnDownloadStoredToCache, | 2298 base::Bind(&DriveFileSystem::OnDownloadStoredToCache, |
2294 ui_weak_ptr_)); | 2299 ui_weak_ptr_)); |
2295 } else { | 2300 } else { |
2296 // If we don't have enough space, remove the downloaded file, and | 2301 // If we don't have enough space, remove the downloaded file, and |
2297 // report "no space" error. | 2302 // report "no space" error. |
2298 util::PostBlockingPoolSequencedTask( | 2303 gdata::util::PostBlockingPoolSequencedTask( |
2299 FROM_HERE, | 2304 FROM_HERE, |
2300 blocking_task_runner_, | 2305 blocking_task_runner_, |
2301 base::Bind(base::IgnoreResult(&file_util::Delete), | 2306 base::Bind(base::IgnoreResult(&file_util::Delete), |
2302 downloaded_file_path, | 2307 downloaded_file_path, |
2303 false /* recursive*/)); | 2308 false /* recursive*/)); |
2304 error = DRIVE_FILE_ERROR_NO_SPACE; | 2309 error = DRIVE_FILE_ERROR_NO_SPACE; |
2305 } | 2310 } |
2306 } | 2311 } |
2307 | 2312 |
2308 params.get_file_callback.Run(error, | 2313 params.get_file_callback.Run(error, |
2309 downloaded_file_path, | 2314 downloaded_file_path, |
2310 params.mime_type, | 2315 params.mime_type, |
2311 REGULAR_FILE); | 2316 REGULAR_FILE); |
2312 } | 2317 } |
2313 | 2318 |
2314 void DriveFileSystem::OnDownloadStoredToCache(DriveFileError error, | 2319 void DriveFileSystem::OnDownloadStoredToCache(DriveFileError error, |
2315 const std::string& resource_id, | 2320 const std::string& resource_id, |
2316 const std::string& md5) { | 2321 const std::string& md5) { |
2317 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2318 // Nothing much to do here for now. | 2323 // Nothing much to do here for now. |
2319 } | 2324 } |
2320 | 2325 |
2321 void DriveFileSystem::MoveEntryToDirectory( | 2326 void DriveFileSystem::MoveEntryToDirectory( |
2322 const FilePath& file_path, | 2327 const FilePath& file_path, |
2323 const FilePath& directory_path, | 2328 const FilePath& directory_path, |
2324 const FileMoveCallback& callback, | 2329 const FileMoveCallback& callback, |
2325 GDataErrorCode status, | 2330 gdata::GDataErrorCode status, |
2326 const GURL& /* document_url */) { | 2331 const GURL& /* document_url */) { |
2327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2328 DCHECK(!callback.is_null()); | 2333 DCHECK(!callback.is_null()); |
2329 | 2334 |
2330 const DriveFileError error = util::GDataToDriveFileError(status); | 2335 const DriveFileError error = util::GDataToDriveFileError(status); |
2331 if (error != DRIVE_FILE_OK) { | 2336 if (error != DRIVE_FILE_OK) { |
2332 callback.Run(error, FilePath()); | 2337 callback.Run(error, FilePath()); |
2333 return; | 2338 return; |
2334 } | 2339 } |
2335 | 2340 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2462 params->callback.Run(result); | 2467 params->callback.Run(result); |
2463 } else { | 2468 } else { |
2464 // This parent exists, so recursively look at the next element. | 2469 // This parent exists, so recursively look at the next element. |
2465 params->last_dir_content_url = GURL(entry_proto->content_url()); | 2470 params->last_dir_content_url = GURL(entry_proto->content_url()); |
2466 params->index++; | 2471 params->index++; |
2467 FindFirstMissingParentDirectoryInternal(params.Pass()); | 2472 FindFirstMissingParentDirectoryInternal(params.Pass()); |
2468 } | 2473 } |
2469 } | 2474 } |
2470 | 2475 |
2471 void DriveFileSystem::AddUploadedFile( | 2476 void DriveFileSystem::AddUploadedFile( |
2472 UploadMode upload_mode, | 2477 gdata::UploadMode upload_mode, |
2473 const FilePath& directory_path, | 2478 const FilePath& directory_path, |
2474 scoped_ptr<DocumentEntry> entry, | 2479 scoped_ptr<gdata::DocumentEntry> entry, |
2475 const FilePath& file_content_path, | 2480 const FilePath& file_content_path, |
2476 DriveCache::FileOperationType cache_operation, | 2481 DriveCache::FileOperationType cache_operation, |
2477 const base::Closure& callback) { | 2482 const base::Closure& callback) { |
2478 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2483 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2479 | 2484 |
2480 // Post a task to the same thread, rather than calling it here, as | 2485 // Post a task to the same thread, rather than calling it here, as |
2481 // AddUploadedFile() is asynchronous. | 2486 // AddUploadedFile() is asynchronous. |
2482 base::MessageLoopProxy::current()->PostTask( | 2487 base::MessageLoopProxy::current()->PostTask( |
2483 FROM_HERE, | 2488 FROM_HERE, |
2484 base::Bind(&DriveFileSystem::AddUploadedFileOnUIThread, | 2489 base::Bind(&DriveFileSystem::AddUploadedFileOnUIThread, |
2485 ui_weak_ptr_, | 2490 ui_weak_ptr_, |
2486 upload_mode, | 2491 upload_mode, |
2487 directory_path, | 2492 directory_path, |
2488 base::Passed(&entry), | 2493 base::Passed(&entry), |
2489 file_content_path, | 2494 file_content_path, |
2490 cache_operation, | 2495 cache_operation, |
2491 callback)); | 2496 callback)); |
2492 } | 2497 } |
2493 | 2498 |
2494 void DriveFileSystem::AddUploadedFileOnUIThread( | 2499 void DriveFileSystem::AddUploadedFileOnUIThread( |
2495 UploadMode upload_mode, | 2500 gdata::UploadMode upload_mode, |
2496 const FilePath& directory_path, | 2501 const FilePath& directory_path, |
2497 scoped_ptr<DocumentEntry> doc_entry, | 2502 scoped_ptr<gdata::DocumentEntry> doc_entry, |
2498 const FilePath& file_content_path, | 2503 const FilePath& file_content_path, |
2499 DriveCache::FileOperationType cache_operation, | 2504 DriveCache::FileOperationType cache_operation, |
2500 const base::Closure& callback) { | 2505 const base::Closure& callback) { |
2501 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2506 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2502 DCHECK(doc_entry.get()); | 2507 DCHECK(doc_entry.get()); |
2503 | 2508 |
2504 const std::string& resource_id = doc_entry->resource_id(); | 2509 const std::string& resource_id = doc_entry->resource_id(); |
2505 scoped_ptr<AddUploadedFileParams> params( | 2510 scoped_ptr<AddUploadedFileParams> params( |
2506 new AddUploadedFileParams(upload_mode, | 2511 new AddUploadedFileParams(upload_mode, |
2507 directory_path, | 2512 directory_path, |
2508 doc_entry.Pass(), | 2513 doc_entry.Pass(), |
2509 file_content_path, | 2514 file_content_path, |
2510 cache_operation, | 2515 cache_operation, |
2511 callback)); | 2516 callback)); |
2512 | 2517 |
2513 const FileMoveCallback file_move_callback = | 2518 const FileMoveCallback file_move_callback = |
2514 base::Bind(&DriveFileSystem::ContinueAddUploadedFile, | 2519 base::Bind(&DriveFileSystem::ContinueAddUploadedFile, |
2515 ui_weak_ptr_, base::Passed(¶ms)); | 2520 ui_weak_ptr_, base::Passed(¶ms)); |
2516 | 2521 |
2517 if (upload_mode == UPLOAD_EXISTING_FILE) { | 2522 if (upload_mode == gdata::UPLOAD_EXISTING_FILE) { |
2518 // Remove the existing entry. | 2523 // Remove the existing entry. |
2519 resource_metadata_->RemoveEntryFromParent(resource_id, file_move_callback); | 2524 resource_metadata_->RemoveEntryFromParent(resource_id, file_move_callback); |
2520 } else { | 2525 } else { |
2521 file_move_callback.Run(DRIVE_FILE_OK, FilePath()); | 2526 file_move_callback.Run(DRIVE_FILE_OK, FilePath()); |
2522 } | 2527 } |
2523 } | 2528 } |
2524 | 2529 |
2525 void DriveFileSystem::ContinueAddUploadedFile( | 2530 void DriveFileSystem::ContinueAddUploadedFile( |
2526 scoped_ptr<AddUploadedFileParams> params, | 2531 scoped_ptr<AddUploadedFileParams> params, |
2527 DriveFileError error, | 2532 DriveFileError error, |
2528 const FilePath& /* file_path */) { | 2533 const FilePath& /* file_path */) { |
2529 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2534 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2530 DCHECK_EQ(DRIVE_FILE_OK, error); | 2535 DCHECK_EQ(DRIVE_FILE_OK, error); |
2531 DCHECK(params->doc_entry.get()); | 2536 DCHECK(params->doc_entry.get()); |
2532 | 2537 |
2533 params->resource_id = params->doc_entry->resource_id(); | 2538 params->resource_id = params->doc_entry->resource_id(); |
2534 params->md5 = params->doc_entry->file_md5(); | 2539 params->md5 = params->doc_entry->file_md5(); |
2535 DCHECK(!params->resource_id.empty()); | 2540 DCHECK(!params->resource_id.empty()); |
2536 DCHECK(!params->md5.empty()); | 2541 DCHECK(!params->md5.empty()); |
2537 | 2542 |
2538 // Get parameters before base::Passed() invalidates |params|. | 2543 // Get parameters before base::Passed() invalidates |params|. |
2539 const FilePath& directory_path = params->directory_path; | 2544 const FilePath& directory_path = params->directory_path; |
2540 scoped_ptr<DocumentEntry> doc_entry(params->doc_entry.Pass()); | 2545 scoped_ptr<gdata::DocumentEntry> doc_entry(params->doc_entry.Pass()); |
2541 | 2546 |
2542 resource_metadata_->AddEntryToDirectory( | 2547 resource_metadata_->AddEntryToDirectory( |
2543 directory_path, | 2548 directory_path, |
2544 doc_entry.Pass(), | 2549 doc_entry.Pass(), |
2545 base::Bind(&DriveFileSystem::AddUploadedFileToCache, | 2550 base::Bind(&DriveFileSystem::AddUploadedFileToCache, |
2546 ui_weak_ptr_, | 2551 ui_weak_ptr_, |
2547 base::Passed(¶ms))); | 2552 base::Passed(¶ms))); |
2548 } | 2553 } |
2549 | 2554 |
2550 void DriveFileSystem::AddUploadedFileToCache( | 2555 void DriveFileSystem::AddUploadedFileToCache( |
2551 scoped_ptr<AddUploadedFileParams> params, | 2556 scoped_ptr<AddUploadedFileParams> params, |
2552 DriveFileError error, | 2557 DriveFileError error, |
2553 const FilePath& file_path) { | 2558 const FilePath& file_path) { |
2554 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2559 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2555 DCHECK(!params->resource_id.empty()); | 2560 DCHECK(!params->resource_id.empty()); |
2556 DCHECK(!params->md5.empty()); | 2561 DCHECK(!params->md5.empty()); |
2557 DCHECK(!params->resource_id.empty()); | 2562 DCHECK(!params->resource_id.empty()); |
2558 DCHECK(!params->callback.is_null()); | 2563 DCHECK(!params->callback.is_null()); |
2559 | 2564 |
2560 if (error != DRIVE_FILE_OK) { | 2565 if (error != DRIVE_FILE_OK) { |
2561 params->callback.Run(); | 2566 params->callback.Run(); |
2562 return; | 2567 return; |
2563 } | 2568 } |
2564 | 2569 |
2565 OnDirectoryChanged(file_path.DirName()); | 2570 OnDirectoryChanged(file_path.DirName()); |
2566 | 2571 |
2567 if (params->upload_mode == UPLOAD_NEW_FILE) { | 2572 if (params->upload_mode == gdata::UPLOAD_NEW_FILE) { |
2568 // Add the file to the cache if we have uploaded a new file. | 2573 // Add the file to the cache if we have uploaded a new file. |
2569 cache_->StoreOnUIThread(params->resource_id, | 2574 cache_->StoreOnUIThread(params->resource_id, |
2570 params->md5, | 2575 params->md5, |
2571 params->file_content_path, | 2576 params->file_content_path, |
2572 params->cache_operation, | 2577 params->cache_operation, |
2573 base::Bind(&OnCacheUpdatedForAddUploadedFile, | 2578 base::Bind(&OnCacheUpdatedForAddUploadedFile, |
2574 params->callback)); | 2579 params->callback)); |
2575 } else if (params->upload_mode == UPLOAD_EXISTING_FILE) { | 2580 } else if (params->upload_mode == gdata::UPLOAD_EXISTING_FILE) { |
2576 // Clear the dirty bit if we have updated an existing file. | 2581 // Clear the dirty bit if we have updated an existing file. |
2577 cache_->ClearDirtyOnUIThread(params->resource_id, | 2582 cache_->ClearDirtyOnUIThread(params->resource_id, |
2578 params->md5, | 2583 params->md5, |
2579 base::Bind(&OnCacheUpdatedForAddUploadedFile, | 2584 base::Bind(&OnCacheUpdatedForAddUploadedFile, |
2580 params->callback)); | 2585 params->callback)); |
2581 } else { | 2586 } else { |
2582 NOTREACHED() << "Unexpected upload mode: " << params->upload_mode; | 2587 NOTREACHED() << "Unexpected upload mode: " << params->upload_mode; |
2583 // Shouldn't reach here, so the line below should not make much sense, but | 2588 // Shouldn't reach here, so the line below should not make much sense, but |
2584 // since calling |callback| exactly once is our obligation, we'd better call | 2589 // since calling |callback| exactly once is our obligation, we'd better call |
2585 // it for not to clutter further more. | 2590 // it for not to clutter further more. |
2586 params->callback.Run(); | 2591 params->callback.Run(); |
2587 } | 2592 } |
2588 } | 2593 } |
2589 | 2594 |
2590 void DriveFileSystem::UpdateEntryData(const std::string& resource_id, | 2595 void DriveFileSystem::UpdateEntryData(const std::string& resource_id, |
2591 const std::string& md5, | 2596 const std::string& md5, |
2592 scoped_ptr<DocumentEntry> entry, | 2597 scoped_ptr<gdata::DocumentEntry> entry, |
2593 const FilePath& file_content_path, | 2598 const FilePath& file_content_path, |
2594 const base::Closure& callback) { | 2599 const base::Closure& callback) { |
2595 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2600 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2596 | 2601 |
2597 // Post a task to the same thread, rather than calling it here, as | 2602 // Post a task to the same thread, rather than calling it here, as |
2598 // UpdateEntryData() is asynchronous. | 2603 // UpdateEntryData() is asynchronous. |
2599 base::MessageLoopProxy::current()->PostTask( | 2604 base::MessageLoopProxy::current()->PostTask( |
2600 FROM_HERE, | 2605 FROM_HERE, |
2601 base::Bind(&DriveFileSystem::UpdateEntryDataOnUIThread, | 2606 base::Bind(&DriveFileSystem::UpdateEntryDataOnUIThread, |
2602 ui_weak_ptr_, | 2607 ui_weak_ptr_, |
2603 UpdateEntryParams(resource_id, | 2608 UpdateEntryParams(resource_id, |
2604 md5, | 2609 md5, |
2605 file_content_path, | 2610 file_content_path, |
2606 callback), | 2611 callback), |
2607 base::Passed(&entry))); | 2612 base::Passed(&entry))); |
2608 } | 2613 } |
2609 | 2614 |
2610 void DriveFileSystem::UpdateEntryDataOnUIThread( | 2615 void DriveFileSystem::UpdateEntryDataOnUIThread( |
2611 const UpdateEntryParams& params, | 2616 const UpdateEntryParams& params, |
2612 scoped_ptr<DocumentEntry> entry) { | 2617 scoped_ptr<gdata::DocumentEntry> entry) { |
2613 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2618 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2614 | 2619 |
2615 resource_metadata_->RefreshFile( | 2620 resource_metadata_->RefreshFile( |
2616 entry.Pass(), | 2621 entry.Pass(), |
2617 base::Bind(&DriveFileSystem::UpdateCacheEntryOnUIThread, | 2622 base::Bind(&DriveFileSystem::UpdateCacheEntryOnUIThread, |
2618 ui_weak_ptr_, | 2623 ui_weak_ptr_, |
2619 params)); | 2624 params)); |
2620 } | 2625 } |
2621 | 2626 |
2622 void DriveFileSystem::UpdateCacheEntryOnUIThread( | 2627 void DriveFileSystem::UpdateCacheEntryOnUIThread( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2677 | 2682 |
2678 pref_registrar_.reset(new PrefChangeRegistrar()); | 2683 pref_registrar_.reset(new PrefChangeRegistrar()); |
2679 pref_registrar_->Init(profile_->GetPrefs()); | 2684 pref_registrar_->Init(profile_->GetPrefs()); |
2680 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); | 2685 pref_registrar_->Add(prefs::kDisableGDataHostedFiles, this); |
2681 } | 2686 } |
2682 | 2687 |
2683 void DriveFileSystem::OpenFile(const FilePath& file_path, | 2688 void DriveFileSystem::OpenFile(const FilePath& file_path, |
2684 const OpenFileCallback& callback) { | 2689 const OpenFileCallback& callback) { |
2685 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2690 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
2686 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2691 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2687 RunTaskOnUIThread(base::Bind(&DriveFileSystem::OpenFileOnUIThread, | 2692 gdata::RunTaskOnUIThread(base::Bind(&DriveFileSystem::OpenFileOnUIThread, |
2688 ui_weak_ptr_, | 2693 ui_weak_ptr_, |
2689 file_path, | 2694 file_path, |
2690 CreateRelayCallback(callback))); | 2695 gdata::CreateRelayCallback(callback))); |
2691 } | 2696 } |
2692 | 2697 |
2693 void DriveFileSystem::OpenFileOnUIThread(const FilePath& file_path, | 2698 void DriveFileSystem::OpenFileOnUIThread(const FilePath& file_path, |
2694 const OpenFileCallback& callback) { | 2699 const OpenFileCallback& callback) { |
2695 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2700 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2696 | 2701 |
2697 // If the file is already opened, it cannot be opened again before closed. | 2702 // If the file is already opened, it cannot be opened again before closed. |
2698 // This is for avoiding simultaneous modification to the file, and moreover | 2703 // This is for avoiding simultaneous modification to the file, and moreover |
2699 // to avoid an inconsistent cache state (suppose an operation sequence like | 2704 // to avoid an inconsistent cache state (suppose an operation sequence like |
2700 // Open->Open->modify->Close->modify->Close; the second modify may not be | 2705 // Open->Open->modify->Close->modify->Close; the second modify may not be |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2747 // Extract a pointer before we call Pass() so we can use it below. | 2752 // Extract a pointer before we call Pass() so we can use it below. |
2748 DriveEntryProto* entry_proto_ptr = entry_proto.get(); | 2753 DriveEntryProto* entry_proto_ptr = entry_proto.get(); |
2749 GetResolvedFileByPath( | 2754 GetResolvedFileByPath( |
2750 file_path, | 2755 file_path, |
2751 base::Bind(&DriveFileSystem::OnGetFileCompleteForOpenFile, | 2756 base::Bind(&DriveFileSystem::OnGetFileCompleteForOpenFile, |
2752 ui_weak_ptr_, | 2757 ui_weak_ptr_, |
2753 callback, | 2758 callback, |
2754 GetFileCompleteForOpenParams( | 2759 GetFileCompleteForOpenParams( |
2755 entry_proto_ptr->resource_id(), | 2760 entry_proto_ptr->resource_id(), |
2756 entry_proto_ptr->file_specific_info().file_md5())), | 2761 entry_proto_ptr->file_specific_info().file_md5())), |
2757 GetContentCallback(), | 2762 gdata::GetContentCallback(), |
2758 entry_proto.Pass()); | 2763 entry_proto.Pass()); |
2759 } | 2764 } |
2760 | 2765 |
2761 void DriveFileSystem::OnGetFileCompleteForOpenFile( | 2766 void DriveFileSystem::OnGetFileCompleteForOpenFile( |
2762 const OpenFileCallback& callback, | 2767 const OpenFileCallback& callback, |
2763 const GetFileCompleteForOpenParams& entry_proto, | 2768 const GetFileCompleteForOpenParams& entry_proto, |
2764 DriveFileError error, | 2769 DriveFileError error, |
2765 const FilePath& file_path, | 2770 const FilePath& file_path, |
2766 const std::string& mime_type, | 2771 const std::string& mime_type, |
2767 DriveFileType file_type) { | 2772 DriveFileType file_type) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2809 if (!callback.is_null()) | 2814 if (!callback.is_null()) |
2810 callback.Run(result, cache_file_path); | 2815 callback.Run(result, cache_file_path); |
2811 } | 2816 } |
2812 | 2817 |
2813 void DriveFileSystem::CloseFile(const FilePath& file_path, | 2818 void DriveFileSystem::CloseFile(const FilePath& file_path, |
2814 const FileOperationCallback& callback) { | 2819 const FileOperationCallback& callback) { |
2815 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || | 2820 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI) || |
2816 BrowserThread::CurrentlyOn(BrowserThread::IO)); | 2821 BrowserThread::CurrentlyOn(BrowserThread::IO)); |
2817 DCHECK(!callback.is_null()); | 2822 DCHECK(!callback.is_null()); |
2818 | 2823 |
2819 RunTaskOnUIThread(base::Bind(&DriveFileSystem::CloseFileOnUIThread, | 2824 gdata::RunTaskOnUIThread(base::Bind(&DriveFileSystem::CloseFileOnUIThread, |
2820 ui_weak_ptr_, | 2825 ui_weak_ptr_, |
2821 file_path, | 2826 file_path, |
2822 CreateRelayCallback(callback))); | 2827 gdata::CreateRelayCallback(callback))); |
2823 } | 2828 } |
2824 | 2829 |
2825 void DriveFileSystem::CloseFileOnUIThread( | 2830 void DriveFileSystem::CloseFileOnUIThread( |
2826 const FilePath& file_path, | 2831 const FilePath& file_path, |
2827 const FileOperationCallback& callback) { | 2832 const FileOperationCallback& callback) { |
2828 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 2833 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
2829 DCHECK(!callback.is_null()); | 2834 DCHECK(!callback.is_null()); |
2830 | 2835 |
2831 if (open_files_.find(file_path) == open_files_.end()) { | 2836 if (open_files_.find(file_path) == open_files_.end()) { |
2832 // The file is not being opened. | 2837 // The file is not being opened. |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2966 | 2971 |
2967 // When no dirty cache is found, use the original entry info as is. | 2972 // When no dirty cache is found, use the original entry info as is. |
2968 if (error != DRIVE_FILE_OK) { | 2973 if (error != DRIVE_FILE_OK) { |
2969 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); | 2974 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); |
2970 return; | 2975 return; |
2971 } | 2976 } |
2972 | 2977 |
2973 // If the cache is dirty, obtain the file info from the cache file itself. | 2978 // If the cache is dirty, obtain the file info from the cache file itself. |
2974 base::PlatformFileInfo* file_info = new base::PlatformFileInfo; | 2979 base::PlatformFileInfo* file_info = new base::PlatformFileInfo; |
2975 bool* get_file_info_result = new bool(false); | 2980 bool* get_file_info_result = new bool(false); |
2976 util::PostBlockingPoolSequencedTaskAndReply( | 2981 gdata::util::PostBlockingPoolSequencedTaskAndReply( |
2977 FROM_HERE, | 2982 FROM_HERE, |
2978 blocking_task_runner_, | 2983 blocking_task_runner_, |
2979 base::Bind(&GetFileInfoOnBlockingPool, | 2984 base::Bind(&GetFileInfoOnBlockingPool, |
2980 local_cache_path, | 2985 local_cache_path, |
2981 base::Unretained(file_info), | 2986 base::Unretained(file_info), |
2982 base::Unretained(get_file_info_result)), | 2987 base::Unretained(get_file_info_result)), |
2983 base::Bind(&DriveFileSystem::CheckLocalModificationAndRunAfterGetFileInfo, | 2988 base::Bind(&DriveFileSystem::CheckLocalModificationAndRunAfterGetFileInfo, |
2984 ui_weak_ptr_, | 2989 ui_weak_ptr_, |
2985 base::Passed(&entry_proto), | 2990 base::Passed(&entry_proto), |
2986 callback, | 2991 callback, |
(...skipping 13 matching lines...) Expand all Loading... | |
3000 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, scoped_ptr<DriveEntryProto>()); | 3005 callback.Run(DRIVE_FILE_ERROR_NOT_FOUND, scoped_ptr<DriveEntryProto>()); |
3001 return; | 3006 return; |
3002 } | 3007 } |
3003 | 3008 |
3004 PlatformFileInfoProto entry_file_info; | 3009 PlatformFileInfoProto entry_file_info; |
3005 DriveEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); | 3010 DriveEntry::ConvertPlatformFileInfoToProto(*file_info, &entry_file_info); |
3006 *entry_proto->mutable_file_info() = entry_file_info; | 3011 *entry_proto->mutable_file_info() = entry_file_info; |
3007 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); | 3012 callback.Run(DRIVE_FILE_OK, entry_proto.Pass()); |
3008 } | 3013 } |
3009 | 3014 |
3010 } // namespace gdata | 3015 } // namespace drive |
OLD | NEW |