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

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

Issue 2747423004: Use Drive v2 API for team drive operations. (Closed)
Patch Set: Created 3 years, 9 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"
11 #include "google_apis/drive/drive_switches.h" 11 #include "google_apis/drive/drive_switches.h"
12 #include "google_apis/google_api_keys.h" 12 #include "google_apis/google_api_keys.h"
13 #include "net/base/escape.h" 13 #include "net/base/escape.h"
14 #include "net/base/url_util.h" 14 #include "net/base/url_util.h"
15 15
16 namespace google_apis { 16 namespace google_apis {
17 17
18 namespace { 18 namespace {
19 19
20 // Hard coded URLs for communication with a google drive server. 20 // Hard coded URLs for communication with a google drive server.
21 // TODO(yamaguchi): Make a utility function to compose some of these URLs by a 21 // TODO(yamaguchi): Make a utility function to compose some of these URLs by a
22 // version and a resource name. 22 // version and a resource name.
23 const char kDriveV2AboutUrl[] = "drive/v2/about"; 23 const char kDriveV2AboutUrl[] = "drive/v2/about";
24 const char kDriveV2AppsUrl[] = "drive/v2/apps"; 24 const char kDriveV2AppsUrl[] = "drive/v2/apps";
25 const char kDriveV2ChangelistUrl[] = "drive/v2/changes"; 25 const char kDriveV2ChangelistUrl[] = "drive/v2/changes";
26 const char kDriveV2BetaChangelistUrl[] = "drive/v2beta/changes";
27 const char kDriveV2FilesUrl[] = "drive/v2/files"; 26 const char kDriveV2FilesUrl[] = "drive/v2/files";
28 const char kDriveV2BetaFilesUrl[] = "drive/v2beta/files";
29 const char kDriveV2FileUrlPrefix[] = "drive/v2/files/"; 27 const char kDriveV2FileUrlPrefix[] = "drive/v2/files/";
30 const char kDriveV2BetaFileUrlPrefix[] = "drive/v2beta/files/";
31 const char kDriveV2ChildrenUrlFormat[] = "drive/v2/files/%s/children"; 28 const char kDriveV2ChildrenUrlFormat[] = "drive/v2/files/%s/children";
32 const char kDriveV2ChildrenUrlForRemovalFormat[] = 29 const char kDriveV2ChildrenUrlForRemovalFormat[] =
33 "drive/v2/files/%s/children/%s"; 30 "drive/v2/files/%s/children/%s";
34 const char kDriveV2FileCopyUrlFormat[] = "drive/v2/files/%s/copy"; 31 const char kDriveV2FileCopyUrlFormat[] = "drive/v2/files/%s/copy";
35 const char kDriveV2FileDeleteUrlFormat[] = "drive/v2/files/%s"; 32 const char kDriveV2FileDeleteUrlFormat[] = "drive/v2/files/%s";
36 const char kDriveV2FileTrashUrlFormat[] = "drive/v2/files/%s/trash"; 33 const char kDriveV2FileTrashUrlFormat[] = "drive/v2/files/%s/trash";
37 const char kDriveV2UploadNewFileUrl[] = "upload/drive/v2/files"; 34 const char kDriveV2UploadNewFileUrl[] = "upload/drive/v2/files";
38 const char kDriveV2UploadExistingFileUrlPrefix[] = "upload/drive/v2/files/"; 35 const char kDriveV2UploadExistingFileUrlPrefix[] = "upload/drive/v2/files/";
39 const char kDriveV2BatchUploadUrl[] = "upload/drive"; 36 const char kDriveV2BatchUploadUrl[] = "upload/drive";
40 const char kDriveV2PermissionsUrlFormat[] = "drive/v2/files/%s/permissions"; 37 const char kDriveV2PermissionsUrlFormat[] = "drive/v2/files/%s/permissions";
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 return base_url_.Resolve(base::StringPrintf( 96 return base_url_.Resolve(base::StringPrintf(
100 kDriveV2AppsDeleteUrlFormat, net::EscapePath(app_id).c_str())); 97 kDriveV2AppsDeleteUrlFormat, net::EscapePath(app_id).c_str()));
101 } 98 }
102 99
103 GURL DriveApiUrlGenerator::GetFilesGetUrl(const std::string& file_id, 100 GURL DriveApiUrlGenerator::GetFilesGetUrl(const std::string& file_id,
104 bool use_internal_endpoint, 101 bool use_internal_endpoint,
105 const GURL& embed_origin) const { 102 const GURL& embed_origin) const {
106 const char* url_prefix = nullptr; 103 const char* url_prefix = nullptr;
107 if (use_internal_endpoint) 104 if (use_internal_endpoint)
108 url_prefix = kDriveV2InternalFileUrlPrefix; 105 url_prefix = kDriveV2InternalFileUrlPrefix;
109 else if (enable_team_drives_)
110 url_prefix = kDriveV2BetaFileUrlPrefix;
111 else 106 else
112 url_prefix = kDriveV2FileUrlPrefix; 107 url_prefix = kDriveV2FileUrlPrefix;
113 108
114 GURL url = base_url_.Resolve(url_prefix + net::EscapePath(file_id)); 109 GURL url = base_url_.Resolve(url_prefix + net::EscapePath(file_id));
115 110
116 if (enable_team_drives_) 111 if (enable_team_drives_)
117 url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true"); 112 url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
118 113
119 if (!embed_origin.is_empty()) { 114 if (!embed_origin.is_empty()) {
120 // Construct a valid serialized embed origin from an url, according to 115 // Construct a valid serialized embed origin from an url, according to
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 169
175 if (!visibility.empty()) 170 if (!visibility.empty())
176 url = net::AppendOrReplaceQueryParameter(url, "visibility", visibility); 171 url = net::AppendOrReplaceQueryParameter(url, "visibility", visibility);
177 172
178 return url; 173 return url;
179 } 174 }
180 175
181 GURL DriveApiUrlGenerator::GetFilesListUrl(int max_results, 176 GURL DriveApiUrlGenerator::GetFilesListUrl(int max_results,
182 const std::string& page_token, 177 const std::string& page_token,
183 const std::string& q) const { 178 const std::string& q) const {
184 GURL url; 179 GURL url = base_url_.Resolve(kDriveV2FilesUrl);
185 if (enable_team_drives_) { 180 if (enable_team_drives_) {
186 url = base_url_.Resolve(kDriveV2BetaFilesUrl);
187 url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true"); 181 url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
188 url = net::AppendOrReplaceQueryParameter(url, kIncludeTeamDriveItems, 182 url = net::AppendOrReplaceQueryParameter(url, kIncludeTeamDriveItems,
189 "true"); 183 "true");
190 } else {
191 url = base_url_.Resolve(kDriveV2FilesUrl);
192 } 184 }
193 // maxResults is 100 by default. 185 // maxResults is 100 by default.
194 if (max_results != 100) { 186 if (max_results != 100) {
195 url = net::AppendOrReplaceQueryParameter( 187 url = net::AppendOrReplaceQueryParameter(
196 url, "maxResults", base::IntToString(max_results)); 188 url, "maxResults", base::IntToString(max_results));
197 } 189 }
198 190
199 if (!page_token.empty()) 191 if (!page_token.empty())
200 url = net::AppendOrReplaceQueryParameter(url, "pageToken", page_token); 192 url = net::AppendOrReplaceQueryParameter(url, "pageToken", page_token);
201 193
(...skipping 12 matching lines...) Expand all
214 return base_url_.Resolve(base::StringPrintf( 206 return base_url_.Resolve(base::StringPrintf(
215 kDriveV2FileTrashUrlFormat, net::EscapePath(file_id).c_str())); 207 kDriveV2FileTrashUrlFormat, net::EscapePath(file_id).c_str()));
216 } 208 }
217 209
218 GURL DriveApiUrlGenerator::GetChangesListUrl(bool include_deleted, 210 GURL DriveApiUrlGenerator::GetChangesListUrl(bool include_deleted,
219 int max_results, 211 int max_results,
220 const std::string& page_token, 212 const std::string& page_token,
221 int64_t start_change_id) const { 213 int64_t start_change_id) const {
222 DCHECK_GE(start_change_id, 0); 214 DCHECK_GE(start_change_id, 0);
223 215
224 GURL url; 216 GURL url = base_url_.Resolve(kDriveV2ChangelistUrl);
225 if (enable_team_drives_) { 217 if (enable_team_drives_) {
226 url = base_url_.Resolve(kDriveV2BetaChangelistUrl);
227 url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true"); 218 url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
228 url = net::AppendOrReplaceQueryParameter(url, kIncludeTeamDriveItems, 219 url = net::AppendOrReplaceQueryParameter(url, kIncludeTeamDriveItems,
229 "true"); 220 "true");
230 } else {
231 url = base_url_.Resolve(kDriveV2ChangelistUrl);
232 } 221 }
233 // includeDeleted is "true" by default. 222 // includeDeleted is "true" by default.
234 if (!include_deleted) 223 if (!include_deleted)
235 url = net::AppendOrReplaceQueryParameter(url, "includeDeleted", "false"); 224 url = net::AppendOrReplaceQueryParameter(url, "includeDeleted", "false");
236 225
237 // maxResults is "100" by default. 226 // maxResults is "100" by default.
238 if (max_results != 100) { 227 if (max_results != 100) {
239 url = net::AppendOrReplaceQueryParameter( 228 url = net::AppendOrReplaceQueryParameter(
240 url, "maxResults", base::IntToString(max_results)); 229 url, "maxResults", base::IntToString(max_results));
241 } 230 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 base::StringPrintf( 328 base::StringPrintf(
340 crop ? kDriveV2ThumbnailUrlWithCropFormat : kDriveV2ThumbnailUrlFormat, 329 crop ? kDriveV2ThumbnailUrlWithCropFormat : kDriveV2ThumbnailUrlFormat,
341 net::EscapePath(resource_id).c_str(), width, height)); 330 net::EscapePath(resource_id).c_str(), width, height));
342 } 331 }
343 332
344 GURL DriveApiUrlGenerator::GetBatchUploadUrl() const { 333 GURL DriveApiUrlGenerator::GetBatchUploadUrl() const {
345 return base_url_.Resolve(kDriveV2BatchUploadUrl); 334 return base_url_.Resolve(kDriveV2BatchUploadUrl);
346 } 335 }
347 336
348 } // namespace google_apis 337 } // namespace google_apis
OLDNEW
« no previous file with comments | « google_apis/drive/drive_api_parser.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