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 "net/base/escape.h" | 10 #include "net/base/escape.h" |
11 #include "net/base/url_util.h" | 11 #include "net/base/url_util.h" |
12 | 12 |
13 namespace google_apis { | 13 namespace google_apis { |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 // Hard coded URLs for communication with a google drive server. | 17 // Hard coded URLs for communication with a google drive server. |
18 const char kDriveV2AboutUrl[] = "/drive/v2/about"; | 18 const char kDriveV2AboutUrl[] = "/drive/v2/about"; |
19 const char kDriveV2AppsUrl[] = "/drive/v2/apps"; | 19 const char kDriveV2AppsUrl[] = "/drive/v2/apps"; |
20 // apps.delete API is exposed through a special endpoint v2internal that | |
21 // is accessible only by the official API key for Chrome. | |
22 const char kDriveV2AppsDeleteUrlFormat[] = "/drive/v2internal/apps/%s"; | |
23 const char kDriveV2ChangelistUrl[] = "/drive/v2/changes"; | 20 const char kDriveV2ChangelistUrl[] = "/drive/v2/changes"; |
24 const char kDriveV2FilesUrl[] = "/drive/v2/files"; | 21 const char kDriveV2FilesUrl[] = "/drive/v2/files"; |
25 const char kDriveV2FileUrlPrefix[] = "/drive/v2/files/"; | 22 const char kDriveV2FileUrlPrefix[] = "/drive/v2/files/"; |
26 const char kDriveV2ChildrenUrlFormat[] = "/drive/v2/files/%s/children"; | 23 const char kDriveV2ChildrenUrlFormat[] = "/drive/v2/files/%s/children"; |
27 const char kDriveV2ChildrenUrlForRemovalFormat[] = | 24 const char kDriveV2ChildrenUrlForRemovalFormat[] = |
28 "/drive/v2/files/%s/children/%s"; | 25 "/drive/v2/files/%s/children/%s"; |
29 const char kDriveV2FileCopyUrlFormat[] = "/drive/v2/files/%s/copy"; | 26 const char kDriveV2FileCopyUrlFormat[] = "/drive/v2/files/%s/copy"; |
30 const char kDriveV2FileDeleteUrlFormat[] = "/drive/v2/files/%s"; | 27 const char kDriveV2FileDeleteUrlFormat[] = "/drive/v2/files/%s"; |
31 const char kDriveV2FileTrashUrlFormat[] = "/drive/v2/files/%s/trash"; | 28 const char kDriveV2FileTrashUrlFormat[] = "/drive/v2/files/%s/trash"; |
32 const char kDriveV2InitiateUploadNewFileUrl[] = "/upload/drive/v2/files"; | 29 const char kDriveV2InitiateUploadNewFileUrl[] = "/upload/drive/v2/files"; |
33 const char kDriveV2InitiateUploadExistingFileUrlPrefix[] = | 30 const char kDriveV2InitiateUploadExistingFileUrlPrefix[] = |
34 "/upload/drive/v2/files/"; | 31 "/upload/drive/v2/files/"; |
35 | 32 |
| 33 // apps.delete and file.authorize API is exposed through a special endpoint |
| 34 // v2internal that is accessible only by the official API key for Chrome. |
| 35 const char kDriveV2AppsDeleteUrlFormat[] = "/drive/v2internal/apps/%s"; |
| 36 const char kDriveV2FilesAuthorizeUrlFormat[] = |
| 37 "/drive/v2internal/files/%s/authorize?appId=%s"; |
| 38 |
36 GURL AddResumableUploadParam(const GURL& url) { | 39 GURL AddResumableUploadParam(const GURL& url) { |
37 return net::AppendOrReplaceQueryParameter(url, "uploadType", "resumable"); | 40 return net::AppendOrReplaceQueryParameter(url, "uploadType", "resumable"); |
38 } | 41 } |
39 | 42 |
40 } // namespace | 43 } // namespace |
41 | 44 |
42 DriveApiUrlGenerator::DriveApiUrlGenerator(const GURL& base_url, | 45 DriveApiUrlGenerator::DriveApiUrlGenerator(const GURL& base_url, |
43 const GURL& base_download_url) | 46 const GURL& base_download_url) |
44 : base_url_(base_url), | 47 : base_url_(base_url), |
45 base_download_url_(base_download_url) { | 48 base_download_url_(base_download_url) { |
(...skipping 19 matching lines...) Expand all Loading... |
65 | 68 |
66 GURL DriveApiUrlGenerator::GetAppsDeleteUrl(const std::string& app_id) const { | 69 GURL DriveApiUrlGenerator::GetAppsDeleteUrl(const std::string& app_id) const { |
67 return base_url_.Resolve(base::StringPrintf( | 70 return base_url_.Resolve(base::StringPrintf( |
68 kDriveV2AppsDeleteUrlFormat, net::EscapePath(app_id).c_str())); | 71 kDriveV2AppsDeleteUrlFormat, net::EscapePath(app_id).c_str())); |
69 } | 72 } |
70 | 73 |
71 GURL DriveApiUrlGenerator::GetFilesGetUrl(const std::string& file_id) const { | 74 GURL DriveApiUrlGenerator::GetFilesGetUrl(const std::string& file_id) const { |
72 return base_url_.Resolve(kDriveV2FileUrlPrefix + net::EscapePath(file_id)); | 75 return base_url_.Resolve(kDriveV2FileUrlPrefix + net::EscapePath(file_id)); |
73 } | 76 } |
74 | 77 |
| 78 GURL DriveApiUrlGenerator::GetFilesAuthorizeUrl( |
| 79 const std::string& file_id, |
| 80 const std::string& app_id) const { |
| 81 return base_url_.Resolve(base::StringPrintf(kDriveV2FilesAuthorizeUrlFormat, |
| 82 net::EscapePath(file_id).c_str(), |
| 83 net::EscapePath(app_id).c_str())); |
| 84 } |
| 85 |
75 GURL DriveApiUrlGenerator::GetFilesInsertUrl() const { | 86 GURL DriveApiUrlGenerator::GetFilesInsertUrl() const { |
76 return base_url_.Resolve(kDriveV2FilesUrl); | 87 return base_url_.Resolve(kDriveV2FilesUrl); |
77 } | 88 } |
78 | 89 |
79 GURL DriveApiUrlGenerator::GetFilesPatchUrl(const std::string& file_id, | 90 GURL DriveApiUrlGenerator::GetFilesPatchUrl(const std::string& file_id, |
80 bool set_modified_date, | 91 bool set_modified_date, |
81 bool update_viewed_date) const { | 92 bool update_viewed_date) const { |
82 GURL url = | 93 GURL url = |
83 base_url_.Resolve(kDriveV2FileUrlPrefix + net::EscapePath(file_id)); | 94 base_url_.Resolve(kDriveV2FileUrlPrefix + net::EscapePath(file_id)); |
84 | 95 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 net::EscapePath(resource_id)); | 193 net::EscapePath(resource_id)); |
183 return AddResumableUploadParam(url); | 194 return AddResumableUploadParam(url); |
184 } | 195 } |
185 | 196 |
186 GURL DriveApiUrlGenerator::GenerateDownloadFileUrl( | 197 GURL DriveApiUrlGenerator::GenerateDownloadFileUrl( |
187 const std::string& resource_id) const { | 198 const std::string& resource_id) const { |
188 return base_download_url_.Resolve(net::EscapePath(resource_id)); | 199 return base_download_url_.Resolve(net::EscapePath(resource_id)); |
189 } | 200 } |
190 | 201 |
191 } // namespace google_apis | 202 } // namespace google_apis |
OLD | NEW |