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

Side by Side Diff: google_apis/drive/drive_api_url_generator.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 (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 "google_apis/drive/drive_api_url_generator.h" 5 #include "google_apis/drive/drive_api_url_generator.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 24 matching lines...) Expand all
35 const char kDriveV2UploadExistingFileUrlPrefix[] = "upload/drive/v2/files/"; 35 const char kDriveV2UploadExistingFileUrlPrefix[] = "upload/drive/v2/files/";
36 const char kDriveV2BatchUploadUrl[] = "upload/drive"; 36 const char kDriveV2BatchUploadUrl[] = "upload/drive";
37 const char kDriveV2PermissionsUrlFormat[] = "drive/v2/files/%s/permissions"; 37 const char kDriveV2PermissionsUrlFormat[] = "drive/v2/files/%s/permissions";
38 const char kDriveV2DownloadUrlFormat[] = "drive/v2/files/%s?alt=media"; 38 const char kDriveV2DownloadUrlFormat[] = "drive/v2/files/%s?alt=media";
39 const char kDriveV2ThumbnailUrlFormat[] = "d/%s=w%d-h%d"; 39 const char kDriveV2ThumbnailUrlFormat[] = "d/%s=w%d-h%d";
40 const char kDriveV2ThumbnailUrlWithCropFormat[] = "d/%s=w%d-h%d-c"; 40 const char kDriveV2ThumbnailUrlWithCropFormat[] = "d/%s=w%d-h%d-c";
41 const char kDriveV2TeamDrivesUrl[] = "drive/v2/teamdrives"; 41 const char kDriveV2TeamDrivesUrl[] = "drive/v2/teamdrives";
42 42
43 const char kIncludeTeamDriveItems[] = "includeTeamDriveItems"; 43 const char kIncludeTeamDriveItems[] = "includeTeamDriveItems";
44 const char kSupportsTeamDrives[] = "supportsTeamDrives"; 44 const char kSupportsTeamDrives[] = "supportsTeamDrives";
45 const char kCorpora[] = "corpora";
46 const char kCorporaAllTeamDrives[] = "default,allTeamDrives";
47 const char kCorporaDefault[] = "default";
48 const char kCorporaTeamDrive[] = "teamDrive";
49 const char kTeamDriveId[] = "teamDriveId";
45 50
46 // apps.delete and file.authorize API is exposed through a special endpoint 51 // apps.delete and file.authorize API is exposed through a special endpoint
47 // v2internal that is accessible only by the official API key for Chrome. 52 // v2internal that is accessible only by the official API key for Chrome.
48 const char kDriveV2InternalAppsUrl[] = "drive/v2internal/apps"; 53 const char kDriveV2InternalAppsUrl[] = "drive/v2internal/apps";
49 const char kDriveV2AppsDeleteUrlFormat[] = "drive/v2internal/apps/%s"; 54 const char kDriveV2AppsDeleteUrlFormat[] = "drive/v2internal/apps/%s";
50 const char kDriveV2FilesAuthorizeUrlFormat[] = 55 const char kDriveV2FilesAuthorizeUrlFormat[] =
51 "drive/v2internal/files/%s/authorize?appId=%s"; 56 "drive/v2internal/files/%s/authorize?appId=%s";
52 const char kDriveV2InternalFileUrlPrefix[] = "drive/v2internal/files/"; 57 const char kDriveV2InternalFileUrlPrefix[] = "drive/v2internal/files/";
53 58
54 GURL AddResumableUploadParam(const GURL& url) { 59 GURL AddResumableUploadParam(const GURL& url) {
55 return net::AppendOrReplaceQueryParameter(url, "uploadType", "resumable"); 60 return net::AppendOrReplaceQueryParameter(url, "uploadType", "resumable");
56 } 61 }
57 62
58 GURL AddMultipartUploadParam(const GURL& url) { 63 GURL AddMultipartUploadParam(const GURL& url) {
59 return net::AppendOrReplaceQueryParameter(url, "uploadType", "multipart"); 64 return net::AppendOrReplaceQueryParameter(url, "uploadType", "multipart");
60 } 65 }
61 66
67 const char* GetCorporaString(FilesListCorpora corpora) {
68 switch (corpora) {
69 case FilesListCorpora::DEFAULT:
70 return kCorporaDefault;
71 case FilesListCorpora::TEAM_DRIVE:
72 return kCorporaTeamDrive;
73 case FilesListCorpora::ALL_TEAM_DRIVES:
74 return kCorporaAllTeamDrives;
75 }
76 NOTREACHED();
77 return kCorporaDefault;
78 }
79
62 } // namespace 80 } // namespace
63 81
64 DriveApiUrlGenerator::DriveApiUrlGenerator( 82 DriveApiUrlGenerator::DriveApiUrlGenerator(
65 const GURL& base_url, const GURL& base_thumbnail_url, 83 const GURL& base_url, const GURL& base_thumbnail_url,
66 TeamDrivesIntegrationStatus team_drives_integration) 84 TeamDrivesIntegrationStatus team_drives_integration)
67 : base_url_(base_url), 85 : base_url_(base_url),
68 base_thumbnail_url_(base_thumbnail_url), 86 base_thumbnail_url_(base_thumbnail_url),
69 enable_team_drives_( 87 enable_team_drives_(
70 team_drives_integration == TEAM_DRIVES_INTEGRATION_ENABLED) { 88 team_drives_integration == TEAM_DRIVES_INTEGRATION_ENABLED) {
71 // Do nothing. 89 // Do nothing.
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 if (enable_team_drives_) 196 if (enable_team_drives_)
179 url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true"); 197 url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
180 if (!visibility.empty()) 198 if (!visibility.empty())
181 url = net::AppendOrReplaceQueryParameter(url, "visibility", visibility); 199 url = net::AppendOrReplaceQueryParameter(url, "visibility", visibility);
182 200
183 return url; 201 return url;
184 } 202 }
185 203
186 GURL DriveApiUrlGenerator::GetFilesListUrl(int max_results, 204 GURL DriveApiUrlGenerator::GetFilesListUrl(int max_results,
187 const std::string& page_token, 205 const std::string& page_token,
206 FilesListCorpora corpora,
207 const std::string& team_drive_id,
188 const std::string& q) const { 208 const std::string& q) const {
189 GURL url = base_url_.Resolve(kDriveV2FilesUrl); 209 GURL url = base_url_.Resolve(kDriveV2FilesUrl);
190 if (enable_team_drives_) { 210 if (enable_team_drives_) {
191 url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true"); 211 url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
192 url = net::AppendOrReplaceQueryParameter(url, kIncludeTeamDriveItems, 212 if (corpora != FilesListCorpora::DEFAULT) {
193 "true"); 213 url = net::AppendOrReplaceQueryParameter(url, kIncludeTeamDriveItems,
214 "true");
215 }
216 url = net::AppendOrReplaceQueryParameter(url, kCorpora,
217 GetCorporaString(corpora));
218 if (!team_drive_id.empty())
219 url =
220 net::AppendOrReplaceQueryParameter(url, kTeamDriveId, team_drive_id);
194 } 221 }
195 // maxResults is 100 by default. 222 // maxResults is 100 by default.
196 if (max_results != 100) { 223 if (max_results != 100) {
197 url = net::AppendOrReplaceQueryParameter( 224 url = net::AppendOrReplaceQueryParameter(
198 url, "maxResults", base::IntToString(max_results)); 225 url, "maxResults", base::IntToString(max_results));
199 } 226 }
200 227
201 if (!page_token.empty()) 228 if (!page_token.empty())
202 url = net::AppendOrReplaceQueryParameter(url, "pageToken", page_token); 229 url = net::AppendOrReplaceQueryParameter(url, "pageToken", page_token);
203 230
(...skipping 27 matching lines...) Expand all
231 const std::string& team_drive_id) const { 258 const std::string& team_drive_id) const {
232 DCHECK_GE(start_change_id, 0); 259 DCHECK_GE(start_change_id, 0);
233 260
234 GURL url = base_url_.Resolve(kDriveV2ChangelistUrl); 261 GURL url = base_url_.Resolve(kDriveV2ChangelistUrl);
235 if (enable_team_drives_) { 262 if (enable_team_drives_) {
236 url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true"); 263 url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
237 url = net::AppendOrReplaceQueryParameter(url, kIncludeTeamDriveItems, 264 url = net::AppendOrReplaceQueryParameter(url, kIncludeTeamDriveItems,
238 "true"); 265 "true");
239 if (!team_drive_id.empty()) { 266 if (!team_drive_id.empty()) {
240 url = 267 url =
241 net::AppendOrReplaceQueryParameter(url, "teamDriveId", team_drive_id); 268 net::AppendOrReplaceQueryParameter(url, kTeamDriveId, team_drive_id);
242 } 269 }
243 } 270 }
244 // includeDeleted is "true" by default. 271 // includeDeleted is "true" by default.
245 if (!include_deleted) 272 if (!include_deleted)
246 url = net::AppendOrReplaceQueryParameter(url, "includeDeleted", "false"); 273 url = net::AppendOrReplaceQueryParameter(url, "includeDeleted", "false");
247 274
248 // maxResults is "100" by default. 275 // maxResults is "100" by default.
249 if (max_results != 100) { 276 if (max_results != 100) {
250 url = net::AppendOrReplaceQueryParameter( 277 url = net::AppendOrReplaceQueryParameter(
251 url, "maxResults", base::IntToString(max_results)); 278 url, "maxResults", base::IntToString(max_results));
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 url = net::AppendOrReplaceQueryParameter(url, "maxResults", 412 url = net::AppendOrReplaceQueryParameter(url, "maxResults",
386 base::IntToString(max_results)); 413 base::IntToString(max_results));
387 } 414 }
388 if (!page_token.empty()) 415 if (!page_token.empty())
389 url = net::AppendOrReplaceQueryParameter(url, "pageToken", page_token); 416 url = net::AppendOrReplaceQueryParameter(url, "pageToken", page_token);
390 417
391 return url; 418 return url;
392 } 419 }
393 420
394 } // namespace google_apis 421 } // namespace google_apis
OLDNEW
« no previous file with comments | « google_apis/drive/drive_api_url_generator.h ('k') | google_apis/drive/drive_api_url_generator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698