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

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

Issue 2693093002: Fetch file metadata of files under Team Drives. (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « google_apis/drive/drive_api_url_generator.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/logging.h" 8 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
10 #include "google_apis/google_api_keys.h" 11 #include "google_apis/google_api_keys.h"
11 #include "net/base/escape.h" 12 #include "net/base/escape.h"
12 #include "net/base/url_util.h" 13 #include "net/base/url_util.h"
13 14
14 namespace google_apis { 15 namespace google_apis {
15 16
16 namespace { 17 namespace {
17 18
18 // Hard coded URLs for communication with a google drive server. 19 // Hard coded URLs for communication with a google drive server.
20 // TODO(yamaguchi): Make a utility function to compose some of these URLs by a
21 // version and a resource name.
19 const char kDriveV2AboutUrl[] = "drive/v2/about"; 22 const char kDriveV2AboutUrl[] = "drive/v2/about";
20 const char kDriveV2AppsUrl[] = "drive/v2/apps"; 23 const char kDriveV2AppsUrl[] = "drive/v2/apps";
21 const char kDriveV2ChangelistUrl[] = "drive/v2/changes"; 24 const char kDriveV2ChangelistUrl[] = "drive/v2/changes";
25 const char kDriveV2BetaChangelistUrl[] = "drive/v2beta/changes";
fukino 2017/02/14 19:24:22 Are the new APIs available only in v2beta? If it's
yamaguchi 2017/02/17 08:44:56 It's available only in v2beta right now.
22 const char kDriveV2FilesUrl[] = "drive/v2/files"; 26 const char kDriveV2FilesUrl[] = "drive/v2/files";
27 const char kDriveV2BetaFilesUrl[] = "drive/v2beta/files";
23 const char kDriveV2FileUrlPrefix[] = "drive/v2/files/"; 28 const char kDriveV2FileUrlPrefix[] = "drive/v2/files/";
29 const char kDriveV2BetaFileUrlPrefix[] = "drive/v2beta/files/";
24 const char kDriveV2ChildrenUrlFormat[] = "drive/v2/files/%s/children"; 30 const char kDriveV2ChildrenUrlFormat[] = "drive/v2/files/%s/children";
25 const char kDriveV2ChildrenUrlForRemovalFormat[] = 31 const char kDriveV2ChildrenUrlForRemovalFormat[] =
26 "drive/v2/files/%s/children/%s"; 32 "drive/v2/files/%s/children/%s";
27 const char kDriveV2FileCopyUrlFormat[] = "drive/v2/files/%s/copy"; 33 const char kDriveV2FileCopyUrlFormat[] = "drive/v2/files/%s/copy";
28 const char kDriveV2FileDeleteUrlFormat[] = "drive/v2/files/%s"; 34 const char kDriveV2FileDeleteUrlFormat[] = "drive/v2/files/%s";
29 const char kDriveV2FileTrashUrlFormat[] = "drive/v2/files/%s/trash"; 35 const char kDriveV2FileTrashUrlFormat[] = "drive/v2/files/%s/trash";
30 const char kDriveV2UploadNewFileUrl[] = "upload/drive/v2/files"; 36 const char kDriveV2UploadNewFileUrl[] = "upload/drive/v2/files";
31 const char kDriveV2UploadExistingFileUrlPrefix[] = "upload/drive/v2/files/"; 37 const char kDriveV2UploadExistingFileUrlPrefix[] = "upload/drive/v2/files/";
32 const char kDriveV2BatchUploadUrl[] = "upload/drive"; 38 const char kDriveV2BatchUploadUrl[] = "upload/drive";
33 const char kDriveV2PermissionsUrlFormat[] = "drive/v2/files/%s/permissions"; 39 const char kDriveV2PermissionsUrlFormat[] = "drive/v2/files/%s/permissions";
34 const char kDriveV2DownloadUrlFormat[] = "drive/v2/files/%s?alt=media"; 40 const char kDriveV2DownloadUrlFormat[] = "drive/v2/files/%s?alt=media";
35 const char kDriveV2ThumbnailUrlFormat[] = "d/%s=w%d-h%d"; 41 const char kDriveV2ThumbnailUrlFormat[] = "d/%s=w%d-h%d";
36 const char kDriveV2ThumbnailUrlWithCropFormat[] = "d/%s=w%d-h%d-c"; 42 const char kDriveV2ThumbnailUrlWithCropFormat[] = "d/%s=w%d-h%d-c";
37 43
44 const char kIncludeTeamDriveItems[] = "includeTeamDriveItems";
45 const char kSupportsTeamDrives[] = "supportsTeamDrives";
46
38 // apps.delete and file.authorize API is exposed through a special endpoint 47 // apps.delete and file.authorize API is exposed through a special endpoint
39 // v2internal that is accessible only by the official API key for Chrome. 48 // v2internal that is accessible only by the official API key for Chrome.
40 const char kDriveV2InternalAppsUrl[] = "drive/v2internal/apps"; 49 const char kDriveV2InternalAppsUrl[] = "drive/v2internal/apps";
41 const char kDriveV2AppsDeleteUrlFormat[] = "drive/v2internal/apps/%s"; 50 const char kDriveV2AppsDeleteUrlFormat[] = "drive/v2internal/apps/%s";
42 const char kDriveV2FilesAuthorizeUrlFormat[] = 51 const char kDriveV2FilesAuthorizeUrlFormat[] =
43 "drive/v2internal/files/%s/authorize?appId=%s"; 52 "drive/v2internal/files/%s/authorize?appId=%s";
44 const char kDriveV2InternalFileUrlPrefix[] = "drive/v2internal/files/"; 53 const char kDriveV2InternalFileUrlPrefix[] = "drive/v2internal/files/";
45 54
55 namespace switches {
56
57 // Enables or disables Team Drives integration.
58 const char kEnableTeamDrives[] = "team-drives";
59
60 } // namespace switches
61
62 bool IsTeamDrivesEnabled() {
63 const base::CommandLine& command_line =
64 *base::CommandLine::ForCurrentProcess();
65 return command_line.HasSwitch(switches::kEnableTeamDrives);
66 }
67
46 GURL AddResumableUploadParam(const GURL& url) { 68 GURL AddResumableUploadParam(const GURL& url) {
47 return net::AppendOrReplaceQueryParameter(url, "uploadType", "resumable"); 69 return net::AppendOrReplaceQueryParameter(url, "uploadType", "resumable");
48 } 70 }
49 71
50 GURL AddMultipartUploadParam(const GURL& url) { 72 GURL AddMultipartUploadParam(const GURL& url) {
51 return net::AppendOrReplaceQueryParameter(url, "uploadType", "multipart"); 73 return net::AppendOrReplaceQueryParameter(url, "uploadType", "multipart");
52 } 74 }
53 75
54 } // namespace 76 } // namespace
55 77
78 DriveApiUrlGenerator::DriveApiUrlGenerator(const DriveApiUrlGenerator& src)
79 : base_url_(src.base_url_),
80 base_thumbnail_url_(src.base_thumbnail_url_),
81 enable_team_drives_(src.enable_team_drives_) {
82 // Do nothing.
83 }
84
56 DriveApiUrlGenerator::DriveApiUrlGenerator(const GURL& base_url, 85 DriveApiUrlGenerator::DriveApiUrlGenerator(const GURL& base_url,
57 const GURL& base_thumbnail_url) 86 const GURL& base_thumbnail_url)
58 : base_url_(base_url), 87 : base_url_(base_url),
59 base_thumbnail_url_(base_thumbnail_url) { 88 base_thumbnail_url_(base_thumbnail_url),
89 enable_team_drives_(IsTeamDrivesEnabled()) {
60 // Do nothing. 90 // Do nothing.
61 } 91 }
62 92
63 DriveApiUrlGenerator::~DriveApiUrlGenerator() { 93 DriveApiUrlGenerator::~DriveApiUrlGenerator() {
64 // Do nothing. 94 // Do nothing.
65 } 95 }
66 96
67 const char DriveApiUrlGenerator::kBaseUrlForProduction[] = 97 const char DriveApiUrlGenerator::kBaseUrlForProduction[] =
68 "https://www.googleapis.com"; 98 "https://www.googleapis.com";
69 99
(...skipping 10 matching lines...) Expand all
80 } 110 }
81 111
82 GURL DriveApiUrlGenerator::GetAppsDeleteUrl(const std::string& app_id) const { 112 GURL DriveApiUrlGenerator::GetAppsDeleteUrl(const std::string& app_id) const {
83 return base_url_.Resolve(base::StringPrintf( 113 return base_url_.Resolve(base::StringPrintf(
84 kDriveV2AppsDeleteUrlFormat, net::EscapePath(app_id).c_str())); 114 kDriveV2AppsDeleteUrlFormat, net::EscapePath(app_id).c_str()));
85 } 115 }
86 116
87 GURL DriveApiUrlGenerator::GetFilesGetUrl(const std::string& file_id, 117 GURL DriveApiUrlGenerator::GetFilesGetUrl(const std::string& file_id,
88 bool use_internal_endpoint, 118 bool use_internal_endpoint,
89 const GURL& embed_origin) const { 119 const GURL& embed_origin) const {
90 GURL url = base_url_.Resolve(use_internal_endpoint ? 120 const char* url_prefix;
91 kDriveV2InternalFileUrlPrefix + net::EscapePath(file_id) : 121 if (use_internal_endpoint)
92 kDriveV2FileUrlPrefix + net::EscapePath(file_id)); 122 url_prefix = kDriveV2InternalFileUrlPrefix;
123 else if (enable_team_drives_)
124 url_prefix = kDriveV2BetaFileUrlPrefix;
125 else
126 url_prefix = kDriveV2FileUrlPrefix;
127
128 GURL url = base_url_.Resolve(url_prefix + net::EscapePath(file_id));
129
130 if (enable_team_drives_)
131 url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
132
93 if (!embed_origin.is_empty()) { 133 if (!embed_origin.is_empty()) {
94 // Construct a valid serialized embed origin from an url, according to 134 // Construct a valid serialized embed origin from an url, according to
95 // WD-html5-20110525. Such string has to be built manually, since 135 // WD-html5-20110525. Such string has to be built manually, since
96 // GURL::spec() always adds the trailing slash. Moreover, ports are 136 // GURL::spec() always adds the trailing slash. Moreover, ports are
97 // currently not supported. 137 // currently not supported.
98 DCHECK(!embed_origin.has_port()); 138 DCHECK(!embed_origin.has_port());
99 DCHECK(!embed_origin.has_path() || embed_origin.path() == "/"); 139 DCHECK(!embed_origin.has_path() || embed_origin.path() == "/");
100 const std::string serialized_embed_origin = 140 const std::string serialized_embed_origin =
101 embed_origin.scheme() + "://" + embed_origin.host(); 141 embed_origin.scheme() + "://" + embed_origin.host();
102 url = net::AppendOrReplaceQueryParameter( 142 url = net::AppendOrReplaceQueryParameter(
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 url = net::AppendOrReplaceQueryParameter(url, "visibility", visibility); 190 url = net::AppendOrReplaceQueryParameter(url, "visibility", visibility);
151 191
152 return url; 192 return url;
153 } 193 }
154 194
155 GURL DriveApiUrlGenerator::GetFilesListUrl(int max_results, 195 GURL DriveApiUrlGenerator::GetFilesListUrl(int max_results,
156 const std::string& page_token, 196 const std::string& page_token,
157 const std::string& q) const { 197 const std::string& q) const {
158 GURL url = base_url_.Resolve(kDriveV2FilesUrl); 198 GURL url = base_url_.Resolve(kDriveV2FilesUrl);
159 199
200 if (enable_team_drives_) {
201 url = base_url_.Resolve(kDriveV2BetaFilesUrl);
202 url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
203 url = net::AppendOrReplaceQueryParameter(url, kIncludeTeamDriveItems,
204 "true");
205 }
160 // maxResults is 100 by default. 206 // maxResults is 100 by default.
161 if (max_results != 100) { 207 if (max_results != 100) {
162 url = net::AppendOrReplaceQueryParameter( 208 url = net::AppendOrReplaceQueryParameter(
163 url, "maxResults", base::IntToString(max_results)); 209 url, "maxResults", base::IntToString(max_results));
164 } 210 }
165 211
166 if (!page_token.empty()) 212 if (!page_token.empty())
167 url = net::AppendOrReplaceQueryParameter(url, "pageToken", page_token); 213 url = net::AppendOrReplaceQueryParameter(url, "pageToken", page_token);
168 214
169 if (!q.empty()) 215 if (!q.empty())
(...skipping 11 matching lines...) Expand all
181 return base_url_.Resolve(base::StringPrintf( 227 return base_url_.Resolve(base::StringPrintf(
182 kDriveV2FileTrashUrlFormat, net::EscapePath(file_id).c_str())); 228 kDriveV2FileTrashUrlFormat, net::EscapePath(file_id).c_str()));
183 } 229 }
184 230
185 GURL DriveApiUrlGenerator::GetChangesListUrl(bool include_deleted, 231 GURL DriveApiUrlGenerator::GetChangesListUrl(bool include_deleted,
186 int max_results, 232 int max_results,
187 const std::string& page_token, 233 const std::string& page_token,
188 int64_t start_change_id) const { 234 int64_t start_change_id) const {
189 DCHECK_GE(start_change_id, 0); 235 DCHECK_GE(start_change_id, 0);
190 236
191 GURL url = base_url_.Resolve(kDriveV2ChangelistUrl); 237 GURL url;
192 238 if (enable_team_drives_) {
239 url = base_url_.Resolve(kDriveV2BetaChangelistUrl);
240 url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
241 url = net::AppendOrReplaceQueryParameter(url, kIncludeTeamDriveItems,
242 "true");
243 } else {
244 url = base_url_.Resolve(kDriveV2ChangelistUrl);
245 }
193 // includeDeleted is "true" by default. 246 // includeDeleted is "true" by default.
194 if (!include_deleted) 247 if (!include_deleted)
195 url = net::AppendOrReplaceQueryParameter(url, "includeDeleted", "false"); 248 url = net::AppendOrReplaceQueryParameter(url, "includeDeleted", "false");
196 249
197 // maxResults is "100" by default. 250 // maxResults is "100" by default.
198 if (max_results != 100) { 251 if (max_results != 100) {
199 url = net::AppendOrReplaceQueryParameter( 252 url = net::AppendOrReplaceQueryParameter(
200 url, "maxResults", base::IntToString(max_results)); 253 url, "maxResults", base::IntToString(max_results));
201 } 254 }
202 255
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 base::StringPrintf( 352 base::StringPrintf(
300 crop ? kDriveV2ThumbnailUrlWithCropFormat : kDriveV2ThumbnailUrlFormat, 353 crop ? kDriveV2ThumbnailUrlWithCropFormat : kDriveV2ThumbnailUrlFormat,
301 net::EscapePath(resource_id).c_str(), width, height)); 354 net::EscapePath(resource_id).c_str(), width, height));
302 } 355 }
303 356
304 GURL DriveApiUrlGenerator::GetBatchUploadUrl() const { 357 GURL DriveApiUrlGenerator::GetBatchUploadUrl() const {
305 return base_url_.Resolve(kDriveV2BatchUploadUrl); 358 return base_url_.Resolve(kDriveV2BatchUploadUrl);
306 } 359 }
307 360
308 } // namespace google_apis 361 } // namespace google_apis
OLDNEW
« no previous file with comments | « google_apis/drive/drive_api_url_generator.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698