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

Side by Side Diff: google_apis/drive/files_list_request_runner.cc

Issue 2894513003: Fetch files shared in Team Drives by specifying allTeamDrives corpora. (Closed)
Patch Set: Make comment style consistent with existing one 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "google_apis/drive/files_list_request_runner.h" 5 #include "google_apis/drive/files_list_request_runner.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 11 matching lines...) Expand all
22 : request_sender_(request_sender), 22 : request_sender_(request_sender),
23 url_generator_(url_generator), 23 url_generator_(url_generator),
24 weak_ptr_factory_(this) { 24 weak_ptr_factory_(this) {
25 } 25 }
26 26
27 FilesListRequestRunner::~FilesListRequestRunner() { 27 FilesListRequestRunner::~FilesListRequestRunner() {
28 } 28 }
29 29
30 CancelCallback FilesListRequestRunner::CreateAndStartWithSizeBackoff( 30 CancelCallback FilesListRequestRunner::CreateAndStartWithSizeBackoff(
31 int max_results, 31 int max_results,
32 FilesListCorpora corpora,
33 const std::string& team_drive_id,
32 const std::string& q, 34 const std::string& q,
33 const std::string& fields, 35 const std::string& fields,
34 const FileListCallback& callback) { 36 const FileListCallback& callback) {
35 UMA_HISTOGRAM_COUNTS_1000("Drive.FilesListRequestRunner.MaxResults", 37 UMA_HISTOGRAM_COUNTS_1000("Drive.FilesListRequestRunner.MaxResults",
36 max_results); 38 max_results);
37 base::Closure* const cancel_callback = new base::Closure; 39 base::Closure* const cancel_callback = new base::Closure;
38 std::unique_ptr<drive::FilesListRequest> request = 40 std::unique_ptr<drive::FilesListRequest> request =
39 base::MakeUnique<drive::FilesListRequest>( 41 base::MakeUnique<drive::FilesListRequest>(
40 request_sender_, url_generator_, 42 request_sender_, url_generator_,
41 base::Bind(&FilesListRequestRunner::OnCompleted, 43 base::Bind(&FilesListRequestRunner::OnCompleted,
42 weak_ptr_factory_.GetWeakPtr(), max_results, q, fields, 44 weak_ptr_factory_.GetWeakPtr(), max_results, corpora,
43 callback, base::Owned(cancel_callback))); 45 team_drive_id, q, fields, callback,
46 base::Owned(cancel_callback)));
44 request->set_max_results(max_results); 47 request->set_max_results(max_results);
45 request->set_q(q); 48 request->set_q(q);
46 request->set_fields(fields); 49 request->set_fields(fields);
47 *cancel_callback = 50 *cancel_callback =
48 request_sender_->StartRequestWithAuthRetry(std::move(request)); 51 request_sender_->StartRequestWithAuthRetry(std::move(request));
49 52
50 // The cancellation callback is owned by the completion callback, so it must 53 // The cancellation callback is owned by the completion callback, so it must
51 // not be used after |callback| is called. 54 // not be used after |callback| is called.
52 return base::Bind(&FilesListRequestRunner::OnCancel, 55 return base::Bind(&FilesListRequestRunner::OnCancel,
53 weak_ptr_factory_.GetWeakPtr(), 56 weak_ptr_factory_.GetWeakPtr(),
54 base::Unretained(cancel_callback)); 57 base::Unretained(cancel_callback));
55 } 58 }
56 59
57 void FilesListRequestRunner::OnCancel(base::Closure* cancel_callback) { 60 void FilesListRequestRunner::OnCancel(base::Closure* cancel_callback) {
58 DCHECK(cancel_callback); 61 DCHECK(cancel_callback);
59 DCHECK(!cancel_callback->is_null()); 62 DCHECK(!cancel_callback->is_null());
60 cancel_callback->Run(); 63 cancel_callback->Run();
61 } 64 }
62 65
63 void FilesListRequestRunner::OnCompleted(int max_results, 66 void FilesListRequestRunner::OnCompleted(int max_results,
67 FilesListCorpora corpora,
68 const std::string& team_drive_id,
64 const std::string& q, 69 const std::string& q,
65 const std::string& fields, 70 const std::string& fields,
66 const FileListCallback& callback, 71 const FileListCallback& callback,
67 CancelCallback* cancel_callback, 72 CancelCallback* cancel_callback,
68 DriveApiErrorCode error, 73 DriveApiErrorCode error,
69 std::unique_ptr<FileList> entry) { 74 std::unique_ptr<FileList> entry) {
70 if (!request_completed_callback_for_testing_.is_null()) 75 if (!request_completed_callback_for_testing_.is_null())
71 request_completed_callback_for_testing_.Run(); 76 request_completed_callback_for_testing_.Run();
72 77
73 UMA_HISTOGRAM_SPARSE_SLOWLY( 78 UMA_HISTOGRAM_SPARSE_SLOWLY(
74 "Drive.FilesListRequestRunner.ApiErrorCode", error); 79 "Drive.FilesListRequestRunner.ApiErrorCode", error);
75 80
76 if (error == google_apis::DRIVE_RESPONSE_TOO_LARGE && max_results > 1) { 81 if (error == google_apis::DRIVE_RESPONSE_TOO_LARGE && max_results > 1) {
77 CreateAndStartWithSizeBackoff(max_results / 2, q, fields, callback); 82 CreateAndStartWithSizeBackoff(max_results / 2, corpora, team_drive_id, q,
83 fields, callback);
78 return; 84 return;
79 } 85 }
80 86
81 callback.Run(error, std::move(entry)); 87 callback.Run(error, std::move(entry));
82 } 88 }
83 89
84 void FilesListRequestRunner::SetRequestCompletedCallbackForTesting( 90 void FilesListRequestRunner::SetRequestCompletedCallbackForTesting(
85 const base::Closure& callback) { 91 const base::Closure& callback) {
86 request_completed_callback_for_testing_ = callback; 92 request_completed_callback_for_testing_ = callback;
87 } 93 }
88 94
89 } // namespace google_apis 95 } // namespace google_apis
OLDNEW
« no previous file with comments | « google_apis/drive/files_list_request_runner.h ('k') | google_apis/drive/files_list_request_runner_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698