| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "google_apis/drive/drive_api_url_generator.h" | 5 #include "google_apis/drive/drive_api_url_generator.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 10 #include "google_apis/google_api_keys.h" | 10 #include "google_apis/google_api_keys.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 const char kDriveV2ChildrenUrlFormat[] = "drive/v2/files/%s/children"; | 24 const char kDriveV2ChildrenUrlFormat[] = "drive/v2/files/%s/children"; |
| 25 const char kDriveV2ChildrenUrlForRemovalFormat[] = | 25 const char kDriveV2ChildrenUrlForRemovalFormat[] = |
| 26 "drive/v2/files/%s/children/%s"; | 26 "drive/v2/files/%s/children/%s"; |
| 27 const char kDriveV2FileCopyUrlFormat[] = "drive/v2/files/%s/copy"; | 27 const char kDriveV2FileCopyUrlFormat[] = "drive/v2/files/%s/copy"; |
| 28 const char kDriveV2FileDeleteUrlFormat[] = "drive/v2/files/%s"; | 28 const char kDriveV2FileDeleteUrlFormat[] = "drive/v2/files/%s"; |
| 29 const char kDriveV2FileTrashUrlFormat[] = "drive/v2/files/%s/trash"; | 29 const char kDriveV2FileTrashUrlFormat[] = "drive/v2/files/%s/trash"; |
| 30 const char kDriveV2UploadNewFileUrl[] = "upload/drive/v2/files"; | 30 const char kDriveV2UploadNewFileUrl[] = "upload/drive/v2/files"; |
| 31 const char kDriveV2UploadExistingFileUrlPrefix[] = "upload/drive/v2/files/"; | 31 const char kDriveV2UploadExistingFileUrlPrefix[] = "upload/drive/v2/files/"; |
| 32 const char kDriveV2BatchUploadUrl[] = "upload/drive"; | 32 const char kDriveV2BatchUploadUrl[] = "upload/drive"; |
| 33 const char kDriveV2PermissionsUrlFormat[] = "drive/v2/files/%s/permissions"; | 33 const char kDriveV2PermissionsUrlFormat[] = "drive/v2/files/%s/permissions"; |
| 34 const char kDriveV2DownloadUrlFormat[] = "host/%s"; | 34 const char kDriveV2DownloadUrlFormat[] = "drive/v2/files/%s?alt=media"; |
| 35 const char kDriveV2ThumbnailUrlFormat[] = "d/%s=w%d-h%d"; | 35 const char kDriveV2ThumbnailUrlFormat[] = "d/%s=w%d-h%d"; |
| 36 const char kDriveV2ThumbnailUrlWithCropFormat[] = "d/%s=w%d-h%d-c"; | 36 const char kDriveV2ThumbnailUrlWithCropFormat[] = "d/%s=w%d-h%d-c"; |
| 37 | 37 |
| 38 // apps.delete and file.authorize API is exposed through a special endpoint | 38 // apps.delete and file.authorize API is exposed through a special endpoint |
| 39 // v2internal that is accessible only by the official API key for Chrome. | 39 // v2internal that is accessible only by the official API key for Chrome. |
| 40 const char kDriveV2InternalAppsUrl[] = "drive/v2internal/apps"; | 40 const char kDriveV2InternalAppsUrl[] = "drive/v2internal/apps"; |
| 41 const char kDriveV2AppsDeleteUrlFormat[] = "drive/v2internal/apps/%s"; | 41 const char kDriveV2AppsDeleteUrlFormat[] = "drive/v2internal/apps/%s"; |
| 42 const char kDriveV2FilesAuthorizeUrlFormat[] = | 42 const char kDriveV2FilesAuthorizeUrlFormat[] = |
| 43 "drive/v2internal/files/%s/authorize?appId=%s"; | 43 "drive/v2internal/files/%s/authorize?appId=%s"; |
| 44 const char kDriveV2InternalFileUrlPrefix[] = "drive/v2internal/files/"; | 44 const char kDriveV2InternalFileUrlPrefix[] = "drive/v2internal/files/"; |
| 45 | 45 |
| 46 GURL AddResumableUploadParam(const GURL& url) { | 46 GURL AddResumableUploadParam(const GURL& url) { |
| 47 return net::AppendOrReplaceQueryParameter(url, "uploadType", "resumable"); | 47 return net::AppendOrReplaceQueryParameter(url, "uploadType", "resumable"); |
| 48 } | 48 } |
| 49 | 49 |
| 50 GURL AddMultipartUploadParam(const GURL& url) { | 50 GURL AddMultipartUploadParam(const GURL& url) { |
| 51 return net::AppendOrReplaceQueryParameter(url, "uploadType", "multipart"); | 51 return net::AppendOrReplaceQueryParameter(url, "uploadType", "multipart"); |
| 52 } | 52 } |
| 53 | 53 |
| 54 } // namespace | 54 } // namespace |
| 55 | 55 |
| 56 DriveApiUrlGenerator::DriveApiUrlGenerator(const GURL& base_url, | 56 DriveApiUrlGenerator::DriveApiUrlGenerator(const GURL& base_url, |
| 57 const GURL& base_download_url, | |
| 58 const GURL& base_thumbnail_url) | 57 const GURL& base_thumbnail_url) |
| 59 : base_url_(base_url), | 58 : base_url_(base_url), |
| 60 base_download_url_(base_download_url), | |
| 61 base_thumbnail_url_(base_thumbnail_url) { | 59 base_thumbnail_url_(base_thumbnail_url) { |
| 62 // Do nothing. | 60 // Do nothing. |
| 63 } | 61 } |
| 64 | 62 |
| 65 DriveApiUrlGenerator::~DriveApiUrlGenerator() { | 63 DriveApiUrlGenerator::~DriveApiUrlGenerator() { |
| 66 // Do nothing. | 64 // Do nothing. |
| 67 } | 65 } |
| 68 | 66 |
| 69 const char DriveApiUrlGenerator::kBaseUrlForProduction[] = | 67 const char DriveApiUrlGenerator::kBaseUrlForProduction[] = |
| 70 "https://www.googleapis.com"; | 68 "https://www.googleapis.com"; |
| 71 | 69 |
| 72 const char DriveApiUrlGenerator::kBaseDownloadUrlForProduction[] = | |
| 73 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_OFFICIAL_GOOGLE_API_KEYS) | |
| 74 "https://www.googledrive.com/p/"; | |
| 75 #else | |
| 76 "https://www.googledrive.com"; | |
| 77 #endif | |
| 78 | |
| 79 const char DriveApiUrlGenerator::kBaseThumbnailUrlForProduction[] = | 70 const char DriveApiUrlGenerator::kBaseThumbnailUrlForProduction[] = |
| 80 "https://lh3.googleusercontent.com"; | 71 "https://lh3.googleusercontent.com"; |
| 81 | 72 |
| 82 GURL DriveApiUrlGenerator::GetAboutGetUrl() const { | 73 GURL DriveApiUrlGenerator::GetAboutGetUrl() const { |
| 83 return base_url_.Resolve(kDriveV2AboutUrl); | 74 return base_url_.Resolve(kDriveV2AboutUrl); |
| 84 } | 75 } |
| 85 | 76 |
| 86 GURL DriveApiUrlGenerator::GetAppsListUrl(bool use_internal_endpoint) const { | 77 GURL DriveApiUrlGenerator::GetAppsListUrl(bool use_internal_endpoint) const { |
| 87 return base_url_.Resolve(use_internal_endpoint ? | 78 return base_url_.Resolve(use_internal_endpoint ? |
| 88 kDriveV2InternalAppsUrl : kDriveV2AppsUrl); | 79 kDriveV2InternalAppsUrl : kDriveV2AppsUrl); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 273 |
| 283 // setModifiedDate is "false" by default. | 274 // setModifiedDate is "false" by default. |
| 284 if (set_modified_date) | 275 if (set_modified_date) |
| 285 url = net::AppendOrReplaceQueryParameter(url, "setModifiedDate", "true"); | 276 url = net::AppendOrReplaceQueryParameter(url, "setModifiedDate", "true"); |
| 286 | 277 |
| 287 return url; | 278 return url; |
| 288 } | 279 } |
| 289 | 280 |
| 290 GURL DriveApiUrlGenerator::GenerateDownloadFileUrl( | 281 GURL DriveApiUrlGenerator::GenerateDownloadFileUrl( |
| 291 const std::string& resource_id) const { | 282 const std::string& resource_id) const { |
| 292 return base_download_url_.Resolve(base::StringPrintf( | 283 return base_url_.Resolve(base::StringPrintf( |
| 293 kDriveV2DownloadUrlFormat, net::EscapePath(resource_id).c_str())); | 284 kDriveV2DownloadUrlFormat, net::EscapePath(resource_id).c_str())); |
| 294 } | 285 } |
| 295 | 286 |
| 296 GURL DriveApiUrlGenerator::GetPermissionsInsertUrl( | 287 GURL DriveApiUrlGenerator::GetPermissionsInsertUrl( |
| 297 const std::string& resource_id) const { | 288 const std::string& resource_id) const { |
| 298 return base_url_.Resolve( | 289 return base_url_.Resolve( |
| 299 base::StringPrintf(kDriveV2PermissionsUrlFormat, | 290 base::StringPrintf(kDriveV2PermissionsUrlFormat, |
| 300 net::EscapePath(resource_id).c_str())); | 291 net::EscapePath(resource_id).c_str())); |
| 301 } | 292 } |
| 302 | 293 |
| 303 GURL DriveApiUrlGenerator::GetThumbnailUrl(const std::string& resource_id, | 294 GURL DriveApiUrlGenerator::GetThumbnailUrl(const std::string& resource_id, |
| 304 int width, | 295 int width, |
| 305 int height, | 296 int height, |
| 306 bool crop) const { | 297 bool crop) const { |
| 307 return base_thumbnail_url_.Resolve( | 298 return base_thumbnail_url_.Resolve( |
| 308 base::StringPrintf( | 299 base::StringPrintf( |
| 309 crop ? kDriveV2ThumbnailUrlWithCropFormat : kDriveV2ThumbnailUrlFormat, | 300 crop ? kDriveV2ThumbnailUrlWithCropFormat : kDriveV2ThumbnailUrlFormat, |
| 310 net::EscapePath(resource_id).c_str(), width, height)); | 301 net::EscapePath(resource_id).c_str(), width, height)); |
| 311 } | 302 } |
| 312 | 303 |
| 313 GURL DriveApiUrlGenerator::GetBatchUploadUrl() const { | 304 GURL DriveApiUrlGenerator::GetBatchUploadUrl() const { |
| 314 return base_url_.Resolve(kDriveV2BatchUploadUrl); | 305 return base_url_.Resolve(kDriveV2BatchUploadUrl); |
| 315 } | 306 } |
| 316 | 307 |
| 317 } // namespace google_apis | 308 } // namespace google_apis |
| OLD | NEW |