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

Unified Diff: google_apis/drive/drive_api_url_generator.cc

Issue 2693093002: Fetch file metadata of files under Team Drives. (Closed)
Patch Set: Remove redundant de-referencing. 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
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..171d56d1635017ada3b060ea8b78022b56c4cd77 100644
--- a/google_apis/drive/drive_api_url_generator.cc
+++ b/google_apis/drive/drive_api_url_generator.cc
@@ -4,6 +4,7 @@
#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"
@@ -16,11 +17,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 +41,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";
@@ -43,6 +52,18 @@ const char kDriveV2FilesAuthorizeUrlFormat[] =
"drive/v2internal/files/%s/authorize?appId=%s";
const char kDriveV2InternalFileUrlPrefix[] = "drive/v2internal/files/";
+namespace switches {
+
+// Enables or disables Team Drives integration.
+const char kEnableTeamDrives[] = "team-drives";
hashimoto 2017/02/20 03:26:30 Please put switch constants in a separate file. Us
yamaguchi 2017/02/20 08:21:29 Done.
+
+} // namespace switches
+
+bool IsTeamDrivesEnabled() {
+ return base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableTeamDrives);
+}
+
GURL AddResumableUploadParam(const GURL& url) {
return net::AppendOrReplaceQueryParameter(url, "uploadType", "resumable");
}
@@ -53,10 +74,18 @@ GURL AddMultipartUploadParam(const GURL& url) {
} // namespace
+DriveApiUrlGenerator::DriveApiUrlGenerator(const DriveApiUrlGenerator& src)
+ : base_url_(src.base_url_),
+ base_thumbnail_url_(src.base_thumbnail_url_),
+ enable_team_drives_(src.enable_team_drives_) {
+ // Do nothing.
+}
+
DriveApiUrlGenerator::DriveApiUrlGenerator(const GURL& base_url,
const GURL& base_thumbnail_url)
: base_url_(base_url),
- base_thumbnail_url_(base_thumbnail_url) {
+ base_thumbnail_url_(base_thumbnail_url),
+ enable_team_drives_(IsTeamDrivesEnabled()) {
// Do nothing.
}
@@ -87,9 +116,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;
hashimoto 2017/02/20 03:26:29 Please don't leave this value uninitialized.
yamaguchi 2017/02/20 08:21:29 Is this what you meant? (or did you mean make this
hashimoto 2017/02/21 10:19:10 I meant just initializing with nullptr.
yamaguchi 2017/02/22 02:07:52 Done.
+ 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
@@ -157,6 +196,12 @@ GURL DriveApiUrlGenerator::GetFilesListUrl(int max_results,
const std::string& q) const {
GURL url = base_url_.Resolve(kDriveV2FilesUrl);
hashimoto 2017/02/20 03:26:29 Please be consistent with the code below which put
yamaguchi 2017/02/20 08:21:29 Done.
+ if (enable_team_drives_) {
+ url = base_url_.Resolve(kDriveV2BetaFilesUrl);
+ url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
+ url = net::AppendOrReplaceQueryParameter(url, kIncludeTeamDriveItems,
+ "true");
+ }
// maxResults is 100 by default.
if (max_results != 100) {
url = net::AppendOrReplaceQueryParameter(
@@ -188,8 +233,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");

Powered by Google App Engine
This is Rietveld 408576698