| 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> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "components/drive/drive_api_util.h" | 15 #include "components/drive/drive_api_util.h" |
| 16 #include "google_apis/drive/auth_service.h" | 16 #include "google_apis/drive/auth_service.h" |
| 17 #include "google_apis/drive/base_requests.h" | 17 #include "google_apis/drive/base_requests.h" |
| 18 #include "google_apis/drive/drive_api_parser.h" | 18 #include "google_apis/drive/drive_api_parser.h" |
| 19 #include "google_apis/drive/drive_api_requests.h" | 19 #include "google_apis/drive/drive_api_requests.h" |
| 20 #include "google_apis/drive/drive_switches.h" |
| 20 #include "google_apis/drive/files_list_request_runner.h" | 21 #include "google_apis/drive/files_list_request_runner.h" |
| 21 #include "google_apis/drive/request_sender.h" | 22 #include "google_apis/drive/request_sender.h" |
| 22 #include "google_apis/google_api_keys.h" | 23 #include "google_apis/google_api_keys.h" |
| 23 #include "net/url_request/url_request_context_getter.h" | 24 #include "net/url_request/url_request_context_getter.h" |
| 24 | 25 |
| 25 using google_apis::AboutResourceCallback; | 26 using google_apis::AboutResourceCallback; |
| 26 using google_apis::AppList; | 27 using google_apis::AppList; |
| 27 using google_apis::AppListCallback; | 28 using google_apis::AppListCallback; |
| 28 using google_apis::AuthStatusCallback; | 29 using google_apis::AuthStatusCallback; |
| 29 using google_apis::AuthorizeAppCallback; | 30 using google_apis::AuthorizeAppCallback; |
| 30 using google_apis::CancelCallback; | 31 using google_apis::CancelCallback; |
| 31 using google_apis::ChangeList; | 32 using google_apis::ChangeList; |
| 32 using google_apis::ChangeListCallback; | 33 using google_apis::ChangeListCallback; |
| 33 using google_apis::DRIVE_OTHER_ERROR; | 34 using google_apis::DRIVE_OTHER_ERROR; |
| 34 using google_apis::DRIVE_PARSE_ERROR; | 35 using google_apis::DRIVE_PARSE_ERROR; |
| 35 using google_apis::DownloadActionCallback; | 36 using google_apis::DownloadActionCallback; |
| 36 using google_apis::DriveApiErrorCode; | 37 using google_apis::DriveApiErrorCode; |
| 37 using google_apis::EntryActionCallback; | 38 using google_apis::EntryActionCallback; |
| 38 using google_apis::FileList; | 39 using google_apis::FileList; |
| 39 using google_apis::FileListCallback; | 40 using google_apis::FileListCallback; |
| 40 using google_apis::FileResource; | 41 using google_apis::FileResource; |
| 41 using google_apis::FileResourceCallback; | 42 using google_apis::FileResourceCallback; |
| 43 using google_apis::FilesListCorpora; |
| 42 using google_apis::FilesListRequestRunner; | 44 using google_apis::FilesListRequestRunner; |
| 43 using google_apis::GetContentCallback; | 45 using google_apis::GetContentCallback; |
| 44 using google_apis::GetShareUrlCallback; | 46 using google_apis::GetShareUrlCallback; |
| 45 using google_apis::HTTP_NOT_IMPLEMENTED; | 47 using google_apis::HTTP_NOT_IMPLEMENTED; |
| 46 using google_apis::HTTP_SUCCESS; | 48 using google_apis::HTTP_SUCCESS; |
| 47 using google_apis::InitiateUploadCallback; | 49 using google_apis::InitiateUploadCallback; |
| 48 using google_apis::ProgressCallback; | 50 using google_apis::ProgressCallback; |
| 49 using google_apis::RequestSender; | 51 using google_apis::RequestSender; |
| 50 using google_apis::TeamDriveListCallback; | 52 using google_apis::TeamDriveListCallback; |
| 51 using google_apis::UploadRangeResponse; | 53 using google_apis::UploadRangeResponse; |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 const FileListCallback& callback) { | 341 const FileListCallback& callback) { |
| 340 DCHECK(thread_checker_.CalledOnValidThread()); | 342 DCHECK(thread_checker_.CalledOnValidThread()); |
| 341 DCHECK(!callback.is_null()); | 343 DCHECK(!callback.is_null()); |
| 342 | 344 |
| 343 std::unique_ptr<FilesListRequest> request = | 345 std::unique_ptr<FilesListRequest> request = |
| 344 base::MakeUnique<FilesListRequest>(sender_.get(), url_generator_, | 346 base::MakeUnique<FilesListRequest>(sender_.get(), url_generator_, |
| 345 callback); | 347 callback); |
| 346 request->set_max_results(kMaxNumFilesResourcePerRequest); | 348 request->set_max_results(kMaxNumFilesResourcePerRequest); |
| 347 request->set_q("trashed = false"); // Exclude trashed files. | 349 request->set_q("trashed = false"); // Exclude trashed files. |
| 348 request->set_fields(kFileListFields); | 350 request->set_fields(kFileListFields); |
| 351 if (google_apis::GetTeamDrivesIntegrationSwitch() == |
| 352 google_apis::TEAM_DRIVES_INTEGRATION_ENABLED) { |
| 353 request->set_corpora(google_apis::FilesListCorpora::ALL_TEAM_DRIVES); |
| 354 } |
| 349 return sender_->StartRequestWithAuthRetry(std::move(request)); | 355 return sender_->StartRequestWithAuthRetry(std::move(request)); |
| 350 } | 356 } |
| 351 | 357 |
| 352 CancelCallback DriveAPIService::GetFileListInDirectory( | 358 CancelCallback DriveAPIService::GetFileListInDirectory( |
| 353 const std::string& directory_resource_id, | 359 const std::string& directory_resource_id, |
| 354 const FileListCallback& callback) { | 360 const FileListCallback& callback) { |
| 355 DCHECK(thread_checker_.CalledOnValidThread()); | 361 DCHECK(thread_checker_.CalledOnValidThread()); |
| 356 DCHECK(!directory_resource_id.empty()); | 362 DCHECK(!directory_resource_id.empty()); |
| 357 DCHECK(!callback.is_null()); | 363 DCHECK(!callback.is_null()); |
| 358 | 364 |
| 365 // TODO(yamaguchi): Use FileListScope::CreateForTeamDrive instead of |
| 366 // kAllTeamDrives for efficiency. It'll require to add a new parameter to tell |
| 367 // which team drive the directory resource belongs to. |
| 368 FilesListCorpora corpora = |
| 369 (google_apis::GetTeamDrivesIntegrationSwitch() == |
| 370 google_apis::TEAM_DRIVES_INTEGRATION_ENABLED) |
| 371 ? google_apis::FilesListCorpora::ALL_TEAM_DRIVES |
| 372 : google_apis::FilesListCorpora::DEFAULT; |
| 373 |
| 359 // Because children.list method on Drive API v2 returns only the list of | 374 // Because children.list method on Drive API v2 returns only the list of |
| 360 // children's references, but we need all file resource list. | 375 // children's references, but we need all file resource list. |
| 361 // So, here we use files.list method instead, with setting parents query. | 376 // So, here we use files.list method instead, with setting parents query. |
| 362 // After the migration from GData WAPI to Drive API v2, we should clean the | 377 // After the migration from GData WAPI to Drive API v2, we should clean the |
| 363 // code up by moving the responsibility to include "parents" in the query | 378 // code up by moving the responsibility to include "parents" in the query |
| 364 // to client side. | 379 // to client side. |
| 365 // We aren't interested in files in trash in this context, neither. | 380 // We aren't interested in files in trash in this context, neither. |
| 366 return files_list_request_runner_->CreateAndStartWithSizeBackoff( | 381 return files_list_request_runner_->CreateAndStartWithSizeBackoff( |
| 367 kMaxNumFilesResourcePerRequest, | 382 kMaxNumFilesResourcePerRequest, corpora, std::string(), |
| 368 base::StringPrintf( | 383 base::StringPrintf( |
| 369 "'%s' in parents and trashed = false", | 384 "'%s' in parents and trashed = false", |
| 370 util::EscapeQueryStringValue(directory_resource_id).c_str()), | 385 util::EscapeQueryStringValue(directory_resource_id).c_str()), |
| 371 kFileListFields, callback); | 386 kFileListFields, callback); |
| 372 } | 387 } |
| 373 | 388 |
| 374 CancelCallback DriveAPIService::Search( | 389 CancelCallback DriveAPIService::Search( |
| 375 const std::string& search_query, | 390 const std::string& search_query, |
| 376 const FileListCallback& callback) { | 391 const FileListCallback& callback) { |
| 377 DCHECK(thread_checker_.CalledOnValidThread()); | 392 DCHECK(thread_checker_.CalledOnValidThread()); |
| 378 DCHECK(!search_query.empty()); | 393 DCHECK(!search_query.empty()); |
| 379 DCHECK(!callback.is_null()); | 394 DCHECK(!callback.is_null()); |
| 380 | 395 |
| 396 FilesListCorpora corpora = |
| 397 (google_apis::GetTeamDrivesIntegrationSwitch() == |
| 398 google_apis::TEAM_DRIVES_INTEGRATION_ENABLED) |
| 399 ? google_apis::FilesListCorpora::ALL_TEAM_DRIVES |
| 400 : google_apis::FilesListCorpora::DEFAULT; |
| 401 |
| 381 return files_list_request_runner_->CreateAndStartWithSizeBackoff( | 402 return files_list_request_runner_->CreateAndStartWithSizeBackoff( |
| 382 kMaxNumFilesResourcePerRequestForSearch, | 403 kMaxNumFilesResourcePerRequestForSearch, corpora, std::string(), |
| 383 util::TranslateQuery(search_query), kFileListFields, callback); | 404 util::TranslateQuery(search_query), kFileListFields, callback); |
| 384 } | 405 } |
| 385 | 406 |
| 386 CancelCallback DriveAPIService::SearchByTitle( | 407 CancelCallback DriveAPIService::SearchByTitle( |
| 387 const std::string& title, | 408 const std::string& title, |
| 388 const std::string& directory_resource_id, | 409 const std::string& directory_resource_id, |
| 389 const FileListCallback& callback) { | 410 const FileListCallback& callback) { |
| 390 DCHECK(thread_checker_.CalledOnValidThread()); | 411 DCHECK(thread_checker_.CalledOnValidThread()); |
| 391 DCHECK(!title.empty()); | 412 DCHECK(!title.empty()); |
| 392 DCHECK(!callback.is_null()); | 413 DCHECK(!callback.is_null()); |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 // RequestSender before the request is committed because the request has a | 935 // RequestSender before the request is committed because the request has a |
| 915 // reference to RequestSender and we should ensure to delete the request when | 936 // reference to RequestSender and we should ensure to delete the request when |
| 916 // the sender is deleted. Resolve the circulating dependency and fix it. | 937 // the sender is deleted. Resolve the circulating dependency and fix it. |
| 917 const google_apis::CancelCallback callback = | 938 const google_apis::CancelCallback callback = |
| 918 sender_->StartRequestWithAuthRetry(std::move(request)); | 939 sender_->StartRequestWithAuthRetry(std::move(request)); |
| 919 return base::MakeUnique<BatchRequestConfigurator>( | 940 return base::MakeUnique<BatchRequestConfigurator>( |
| 920 weak_ref, sender_->blocking_task_runner(), url_generator_, callback); | 941 weak_ref, sender_->blocking_task_runner(), url_generator_, callback); |
| 921 } | 942 } |
| 922 | 943 |
| 923 } // namespace drive | 944 } // namespace drive |
| OLD | NEW |