Indicate that the client supports Team Drives in all related Drive API calls.

This change is needed for doing other operations than get and list to Team Drive files,
like writing files to or modifying files in Team Drives directories.

BUG=684277

Review-Url: https://codereview.chromium.org/2778923003
Cr-Original-Commit-Position: refs/heads/master@{#461033}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: ab6d23d22c9b28c9ca9b7568db2091db6b70c090
diff --git a/drive/drive_api_url_generator.cc b/drive/drive_api_url_generator.cc
index 6f91a1f..e796198 100644
--- a/drive/drive_api_url_generator.cc
+++ b/drive/drive_api_url_generator.cc
@@ -129,15 +129,20 @@
 GURL DriveApiUrlGenerator::GetFilesAuthorizeUrl(
     const std::string& file_id,
     const std::string& app_id) const {
-  return base_url_.Resolve(base::StringPrintf(kDriveV2FilesAuthorizeUrlFormat,
-                                              net::EscapePath(file_id).c_str(),
-                                              net::EscapePath(app_id).c_str()));
+  GURL url = base_url_.Resolve(base::StringPrintf(
+      kDriveV2FilesAuthorizeUrlFormat, net::EscapePath(file_id).c_str(),
+      net::EscapePath(app_id).c_str()));
+  if (enable_team_drives_)
+    url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
+  return url;
 }
 
 GURL DriveApiUrlGenerator::GetFilesInsertUrl(
     const std::string& visibility) const {
   GURL url =  base_url_.Resolve(kDriveV2FilesUrl);
 
+  if (enable_team_drives_)
+    url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
   if (!visibility.empty())
     url = net::AppendOrReplaceQueryParameter(url, "visibility", visibility);
 
@@ -150,6 +155,8 @@
   GURL url =
       base_url_.Resolve(kDriveV2FileUrlPrefix + net::EscapePath(file_id));
 
+  if (enable_team_drives_)
+    url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
   // setModifiedDate is "false" by default.
   if (set_modified_date)
     url = net::AppendOrReplaceQueryParameter(url, "setModifiedDate", "true");
@@ -167,6 +174,8 @@
   GURL url =  base_url_.Resolve(base::StringPrintf(
       kDriveV2FileCopyUrlFormat, net::EscapePath(file_id).c_str()));
 
+  if (enable_team_drives_)
+    url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
   if (!visibility.empty())
     url = net::AppendOrReplaceQueryParameter(url, "visibility", visibility);
 
@@ -198,13 +207,19 @@
 }
 
 GURL DriveApiUrlGenerator::GetFilesDeleteUrl(const std::string& file_id) const {
-  return base_url_.Resolve(base::StringPrintf(
+  GURL url = base_url_.Resolve(base::StringPrintf(
       kDriveV2FileDeleteUrlFormat, net::EscapePath(file_id).c_str()));
+  if (enable_team_drives_)
+    url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
+  return url;
 }
 
 GURL DriveApiUrlGenerator::GetFilesTrashUrl(const std::string& file_id) const {
-  return base_url_.Resolve(base::StringPrintf(
+  GURL url = base_url_.Resolve(base::StringPrintf(
       kDriveV2FileTrashUrlFormat, net::EscapePath(file_id).c_str()));
+  if (enable_team_drives_)
+    url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
+  return url;
 }
 
 GURL DriveApiUrlGenerator::GetChangesListUrl(bool include_deleted,
@@ -241,8 +256,11 @@
 
 GURL DriveApiUrlGenerator::GetChildrenInsertUrl(
     const std::string& file_id) const {
-  return base_url_.Resolve(base::StringPrintf(
+  GURL url = base_url_.Resolve(base::StringPrintf(
       kDriveV2ChildrenUrlFormat, net::EscapePath(file_id).c_str()));
+  if (enable_team_drives_)
+    url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
+  return url;
 }
 
 GURL DriveApiUrlGenerator::GetChildrenDeleteUrl(
@@ -258,6 +276,8 @@
   GURL url = AddResumableUploadParam(
       base_url_.Resolve(kDriveV2UploadNewFileUrl));
 
+  if (enable_team_drives_)
+    url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
   // setModifiedDate is "false" by default.
   if (set_modified_date)
     url = net::AppendOrReplaceQueryParameter(url, "setModifiedDate", "true");
@@ -273,6 +293,8 @@
       net::EscapePath(resource_id));
   url = AddResumableUploadParam(url);
 
+  if (enable_team_drives_)
+    url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
   // setModifiedDate is "false" by default.
   if (set_modified_date)
     url = net::AppendOrReplaceQueryParameter(url, "setModifiedDate", "true");
@@ -285,6 +307,8 @@
   GURL url = AddMultipartUploadParam(
       base_url_.Resolve(kDriveV2UploadNewFileUrl));
 
+  if (enable_team_drives_)
+    url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
   // setModifiedDate is "false" by default.
   if (set_modified_date)
     url = net::AppendOrReplaceQueryParameter(url, "setModifiedDate", "true");
@@ -300,6 +324,8 @@
       net::EscapePath(resource_id));
   url = AddMultipartUploadParam(url);
 
+  if (enable_team_drives_)
+    url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
   // setModifiedDate is "false" by default.
   if (set_modified_date)
     url = net::AppendOrReplaceQueryParameter(url, "setModifiedDate", "true");
@@ -309,15 +335,20 @@
 
 GURL DriveApiUrlGenerator::GenerateDownloadFileUrl(
     const std::string& resource_id) const {
-  return base_url_.Resolve(base::StringPrintf(
+  GURL url = base_url_.Resolve(base::StringPrintf(
       kDriveV2DownloadUrlFormat, net::EscapePath(resource_id).c_str()));
+  if (enable_team_drives_)
+    url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
+  return url;
 }
 
 GURL DriveApiUrlGenerator::GetPermissionsInsertUrl(
     const std::string& resource_id) const {
-  return base_url_.Resolve(
-      base::StringPrintf(kDriveV2PermissionsUrlFormat,
-                         net::EscapePath(resource_id).c_str()));
+  GURL url = base_url_.Resolve(base::StringPrintf(
+      kDriveV2PermissionsUrlFormat, net::EscapePath(resource_id).c_str()));
+  if (enable_team_drives_)
+    url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
+  return url;
 }
 
 GURL DriveApiUrlGenerator::GetThumbnailUrl(const std::string& resource_id,
@@ -331,7 +362,10 @@
 }
 
 GURL DriveApiUrlGenerator::GetBatchUploadUrl() const {
-  return base_url_.Resolve(kDriveV2BatchUploadUrl);
+  GURL url = base_url_.Resolve(kDriveV2BatchUploadUrl);
+  if (enable_team_drives_)
+    url = net::AppendOrReplaceQueryParameter(url, kSupportsTeamDrives, "true");
+  return url;
 }
 
 }  // namespace google_apis
diff --git a/drive/drive_api_url_generator_unittest.cc b/drive/drive_api_url_generator_unittest.cc
index 2460a6e..0bc8ce7 100644
--- a/drive/drive_api_url_generator_unittest.cc
+++ b/drive/drive_api_url_generator_unittest.cc
@@ -86,12 +86,22 @@
       "?embedOrigin=chrome-extension%3A%2F%2Ftest",
       url_generator_.GetFilesGetUrl("0ADK06pfg", true,
                                     GURL("chrome-extension://test")).spec());
+
+  EXPECT_EQ(
+      "https://www.example.com/drive/v2/files/0ADK06pfg?"
+      "supportsTeamDrives=true",
+      team_drives_url_generator_.GetFilesGetUrl("0ADK06pfg", false, GURL())
+          .spec());
 }
 
 TEST_F(DriveApiUrlGeneratorTest, GetFilesAuthorizeUrl) {
   EXPECT_EQ(
       "https://www.example.com/drive/v2internal/files/aa/authorize?appId=bb",
       url_generator_.GetFilesAuthorizeUrl("aa", "bb").spec());
+  EXPECT_EQ(
+      "https://www.example.com/drive/v2internal/files/aa/authorize?appId=bb&"
+      "supportsTeamDrives=true",
+      team_drives_url_generator_.GetFilesAuthorizeUrl("aa", "bb").spec());
 }
 
 TEST_F(DriveApiUrlGeneratorTest, GetFilesInsertUrl) {
@@ -101,6 +111,9 @@
             url_generator_.GetFilesInsertUrl("DEFAULT").spec());
   EXPECT_EQ("https://www.example.com/drive/v2/files?visibility=PRIVATE",
             url_generator_.GetFilesInsertUrl("PRIVATE").spec());
+
+  EXPECT_EQ("https://www.example.com/drive/v2/files?supportsTeamDrives=true",
+            team_drives_url_generator_.GetFilesInsertUrl("").spec());
 }
 
 TEST_F(DriveApiUrlGeneratorTest, GetFilePatchUrl) {
@@ -138,6 +151,12 @@
                            "file:file_id", kTestPatterns[i].set_modified_date,
                            kTestPatterns[i].update_viewed_date).spec());
   }
+
+  EXPECT_EQ(
+      "https://www.example.com/drive/v2/files/0ADK06pfg?"
+      "supportsTeamDrives=true",
+      team_drives_url_generator_.GetFilesPatchUrl("0ADK06pfg", false, true)
+          .spec());
 }
 
 TEST_F(DriveApiUrlGeneratorTest, GetFilesCopyUrl) {
@@ -154,6 +173,11 @@
   EXPECT_EQ("https://www.example.com/drive/v2/files/file%3Afile_id/copy"
             "?visibility=PRIVATE",
             url_generator_.GetFilesCopyUrl("file:file_id", "PRIVATE").spec());
+
+  EXPECT_EQ(
+      "https://www.example.com/drive/v2/files/0ADK06pfg/copy?"
+      "supportsTeamDrives=true",
+      team_drives_url_generator_.GetFilesCopyUrl("0ADK06pfg", "").spec());
 }
 
 TEST_F(DriveApiUrlGeneratorTest, GetFilesListUrl) {
@@ -208,6 +232,11 @@
             url_generator_.GetFilesDeleteUrl("0Bz0bd074").spec());
   EXPECT_EQ("https://www.example.com/drive/v2/files/file%3Afile_id",
             url_generator_.GetFilesDeleteUrl("file:file_id").spec());
+
+  EXPECT_EQ(
+      "https://www.example.com/drive/v2/files/0ADK06pfg?"
+      "supportsTeamDrives=true",
+      team_drives_url_generator_.GetFilesDeleteUrl("0ADK06pfg").spec());
 }
 
 TEST_F(DriveApiUrlGeneratorTest, GetFilesTrashUrl) {
@@ -218,6 +247,11 @@
             url_generator_.GetFilesTrashUrl("0Bz0bd074").spec());
   EXPECT_EQ("https://www.example.com/drive/v2/files/file%3Afile_id/trash",
             url_generator_.GetFilesTrashUrl("file:file_id").spec());
+
+  EXPECT_EQ(
+      "https://www.example.com/drive/v2/files/0ADK06pfg/trash?"
+      "supportsTeamDrives=true",
+      team_drives_url_generator_.GetFilesTrashUrl("0ADK06pfg").spec());
 }
 
 TEST_F(DriveApiUrlGeneratorTest, GetChangesListUrl) {
@@ -303,6 +337,11 @@
             url_generator_.GetChildrenInsertUrl("0Bz0bd074").spec());
   EXPECT_EQ("https://www.example.com/drive/v2/files/file%3Afolder_id/children",
             url_generator_.GetChildrenInsertUrl("file:folder_id").spec());
