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

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

Issue 2894513003: Fetch files shared in Team Drives by specifying allTeamDrives corpora. (Closed)
Patch Set: Eliminate variables of class type with static storage duration. 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,
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 = (google_apis::GetTeamDrivesIntegrationSwitch() ==
369 google_apis::TEAM_DRIVES_INTEGRATION_ENABLED)
370 ? google_apis::CORPORA_ALL_TEAM_DRIVES
371 : google_apis::CORPORA_DEFAULT;
372
359 // Because children.list method on Drive API v2 returns only the list of 373 // Because children.list method on Drive API v2 returns only the list of
360 // children's references, but we need all file resource list. 374 // children's references, but we need all file resource list.
361 // So, here we use files.list method instead, with setting parents query. 375 // 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 376 // 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 377 // code up by moving the responsibility to include "parents" in the query
364 // to client side. 378 // to client side.
365 // We aren't interested in files in trash in this context, neither. 379 // We aren't interested in files in trash in this context, neither.
366 return files_list_request_runner_->CreateAndStartWithSizeBackoff( 380 return files_list_request_runner_->CreateAndStartWithSizeBackoff(
367 kMaxNumFilesResourcePerRequest, 381 kMaxNumFilesResourcePerRequest, corpora, "",
hashimoto 2017/06/02 09:44:46 Use std::string() instead "" to avoid char*->std::
yamaguchi 2017/06/02 12:04:01 Done.
368 base::StringPrintf( 382 base::StringPrintf(
369 "'%s' in parents and trashed = false", 383 "'%s' in parents and trashed = false",
370 util::EscapeQueryStringValue(directory_resource_id).c_str()), 384 util::EscapeQueryStringValue(directory_resource_id).c_str()),
371 kFileListFields, callback); 385 kFileListFields, callback);
372 } 386 }
373 387
374 CancelCallback DriveAPIService::Search( 388 CancelCallback DriveAPIService::Search(
375 const std::string& search_query, 389 const std::string& search_query,
376 const FileListCallback& callback) { 390 const FileListCallback& callback) {
377 DCHECK(thread_checker_.CalledOnValidThread()); 391 DCHECK(thread_checker_.CalledOnValidThread());
378 DCHECK(!search_query.empty()); 392 DCHECK(!search_query.empty());
379 DCHECK(!callback.is_null()); 393 DCHECK(!callback.is_null());
380 394
395 FilesListCorpora corpora = (google_apis::GetTeamDrivesIntegrationSwitch() ==
396 google_apis::TEAM_DRIVES_INTEGRATION_ENABLED)
397 ? google_apis::CORPORA_ALL_TEAM_DRIVES
398 : google_apis::CORPORA_DEFAULT;
399
381 return files_list_request_runner_->CreateAndStartWithSizeBackoff( 400 return files_list_request_runner_->CreateAndStartWithSizeBackoff(
382 kMaxNumFilesResourcePerRequestForSearch, 401 kMaxNumFilesResourcePerRequestForSearch, corpora, "",
383 util::TranslateQuery(search_query), kFileListFields, callback); 402 util::TranslateQuery(search_query), kFileListFields, callback);
384 } 403 }
385 404
386 CancelCallback DriveAPIService::SearchByTitle( 405 CancelCallback DriveAPIService::SearchByTitle(
387 const std::string& title, 406 const std::string& title,
388 const std::string& directory_resource_id, 407 const std::string& directory_resource_id,
389 const FileListCallback& callback) { 408 const FileListCallback& callback) {
390 DCHECK(thread_checker_.CalledOnValidThread()); 409 DCHECK(thread_checker_.CalledOnValidThread());
391 DCHECK(!title.empty()); 410 DCHECK(!title.empty());
392 DCHECK(!callback.is_null()); 411 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 933 // RequestSender before the request is committed because the request has a
915 // reference to RequestSender and we should ensure to delete the request when 934 // reference to RequestSender and we should ensure to delete the request when
916 // the sender is deleted. Resolve the circulating dependency and fix it. 935 // the sender is deleted. Resolve the circulating dependency and fix it.
917 const google_apis::CancelCallback callback = 936 const google_apis::CancelCallback callback =
918 sender_->StartRequestWithAuthRetry(std::move(request)); 937 sender_->StartRequestWithAuthRetry(std::move(request));
919 return base::MakeUnique<BatchRequestConfigurator>( 938 return base::MakeUnique<BatchRequestConfigurator>(
920 weak_ref, sender_->blocking_task_runner(), url_generator_, callback); 939 weak_ref, sender_->blocking_task_runner(), url_generator_, callback);
921 } 940 }
922 941
923 } // namespace drive 942 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | google_apis/drive/drive_api_requests.h » ('j') | google_apis/drive/drive_api_requests.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698