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..3f8a56c20ccdb5e70f2a01e2891e048d15085260 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"; |
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.
|
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,19 @@ 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"; |
+ |
+} // namespace switches |
+ |
+bool IsTeamDrivesEnabled() { |
+ const base::CommandLine& command_line = |
+ *base::CommandLine::ForCurrentProcess(); |
+ return command_line.HasSwitch(switches::kEnableTeamDrives); |
+} |
+ |
GURL AddResumableUploadParam(const GURL& url) { |
return net::AppendOrReplaceQueryParameter(url, "uploadType", "resumable"); |
} |
@@ -53,10 +75,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 +117,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; |
+ 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 +197,12 @@ GURL DriveApiUrlGenerator::GetFilesListUrl(int max_results, |
const std::string& q) const { |
GURL url = base_url_.Resolve(kDriveV2FilesUrl); |
+ 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 +234,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"); |