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

Side by Side Diff: chrome/browser/chromeos/drive/file_system.cc

Issue 371883003: Files.app: Add an private API to get a download URL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/drive/file_system.h" 5 #include "chrome/browser/chromeos/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/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/chromeos/drive/change_list_loader.h" 10 #include "chrome/browser/chromeos/drive/change_list_loader.h"
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 } 686 }
687 DCHECK(about_resource); 687 DCHECK(about_resource);
688 688
689 callback.Run(FILE_ERROR_OK, 689 callback.Run(FILE_ERROR_OK,
690 about_resource->quota_bytes_total(), 690 about_resource->quota_bytes_total(),
691 about_resource->quota_bytes_used()); 691 about_resource->quota_bytes_used());
692 } 692 }
693 693
694 void FileSystem::GetShareUrl(const base::FilePath& file_path, 694 void FileSystem::GetShareUrl(const base::FilePath& file_path,
695 const GURL& embed_origin, 695 const GURL& embed_origin,
696 const GetShareUrlCallback& callback) { 696 const GetUrlCallback& callback) {
697 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 697 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
698 DCHECK(!callback.is_null()); 698 DCHECK(!callback.is_null());
699 699
700 // Resolve the resource id. 700 // Resolve the resource id.
701 ResourceEntry* entry = new ResourceEntry; 701 ResourceEntry* entry = new ResourceEntry;
702 base::PostTaskAndReplyWithResult( 702 base::PostTaskAndReplyWithResult(
703 blocking_task_runner_.get(), 703 blocking_task_runner_.get(),
704 FROM_HERE, 704 FROM_HERE,
705 base::Bind(&internal::ResourceMetadata::GetResourceEntryByPath, 705 base::Bind(&internal::ResourceMetadata::GetResourceEntryByPath,
706 base::Unretained(resource_metadata_), 706 base::Unretained(resource_metadata_),
707 file_path, 707 file_path,
708 entry), 708 entry),
709 base::Bind(&FileSystem::GetShareUrlAfterGetResourceEntry, 709 base::Bind(&FileSystem::GetShareUrlAfterGetResourceEntry,
710 weak_ptr_factory_.GetWeakPtr(), 710 weak_ptr_factory_.GetWeakPtr(),
711 file_path, 711 file_path,
712 embed_origin, 712 embed_origin,
713 callback, 713 callback,
714 base::Owned(entry))); 714 base::Owned(entry)));
715 } 715 }
716 716
717 void FileSystem::GetShareUrlAfterGetResourceEntry( 717 void FileSystem::GetShareUrlAfterGetResourceEntry(
718 const base::FilePath& file_path, 718 const base::FilePath& file_path,
719 const GURL& embed_origin, 719 const GURL& embed_origin,
720 const GetShareUrlCallback& callback, 720 const GetUrlCallback& callback,
721 ResourceEntry* entry, 721 ResourceEntry* entry,
722 FileError error) { 722 FileError error) {
723 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 723 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
724 DCHECK(!callback.is_null()); 724 DCHECK(!callback.is_null());
725 725
726 if (error != FILE_ERROR_OK) { 726 if (error != FILE_ERROR_OK) {
727 callback.Run(error, GURL()); 727 callback.Run(error, GURL());
728 return; 728 return;
729 } 729 }
730 if (entry->resource_id().empty()) { 730 if (entry->resource_id().empty()) {
731 // This entry does not exist on the server. Just return. 731 // This entry does not exist on the server. Just return.
732 callback.Run(FILE_ERROR_FAILED, GURL()); 732 callback.Run(FILE_ERROR_FAILED, GURL());
733 return; 733 return;
734 } 734 }
735 735
736 scheduler_->GetShareUrl( 736 scheduler_->GetShareUrl(
737 entry->resource_id(), 737 entry->resource_id(),
738 embed_origin, 738 embed_origin,
739 ClientContext(USER_INITIATED), 739 ClientContext(USER_INITIATED),
740 base::Bind(&FileSystem::OnGetResourceEntryForGetShareUrl, 740 base::Bind(&FileSystem::OnGetResourceEntryForGetShareUrl,
741 weak_ptr_factory_.GetWeakPtr(), 741 weak_ptr_factory_.GetWeakPtr(),
742 callback)); 742 callback));
743 } 743 }
744 744
745 void FileSystem::OnGetResourceEntryForGetShareUrl( 745 void FileSystem::OnGetResourceEntryForGetShareUrl(
746 const GetShareUrlCallback& callback, 746 const GetUrlCallback& callback,
747 google_apis::GDataErrorCode status, 747 google_apis::GDataErrorCode status,
748 const GURL& share_url) { 748 const GURL& share_url) {
749 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 749 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
750 DCHECK(!callback.is_null()); 750 DCHECK(!callback.is_null());
751 751
752 FileError error = GDataToFileError(status); 752 FileError error = GDataToFileError(status);
753 if (error != FILE_ERROR_OK) { 753 if (error != FILE_ERROR_OK) {
754 callback.Run(error, GURL()); 754 callback.Run(error, GURL());
755 return; 755 return;
756 } 756 }
757 757
758 if (share_url.is_empty()) { 758 if (share_url.is_empty()) {
759 callback.Run(FILE_ERROR_FAILED, GURL()); 759 callback.Run(FILE_ERROR_FAILED, GURL());
760 return; 760 return;
761 } 761 }
762 762
763 callback.Run(FILE_ERROR_OK, share_url); 763 callback.Run(FILE_ERROR_OK, share_url);
764 } 764 }
765 765
766 void FileSystem::GetDownloadUrl(const base::FilePath& file_path,
767 const GetUrlCallback& callback) {
768 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
769 DCHECK(!callback.is_null());
770
771 // Resolve the resource id.
772 ResourceEntry* entry = new ResourceEntry;
773 base::PostTaskAndReplyWithResult(
774 blocking_task_runner_.get(),
775 FROM_HERE,
776 base::Bind(&internal::ResourceMetadata::GetResourceEntryByPath,
777 base::Unretained(resource_metadata_),
778 file_path,
779 entry),
780 base::Bind(&FileSystem::GetDownloadUrlAfterGetResourceEntry,
781 weak_ptr_factory_.GetWeakPtr(),
782 file_path,
783 callback,
784 base::Owned(entry)));
785 }
786
787 void FileSystem::GetDownloadUrlAfterGetResourceEntry(
788 const base::FilePath& file_path,
789 const GetUrlCallback& callback,
790 ResourceEntry* entry,
791 FileError error) {
792 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
793 DCHECK(!callback.is_null());
794
795 if (error != FILE_ERROR_OK) {
796 callback.Run(error, GURL());
797 return;
798 }
799 if (entry->resource_id().empty()) {
800 // This entry does not exist on the server. Just return.
801 callback.Run(FILE_ERROR_FAILED, GURL());
802 return;
803 }
804
805 scheduler_->GetFileResource(
806 entry->resource_id(),
807 base::Bind(&FileSystem::OnGetFileResourceForGetDownloadUrl,
808 weak_ptr_factory_.GetWeakPtr(),
809 callback));
810 }
811
812 void FileSystem::OnGetFileResourceForGetDownloadUrl(
813 const GetUrlCallback& callback,
814 google_apis::GDataErrorCode status,
815 scoped_ptr<google_apis::FileResource> file_resource) {
816 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
817 DCHECK(!callback.is_null());
818
819 FileError error = GDataToFileError(status);
820 if (error != FILE_ERROR_OK) {
821 callback.Run(error, GURL());
822 return;
823 }
824
825 if (file_resource->download_url().is_empty()) {
826 callback.Run(FILE_ERROR_FAILED, GURL());
827 return;
828 }
829
830 callback.Run(FILE_ERROR_OK, file_resource->download_url());
831 }
832
766 void FileSystem::Search(const std::string& search_query, 833 void FileSystem::Search(const std::string& search_query,
767 const GURL& next_link, 834 const GURL& next_link,
768 const SearchCallback& callback) { 835 const SearchCallback& callback) {
769 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 836 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
770 DCHECK(!callback.is_null()); 837 DCHECK(!callback.is_null());
771 search_operation_->Search(search_query, next_link, callback); 838 search_operation_->Search(search_query, next_link, callback);
772 } 839 }
773 840
774 void FileSystem::SearchMetadata(const std::string& query, 841 void FileSystem::SearchMetadata(const std::string& query,
775 int options, 842 int options,
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 FROM_HERE, 1051 FROM_HERE,
985 base::Bind(&GetPathFromResourceIdOnBlockingPool, 1052 base::Bind(&GetPathFromResourceIdOnBlockingPool,
986 resource_metadata_, 1053 resource_metadata_,
987 resource_id, 1054 resource_id,
988 file_path), 1055 file_path),
989 base::Bind(&GetPathFromResourceIdAfterGetPath, 1056 base::Bind(&GetPathFromResourceIdAfterGetPath,
990 base::Owned(file_path), 1057 base::Owned(file_path),
991 callback)); 1058 callback));
992 } 1059 }
993 } // namespace drive 1060 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698