+
+  EXPECT_EQ(
+      "https://www.example.com/drive/v2/files/0ADK06pfg/children?"
+      "supportsTeamDrives=true",
+      team_drives_url_generator_.GetChildrenInsertUrl("0ADK06pfg").spec());
 }
 
 TEST_F(DriveApiUrlGeneratorTest, GetChildrenDeleteUrl) {
@@ -330,6 +369,12 @@
       "https://www.example.com/upload/drive/v2/files?uploadType=resumable&"
       "setModifiedDate=true",
       url_generator_.GetInitiateUploadNewFileUrl(kSetModifiedDate).spec());
+
+  EXPECT_EQ(
+      "https://www.example.com/upload/drive/v2/files?uploadType=resumable"
+      "&supportsTeamDrives=true",
+      team_drives_url_generator_.GetInitiateUploadNewFileUrl(!kSetModifiedDate)
+          .spec());
 }
 
 TEST_F(DriveApiUrlGeneratorTest, GetInitiateUploadExistingFileUrl) {
@@ -356,6 +401,13 @@
       "?uploadType=resumable&setModifiedDate=true",
       url_generator_.GetInitiateUploadExistingFileUrl("file:file_id",
                                                       kSetModifiedDate).spec());
+
+  EXPECT_EQ(
+      "https://www.example.com/upload/drive/v2/files/0ADK06pfg"
+      "?uploadType=resumable&supportsTeamDrives=true",
+      team_drives_url_generator_
+          .GetInitiateUploadExistingFileUrl("0ADK06pfg", !kSetModifiedDate)
+          .spec());
 }
 
 TEST_F(DriveApiUrlGeneratorTest, GetMultipartUploadNewFileUrl) {
@@ -368,6 +420,12 @@
       "https://www.example.com/upload/drive/v2/files?uploadType=multipart&"
       "setModifiedDate=true",
       url_generator_.GetMultipartUploadNewFileUrl(kSetModifiedDate).spec());
