Chromium Code Reviews| 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..f226d5c3e472cc0f22df6a9f96e28b19f2fb00dd 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,10 +63,18 @@ GURL AddMultipartUploadParam(const GURL& url) { |
| } // namespace |
| +DriveApiUrlGenerator::DriveApiUrlGenerator(const DriveApiUrlGenerator& src) |
|
hashimoto
2017/02/22 03:52:03
Can't you just use "= default"?
yamaguchi
2017/02/22 06:41:22
Done.
|
| + : 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 +105,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 +183,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 +223,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"); |