| 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 "components/drive/service/drive_api_service.h" | 5 #include "components/drive/service/drive_api_service.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 |
| 7 #include <string> | 9 #include <string> |
| 8 #include <vector> | 10 #include <vector> |
| 9 | 11 |
| 10 #include "base/bind.h" | 12 #include "base/bind.h" |
| 11 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 12 #include "components/drive/drive_api_util.h" | 14 #include "components/drive/drive_api_util.h" |
| 13 #include "google_apis/drive/auth_service.h" | 15 #include "google_apis/drive/auth_service.h" |
| 14 #include "google_apis/drive/base_requests.h" | 16 #include "google_apis/drive/base_requests.h" |
| 15 #include "google_apis/drive/drive_api_parser.h" | 17 #include "google_apis/drive/drive_api_parser.h" |
| 16 #include "google_apis/drive/drive_api_requests.h" | 18 #include "google_apis/drive/drive_api_requests.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 } | 176 } |
| 175 | 177 |
| 176 BatchRequestConfigurator::~BatchRequestConfigurator() { | 178 BatchRequestConfigurator::~BatchRequestConfigurator() { |
| 177 // The batch requst has not been committed. | 179 // The batch requst has not been committed. |
| 178 if (batch_request_) | 180 if (batch_request_) |
| 179 cancel_callback_.Run(); | 181 cancel_callback_.Run(); |
| 180 } | 182 } |
| 181 | 183 |
| 182 google_apis::CancelCallback BatchRequestConfigurator::MultipartUploadNewFile( | 184 google_apis::CancelCallback BatchRequestConfigurator::MultipartUploadNewFile( |
| 183 const std::string& content_type, | 185 const std::string& content_type, |
| 184 int64 content_length, | 186 int64_t content_length, |
| 185 const std::string& parent_resource_id, | 187 const std::string& parent_resource_id, |
| 186 const std::string& title, | 188 const std::string& title, |
| 187 const base::FilePath& local_file_path, | 189 const base::FilePath& local_file_path, |
| 188 const UploadNewFileOptions& options, | 190 const UploadNewFileOptions& options, |
| 189 const google_apis::FileResourceCallback& callback, | 191 const google_apis::FileResourceCallback& callback, |
| 190 const google_apis::ProgressCallback& progress_callback) { | 192 const google_apis::ProgressCallback& progress_callback) { |
| 191 DCHECK(CalledOnValidThread()); | 193 DCHECK(CalledOnValidThread()); |
| 192 DCHECK(!callback.is_null()); | 194 DCHECK(!callback.is_null()); |
| 193 | 195 |
| 194 scoped_ptr<google_apis::BatchableDelegate> delegate( | 196 scoped_ptr<google_apis::BatchableDelegate> delegate( |
| 195 new google_apis::drive::MultipartUploadNewFileDelegate( | 197 new google_apis::drive::MultipartUploadNewFileDelegate( |
| 196 task_runner_.get(), title, parent_resource_id, content_type, | 198 task_runner_.get(), title, parent_resource_id, content_type, |
| 197 content_length, options.modified_date, options.last_viewed_by_me_date, | 199 content_length, options.modified_date, options.last_viewed_by_me_date, |
| 198 local_file_path, options.properties, url_generator_, callback, | 200 local_file_path, options.properties, url_generator_, callback, |
| 199 progress_callback)); | 201 progress_callback)); |
| 200 // Batch request can be null when pre-authorization for the requst is failed | 202 // Batch request can be null when pre-authorization for the requst is failed |
| 201 // in request sender. | 203 // in request sender. |
| 202 if (batch_request_) | 204 if (batch_request_) |
| 203 batch_request_->AddRequest(delegate.release()); | 205 batch_request_->AddRequest(delegate.release()); |
| 204 else | 206 else |
| 205 delegate->NotifyError(DRIVE_OTHER_ERROR); | 207 delegate->NotifyError(DRIVE_OTHER_ERROR); |
| 206 return cancel_callback_; | 208 return cancel_callback_; |
| 207 } | 209 } |
| 208 | 210 |
| 209 google_apis::CancelCallback | 211 google_apis::CancelCallback |
| 210 BatchRequestConfigurator::MultipartUploadExistingFile( | 212 BatchRequestConfigurator::MultipartUploadExistingFile( |
| 211 const std::string& content_type, | 213 const std::string& content_type, |
| 212 int64 content_length, | 214 int64_t content_length, |
| 213 const std::string& resource_id, | 215 const std::string& resource_id, |
| 214 const base::FilePath& local_file_path, | 216 const base::FilePath& local_file_path, |
| 215 const UploadExistingFileOptions& options, | 217 const UploadExistingFileOptions& options, |
| 216 const google_apis::FileResourceCallback& callback, | 218 const google_apis::FileResourceCallback& callback, |
| 217 const google_apis::ProgressCallback& progress_callback) { | 219 const google_apis::ProgressCallback& progress_callback) { |
| 218 DCHECK(CalledOnValidThread()); | 220 DCHECK(CalledOnValidThread()); |
| 219 DCHECK(!callback.is_null()); | 221 DCHECK(!callback.is_null()); |
| 220 | 222 |
| 221 scoped_ptr<google_apis::BatchableDelegate> delegate( | 223 scoped_ptr<google_apis::BatchableDelegate> delegate( |
| 222 new google_apis::drive::MultipartUploadExistingFileDelegate( | 224 new google_apis::drive::MultipartUploadExistingFileDelegate( |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 | 377 |
| 376 FilesListRequest* request = new FilesListRequest( | 378 FilesListRequest* request = new FilesListRequest( |
| 377 sender_.get(), url_generator_, callback); | 379 sender_.get(), url_generator_, callback); |
| 378 request->set_max_results(kMaxNumFilesResourcePerRequest); | 380 request->set_max_results(kMaxNumFilesResourcePerRequest); |
| 379 request->set_q(query); | 381 request->set_q(query); |
| 380 request->set_fields(kFileListFields); | 382 request->set_fields(kFileListFields); |
| 381 return sender_->StartRequestWithAuthRetry(request); | 383 return sender_->StartRequestWithAuthRetry(request); |
| 382 } | 384 } |
| 383 | 385 |
| 384 CancelCallback DriveAPIService::GetChangeList( | 386 CancelCallback DriveAPIService::GetChangeList( |
| 385 int64 start_changestamp, | 387 int64_t start_changestamp, |
| 386 const ChangeListCallback& callback) { | 388 const ChangeListCallback& callback) { |
| 387 DCHECK(thread_checker_.CalledOnValidThread()); | 389 DCHECK(thread_checker_.CalledOnValidThread()); |
| 388 DCHECK(!callback.is_null()); | 390 DCHECK(!callback.is_null()); |
| 389 | 391 |
| 390 ChangesListRequest* request = new ChangesListRequest( | 392 ChangesListRequest* request = new ChangesListRequest( |
| 391 sender_.get(), url_generator_, callback); | 393 sender_.get(), url_generator_, callback); |
| 392 request->set_max_results(kMaxNumFilesResourcePerRequest); | 394 request->set_max_results(kMaxNumFilesResourcePerRequest); |
| 393 request->set_start_change_id(start_changestamp); | 395 request->set_start_change_id(start_changestamp); |
| 394 request->set_fields(kChangeListFields); | 396 request->set_fields(kChangeListFields); |
| 395 return sender_->StartRequestWithAuthRetry(request); | 397 return sender_->StartRequestWithAuthRetry(request); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 | 619 |
| 618 ChildrenDeleteRequest* request = | 620 ChildrenDeleteRequest* request = |
| 619 new ChildrenDeleteRequest(sender_.get(), url_generator_, callback); | 621 new ChildrenDeleteRequest(sender_.get(), url_generator_, callback); |
| 620 request->set_child_id(resource_id); | 622 request->set_child_id(resource_id); |
| 621 request->set_folder_id(parent_resource_id); | 623 request->set_folder_id(parent_resource_id); |
| 622 return sender_->StartRequestWithAuthRetry(request); | 624 return sender_->StartRequestWithAuthRetry(request); |
| 623 } | 625 } |
| 624 | 626 |
| 625 CancelCallback DriveAPIService::InitiateUploadNewFile( | 627 CancelCallback DriveAPIService::InitiateUploadNewFile( |
| 626 const std::string& content_type, | 628 const std::string& content_type, |
| 627 int64 content_length, | 629 int64_t content_length, |
| 628 const std::string& parent_resource_id, | 630 const std::string& parent_resource_id, |
| 629 const std::string& title, | 631 const std::string& title, |
| 630 const UploadNewFileOptions& options, | 632 const UploadNewFileOptions& options, |
| 631 const InitiateUploadCallback& callback) { | 633 const InitiateUploadCallback& callback) { |
| 632 DCHECK(thread_checker_.CalledOnValidThread()); | 634 DCHECK(thread_checker_.CalledOnValidThread()); |
| 633 DCHECK(!callback.is_null()); | 635 DCHECK(!callback.is_null()); |
| 634 | 636 |
| 635 InitiateUploadNewFileRequest* request = | 637 InitiateUploadNewFileRequest* request = |
| 636 new InitiateUploadNewFileRequest(sender_.get(), | 638 new InitiateUploadNewFileRequest(sender_.get(), |
| 637 url_generator_, | 639 url_generator_, |
| 638 content_type, | 640 content_type, |
| 639 content_length, | 641 content_length, |
| 640 parent_resource_id, | 642 parent_resource_id, |
| 641 title, | 643 title, |
| 642 callback); | 644 callback); |
| 643 request->set_modified_date(options.modified_date); | 645 request->set_modified_date(options.modified_date); |
| 644 request->set_last_viewed_by_me_date(options.last_viewed_by_me_date); | 646 request->set_last_viewed_by_me_date(options.last_viewed_by_me_date); |
| 645 request->set_properties(options.properties); | 647 request->set_properties(options.properties); |
| 646 return sender_->StartRequestWithAuthRetry(request); | 648 return sender_->StartRequestWithAuthRetry(request); |
| 647 } | 649 } |
| 648 | 650 |
| 649 CancelCallback DriveAPIService::InitiateUploadExistingFile( | 651 CancelCallback DriveAPIService::InitiateUploadExistingFile( |
| 650 const std::string& content_type, | 652 const std::string& content_type, |
| 651 int64 content_length, | 653 int64_t content_length, |
| 652 const std::string& resource_id, | 654 const std::string& resource_id, |
| 653 const UploadExistingFileOptions& options, | 655 const UploadExistingFileOptions& options, |
| 654 const InitiateUploadCallback& callback) { | 656 const InitiateUploadCallback& callback) { |
| 655 DCHECK(thread_checker_.CalledOnValidThread()); | 657 DCHECK(thread_checker_.CalledOnValidThread()); |
| 656 DCHECK(!callback.is_null()); | 658 DCHECK(!callback.is_null()); |
| 657 | 659 |
| 658 InitiateUploadExistingFileRequest* request = | 660 InitiateUploadExistingFileRequest* request = |
| 659 new InitiateUploadExistingFileRequest(sender_.get(), | 661 new InitiateUploadExistingFileRequest(sender_.get(), |
| 660 url_generator_, | 662 url_generator_, |
| 661 content_type, | 663 content_type, |
| 662 content_length, | 664 content_length, |
| 663 resource_id, | 665 resource_id, |
| 664 options.etag, | 666 options.etag, |
| 665 callback); | 667 callback); |
| 666 request->set_parent_resource_id(options.parent_resource_id); | 668 request->set_parent_resource_id(options.parent_resource_id); |
| 667 request->set_title(options.title); | 669 request->set_title(options.title); |
| 668 request->set_modified_date(options.modified_date); | 670 request->set_modified_date(options.modified_date); |
| 669 request->set_last_viewed_by_me_date(options.last_viewed_by_me_date); | 671 request->set_last_viewed_by_me_date(options.last_viewed_by_me_date); |
| 670 request->set_properties(options.properties); | 672 request->set_properties(options.properties); |
| 671 return sender_->StartRequestWithAuthRetry(request); | 673 return sender_->StartRequestWithAuthRetry(request); |
| 672 } | 674 } |
| 673 | 675 |
| 674 CancelCallback DriveAPIService::ResumeUpload( | 676 CancelCallback DriveAPIService::ResumeUpload( |
| 675 const GURL& upload_url, | 677 const GURL& upload_url, |
| 676 int64 start_position, | 678 int64_t start_position, |
| 677 int64 end_position, | 679 int64_t end_position, |
| 678 int64 content_length, | 680 int64_t content_length, |
| 679 const std::string& content_type, | 681 const std::string& content_type, |
| 680 const base::FilePath& local_file_path, | 682 const base::FilePath& local_file_path, |
| 681 const UploadRangeCallback& callback, | 683 const UploadRangeCallback& callback, |
| 682 const ProgressCallback& progress_callback) { | 684 const ProgressCallback& progress_callback) { |
| 683 DCHECK(thread_checker_.CalledOnValidThread()); | 685 DCHECK(thread_checker_.CalledOnValidThread()); |
| 684 DCHECK(!callback.is_null()); | 686 DCHECK(!callback.is_null()); |
| 685 | 687 |
| 686 return sender_->StartRequestWithAuthRetry(new ResumeUploadRequest( | 688 return sender_->StartRequestWithAuthRetry(new ResumeUploadRequest( |
| 687 sender_.get(), upload_url, start_position, end_position, content_length, | 689 sender_.get(), upload_url, start_position, end_position, content_length, |
| 688 content_type, local_file_path, callback, progress_callback)); | 690 content_type, local_file_path, callback, progress_callback)); |
| 689 } | 691 } |
| 690 | 692 |
| 691 CancelCallback DriveAPIService::GetUploadStatus( | 693 CancelCallback DriveAPIService::GetUploadStatus( |
| 692 const GURL& upload_url, | 694 const GURL& upload_url, |
| 693 int64 content_length, | 695 int64_t content_length, |
| 694 const UploadRangeCallback& callback) { | 696 const UploadRangeCallback& callback) { |
| 695 DCHECK(thread_checker_.CalledOnValidThread()); | 697 DCHECK(thread_checker_.CalledOnValidThread()); |
| 696 DCHECK(!callback.is_null()); | 698 DCHECK(!callback.is_null()); |
| 697 | 699 |
| 698 return sender_->StartRequestWithAuthRetry(new GetUploadStatusRequest( | 700 return sender_->StartRequestWithAuthRetry(new GetUploadStatusRequest( |
| 699 sender_.get(), upload_url, content_length, callback)); | 701 sender_.get(), upload_url, content_length, callback)); |
| 700 } | 702 } |
| 701 | 703 |
| 702 CancelCallback DriveAPIService::MultipartUploadNewFile( | 704 CancelCallback DriveAPIService::MultipartUploadNewFile( |
| 703 const std::string& content_type, | 705 const std::string& content_type, |
| 704 int64 content_length, | 706 int64_t content_length, |
| 705 const std::string& parent_resource_id, | 707 const std::string& parent_resource_id, |
| 706 const std::string& title, | 708 const std::string& title, |
| 707 const base::FilePath& local_file_path, | 709 const base::FilePath& local_file_path, |
| 708 const drive::UploadNewFileOptions& options, | 710 const drive::UploadNewFileOptions& options, |
| 709 const FileResourceCallback& callback, | 711 const FileResourceCallback& callback, |
| 710 const google_apis::ProgressCallback& progress_callback) { | 712 const google_apis::ProgressCallback& progress_callback) { |
| 711 DCHECK(thread_checker_.CalledOnValidThread()); | 713 DCHECK(thread_checker_.CalledOnValidThread()); |
| 712 DCHECK(!callback.is_null()); | 714 DCHECK(!callback.is_null()); |
| 713 | 715 |
| 714 return sender_->StartRequestWithAuthRetry( | 716 return sender_->StartRequestWithAuthRetry( |
| 715 new google_apis::drive::SingleBatchableDelegateRequest( | 717 new google_apis::drive::SingleBatchableDelegateRequest( |
| 716 sender_.get(), | 718 sender_.get(), |
| 717 new google_apis::drive::MultipartUploadNewFileDelegate( | 719 new google_apis::drive::MultipartUploadNewFileDelegate( |
| 718 sender_->blocking_task_runner(), title, parent_resource_id, | 720 sender_->blocking_task_runner(), title, parent_resource_id, |
| 719 content_type, content_length, options.modified_date, | 721 content_type, content_length, options.modified_date, |
| 720 options.last_viewed_by_me_date, local_file_path, | 722 options.last_viewed_by_me_date, local_file_path, |
| 721 options.properties, url_generator_, callback, | 723 options.properties, url_generator_, callback, |
| 722 progress_callback))); | 724 progress_callback))); |
| 723 } | 725 } |
| 724 | 726 |
| 725 CancelCallback DriveAPIService::MultipartUploadExistingFile( | 727 CancelCallback DriveAPIService::MultipartUploadExistingFile( |
| 726 const std::string& content_type, | 728 const std::string& content_type, |
| 727 int64 content_length, | 729 int64_t content_length, |
| 728 const std::string& resource_id, | 730 const std::string& resource_id, |
| 729 const base::FilePath& local_file_path, | 731 const base::FilePath& local_file_path, |
| 730 const drive::UploadExistingFileOptions& options, | 732 const drive::UploadExistingFileOptions& options, |
| 731 const FileResourceCallback& callback, | 733 const FileResourceCallback& callback, |
| 732 const google_apis::ProgressCallback& progress_callback) { | 734 const google_apis::ProgressCallback& progress_callback) { |
| 733 DCHECK(thread_checker_.CalledOnValidThread()); | 735 DCHECK(thread_checker_.CalledOnValidThread()); |
| 734 DCHECK(!callback.is_null()); | 736 DCHECK(!callback.is_null()); |
| 735 | 737 |
| 736 return sender_->StartRequestWithAuthRetry( | 738 return sender_->StartRequestWithAuthRetry( |
| 737 new google_apis::drive::SingleBatchableDelegateRequest( | 739 new google_apis::drive::SingleBatchableDelegateRequest( |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 // reference to RequestSender and we should ensure to delete the request when | 867 // reference to RequestSender and we should ensure to delete the request when |
| 866 // the sender is deleted. Resolve the circulating dependency and fix it. | 868 // the sender is deleted. Resolve the circulating dependency and fix it. |
| 867 const google_apis::CancelCallback callback = | 869 const google_apis::CancelCallback callback = |
| 868 sender_->StartRequestWithAuthRetry(request.release()); | 870 sender_->StartRequestWithAuthRetry(request.release()); |
| 869 return make_scoped_ptr<BatchRequestConfiguratorInterface>( | 871 return make_scoped_ptr<BatchRequestConfiguratorInterface>( |
| 870 new BatchRequestConfigurator(weak_ref, sender_->blocking_task_runner(), | 872 new BatchRequestConfigurator(weak_ref, sender_->blocking_task_runner(), |
| 871 url_generator_, callback)); | 873 url_generator_, callback)); |
| 872 } | 874 } |
| 873 | 875 |
| 874 } // namespace drive | 876 } // namespace drive |
| OLD | NEW |