+
+  EXPECT_EQ(
+      "https://www.example.com/upload/drive/v2/files?uploadType=multipart"
+      "&supportsTeamDrives=true",
+      team_drives_url_generator_.GetMultipartUploadNewFileUrl(!kSetModifiedDate)
+          .spec());
 }
 
 TEST_F(DriveApiUrlGeneratorTest, GetMultipartUploadExistingFileUrl) {
@@ -394,6 +452,13 @@
       "?uploadType=multipart&setModifiedDate=true",
       url_generator_.GetMultipartUploadExistingFileUrl(
                          "file:file_id", kSetModifiedDate).spec());
+
+  EXPECT_EQ(
+      "https://www.example.com/upload/drive/v2/files/0ADK06pfg"
+      "?uploadType=multipart&supportsTeamDrives=true",
+      team_drives_url_generator_
+          .GetMultipartUploadExistingFileUrl("0ADK06pfg", !kSetModifiedDate)
+          .spec());
 }
 
 TEST_F(DriveApiUrlGeneratorTest, GenerateDownloadFileUrl) {
@@ -403,11 +468,20 @@
   EXPECT_EQ(
       "https://www.example.com/drive/v2/files/file%3AresourceId?alt=media",
       url_generator_.GenerateDownloadFileUrl("file:resourceId").spec());
+
+  EXPECT_EQ(
+      "https://www.example.com/drive/v2/files/resourceId?"
+      "alt=media&supportsTeamDrives=true",
+      team_drives_url_generator_.GenerateDownloadFileUrl("resourceId").spec());
 }
 
 TEST_F(DriveApiUrlGeneratorTest, GeneratePermissionsInsertUrl) {
   EXPECT_EQ("https://www.example.com/drive/v2/files/0ADK06pfg/permissions",
             url_generator_.GetPermissionsInsertUrl("0ADK06pfg").spec());
+  EXPECT_EQ(
+      "https://www.example.com/drive/v2/files/0ADK06pfg/permissions?"
+      "supportsTeamDrives=true",
+      team_drives_url_generator_.GetPermissionsInsertUrl("0ADK06pfg").spec());
 }
 
 TEST_F(DriveApiUrlGeneratorTest, GenerateThumbnailUrl) {
@@ -423,6 +497,8 @@
 TEST_F(DriveApiUrlGeneratorTest, BatchUploadUrl) {
   EXPECT_EQ("https://www.example.com/upload/drive",
             url_generator_.GetBatchUploadUrl().spec());
+  EXPECT_EQ("https://www.example.com/upload/drive?supportsTeamDrives=true",
+            team_drives_url_generator_.GetBatchUploadUrl().spec());
 }
 
 }  // namespace google_apis