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

Side by Side Diff: components/drive/service/drive_api_service.cc

Issue 2910913002: WIP.
Patch Set: rebase Created 3 years, 6 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
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 "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
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::CORPORA_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,
360 const std::string& team_drive_id,
354 const FileListCallback& callback) { 361 const FileListCallback& callback) {
355 DCHECK(thread_checker_.CalledOnValidThread()); 362 DCHECK(thread_checker_.CalledOnValidThread());
356 DCHECK(!directory_resource_id.empty()); 363 DCHECK(!directory_resource_id.empty());
357 DCHECK(!callback.is_null()); 364 DCHECK(!callback.is_null());
358 365
366 FilesListCorpora corpora = team_drive_id.empty()
367 ? google_apis::CORPORA_DEFAULT
368 : google_apis::CORPORA_TEAM_DRIVE;
369
359 // Because children.list method on Drive API v2 returns only the list of 370 // Because children.list method on Drive API v2 returns only the list of
360 // children's references, but we need all file resource list. 371 // children's references, but we need all file resource list.
361 // So, here we use files.list method instead, with setting parents query. 372 // 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 373 // 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 374 // code up by moving the responsibility to include "parents" in the query
364 // to client side. 375 // to client side.
365 // We aren't interested in files in trash in this context, neither. 376 // We aren't interested in files in trash in this context, neither.
366 return files_list_request_runner_->CreateAndStartWithSizeBackoff( 377 return files_list_request_runner_->CreateAndStartWithSizeBackoff(
367 kMaxNumFilesResourcePerRequest, 378 kMaxNumFilesResourcePerRequest, corpora, team_drive_id,
368 base::StringPrintf( 379 base::StringPrintf(
369 "'%s' in parents and trashed = false", 380 "'%s' in parents and trashed = false",
370 util::EscapeQueryStringValue(directory_resource_id).c_str()), 381 util::EscapeQueryStringValue(directory_resource_id).c_str()),
371 kFileListFields, callback); 382 kFileListFields, callback);
372 } 383 }
373 384
374 CancelCallback DriveAPIService::Search( 385 CancelCallback DriveAPIService::Search(
375 const std::string& search_query, 386 const std::string& search_query,
376 const FileListCallback& callback) { 387 const FileListCallback& callback) {
377 DCHECK(thread_checker_.CalledOnValidThread()); 388 DCHECK(thread_checker_.CalledOnValidThread());
378 DCHECK(!search_query.empty()); 389 DCHECK(!search_query.empty());
379 DCHECK(!callback.is_null()); 390 DCHECK(!callback.is_null());
380 391
392 FilesListCorpora corpora = (google_apis::GetTeamDrivesIntegrationSwitch() ==
393 google_apis::TEAM_DRIVES_INTEGRATION_ENABLED)
394 ? google_apis::CORPORA_ALL_TEAM_DRIVES
395 : google_apis::CORPORA_DEFAULT;
396
381 return files_list_request_runner_->CreateAndStartWithSizeBackoff( 397 return files_list_request_runner_->CreateAndStartWithSizeBackoff(
382 kMaxNumFilesResourcePerRequestForSearch, 398 kMaxNumFilesResourcePerRequestForSearch, corpora, "",
383 util::TranslateQuery(search_query), kFileListFields, callback); 399 util::TranslateQuery(search_query), kFileListFields, callback);
384 } 400 }
385 401
386 CancelCallback DriveAPIService::SearchByTitle( 402 CancelCallback DriveAPIService::SearchByTitle(
387 const std::string& title, 403 const std::string& title,
388 const std::string& directory_resource_id, 404 const std::string& directory_resource_id,
389 const FileListCallback& callback) { 405 const FileListCallback& callback) {
390 DCHECK(thread_checker_.CalledOnValidThread()); 406 DCHECK(thread_checker_.CalledOnValidThread());
391 DCHECK(!title.empty()); 407 DCHECK(!title.empty());
392 DCHECK(!callback.is_null()); 408 DCHECK(!callback.is_null());
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 // RequestSender before the request is committed because the request has a 930 // RequestSender before the request is committed because the request has a
915 // reference to RequestSender and we should ensure to delete the request when 931 // reference to RequestSender and we should ensure to delete the request when
916 // the sender is deleted. Resolve the circulating dependency and fix it. 932 // the sender is deleted. Resolve the circulating dependency and fix it.
917 const google_apis::CancelCallback callback = 933 const google_apis::CancelCallback callback =
918 sender_->StartRequestWithAuthRetry(std::move(request)); 934 sender_->StartRequestWithAuthRetry(std::move(request));
919 return base::MakeUnique<BatchRequestConfigurator>( 935 return base::MakeUnique<BatchRequestConfigurator>(
920 weak_ref, sender_->blocking_task_runner(), url_generator_, callback); 936 weak_ref, sender_->blocking_task_runner(), url_generator_, callback);
921 } 937 }
922 938
923 } // namespace drive 939 } // namespace drive
OLDNEW
« no previous file with comments | « components/drive/service/drive_api_service.h ('k') | components/drive/service/drive_service_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698