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

Unified Diff: google_apis/drive/drive_api_url_generator.cc

Issue 2693093002: Fetch file metadata of files under Team Drives. (Closed)
Patch Set: Rename the enum to TeamDrivesIntegrationStatus to be more descriptive. 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: google_apis/drive/drive_api_url_generator.cc
diff --git a/google_apis/drive/drive_api_url_generator.cc b/google_apis/drive/drive_api_url_generator.cc
index a2113d41463aa7c52632d159246561f9d20f7547..fc52097288163fa30d6b6fc1d346236811c29540 100644
--- a/google_apis/drive/drive_api_url_generator.cc
+++ b/google_apis/drive/drive_api_url_generator.cc
@@ -4,9 +4,11 @@
#include "google_apis/drive/drive_api_url_generator.h"
+#include "base/command_line.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
+#include "google_apis/drive/drive_switches.h"
#include "google_apis/google_api_keys.h"
#include "net/base/escape.h"
#include "net/base/url_util.h"
@@ -16,11 +18,16 @@ namespace google_apis {
namespace {
// Hard coded URLs for communication with a google drive server.
+// TODO(yamaguchi): Make a utility function to compose some of these URLs by a
+// version and a resource name.
const char kDriveV2AboutUrl[] = "drive/v2/about";
const char kDriveV2AppsUrl[] = "drive/v2/apps";
const char kDriveV2ChangelistUrl[] = "drive/v2/changes";
+const char kDriveV2BetaChangelistUrl[] = "drive/v2beta/changes";
const char kDriveV2FilesUrl[] = "drive/v2/files";
+const char kDriveV2BetaFilesUrl[] = "drive/v2beta/files";
const char kDriveV2FileUrlPrefix[] = "drive/v2/files/";
+const char kDriveV2BetaFileUrlPrefix[] = "drive/v2beta/files/";
const char kDriveV2ChildrenUrlFormat[] = "drive/v2/files/%s/children";
const char kDriveV2ChildrenUrlForRemovalFormat[] =
"drive/v2/files/%s/children/%s";
@@ -35,6 +42,9 @@ const char kDriveV2DownloadUrlFormat[] = "drive/v2/files/%s?alt=media";
const char kDriveV2ThumbnailUrlFormat[] = "d/%s=w%d-h%d";
const char kDriveV2ThumbnailUrlWithCropFormat[] = "d/%s=w%d-h%d-c";
+const char kIncludeTeamDriveItems[] = "includeTeamDriveItems";
+const char kSupportsTeamDrives[] = "supportsTeamDrives";
+
// apps.delete and file.authorize API is exposed through a special endpoint
// v2internal that is accessible only by the official API key for Chrome.
const char kDriveV2InternalAppsUrl[] = "drive/v2internal/apps";
@@ -53,13 +63,19 @@ GURL AddMultipartUploadParam(const GURL& url) {
} // namespace
-DriveApiUrlGenerator::DriveApiUrlGenerator(const GURL& base_url,
- const GURL& base_thumbnail_url)
+DriveApiUrlGenerator::DriveApiUrlGenerator(
+ const GURL& base_url, const GURL& base_thumbnail_url,
+ TeamDrivesIntegrationStatus team_drives_integration)
: base_url_(base_url),
- base_thumbnail_url_(base_thumbnail_url) {
+ base_thumbnail_url_(base_thumbnail_url),
+ enable_team_drives_(
+ team_drives_integration == TEAM_DRIVES_INTEGRATION_ENABLED) {
// Do nothing.
}
+DriveApiUrlGenerator::DriveApiUrlGenerator(const DriveApiUrlGenerator& src) =
+ default;
+
DriveApiUrlGenerator::~DriveApiUrlGenerator() {
// Do nothing.
}
@@ -87,9 +103,19 @@ GURL DriveApiUrlGenerator::GetAppsDeleteUrl(const std::string& app_id) const {
GURL DriveApiUrlGenerator::GetFilesGetUrl(const std::string& file_id,
bool use_internal_endpoint,
const GURL& embed_origin) const {
- GURL url = base_url_.Resolve(use_internal_endpoint ?
- kDriveV2InternalFileUrlPrefix + net::EscapePath(file_id) :
- kDriveV2FileUrlPrefix + net::EscapePath(file_id));
+ const char* url_prefix = nullptr;
+ if (use_internal_endpoint)
+ url_prefix = kDriveV2InternalFileUrlPrefix;
+ else if (enable_team_drives_)
+ url_prefix = kDriveV2BetaFileUrlPrefix;
+ else
+ url_prefix = kDriveV2FileUrlPrefix;
+
+ GURL url = base_url_.Resolve(url_prefix + net::EscapePath(file_id));
+
+ if (enable_team_drives_)
+ url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
+
if (!embed_origin.is_empty()) {
// Construct a valid serialized embed origin from an url, according to
// WD-html5-20110525. Such string has to be built manually, since
@@ -155,8 +181,15 @@ GURL DriveApiUrlGenerator::GetFilesCopyUrl(
GURL DriveApiUrlGenerator::GetFilesListUrl(int max_results,
const std::string& page_token,
const std::string& q) const {
- GURL url = base_url_.Resolve(kDriveV2FilesUrl);
-
+ GURL url;
+ if (enable_team_drives_) {
+ url = base_url_.Resolve(kDriveV2BetaFilesUrl);
+ url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
+ url = net::AppendOrReplaceQueryParameter(url, kIncludeTeamDriveItems,
+ "true");
+ } else {
+ url = base_url_.Resolve(kDriveV2FilesUrl);
+ }
// maxResults is 100 by default.
if (max_results != 100) {
url = net::AppendOrReplaceQueryParameter(
@@ -188,8 +221,15 @@ GURL DriveApiUrlGenerator::GetChangesListUrl(bool include_deleted,
int64_t start_change_id) const {
DCHECK_GE(start_change_id, 0);
- GURL url = base_url_.Resolve(kDriveV2ChangelistUrl);
-
+ GURL url;
+ if (enable_team_drives_) {
+ url = base_url_.Resolve(kDriveV2BetaChangelistUrl);
+ url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
+ url = net::AppendOrReplaceQueryParameter(url, kIncludeTeamDriveItems,
+ "true");
+ } else {
+ url = base_url_.Resolve(kDriveV2ChangelistUrl);
+ }
// includeDeleted is "true" by default.
if (!include_deleted)
url = net::AppendOrReplaceQueryParameter(url, "includeDeleted", "false");
« 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