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 "chrome/browser/google_apis/drive_api_url_generator.h" | 5 #include "chrome/browser/google_apis/drive_api_url_generator.h" |
6 | 6 |
7 #include "base/string_number_conversions.h" | 7 #include "base/string_number_conversions.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "net/base/escape.h" | 9 #include "net/base/escape.h" |
10 #include "net/base/url_util.h" | 10 #include "net/base/url_util.h" |
11 | 11 |
12 namespace google_apis { | 12 namespace google_apis { |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 // Hard coded URLs for communication with a google drive server. | 16 // Hard coded URLs for communication with a google drive server. |
17 const char kDriveV2AboutUrl[] = "/drive/v2/about"; | 17 const char kDriveV2AboutUrl[] = "/drive/v2/about"; |
18 const char kDriveV2ApplistUrl[] = "/drive/v2/apps"; | 18 const char kDriveV2ApplistUrl[] = "/drive/v2/apps"; |
19 const char kDriveV2ChangelistUrl[] = "/drive/v2/changes"; | 19 const char kDriveV2ChangelistUrl[] = "/drive/v2/changes"; |
20 const char kDriveV2FilelistUrl[] = "/drive/v2/files"; | 20 const char kDriveV2FilelistUrl[] = "/drive/v2/files"; |
21 const char kDriveV2FileUrlPrefix[] = "/drive/v2/files/"; | 21 const char kDriveV2FileUrlPrefix[] = "/drive/v2/files/"; |
22 const char kDriveV2ChildrenUrlFormat[] = "/drive/v2/files/%s/children"; | 22 const char kDriveV2ChildrenUrlFormat[] = "/drive/v2/files/%s/children"; |
23 const char kDriveV2ChildrenUrlForRemovalFormat[] = | 23 const char kDriveV2ChildrenUrlForRemovalFormat[] = |
24 "/drive/v2/files/%s/children/%s"; | 24 "/drive/v2/files/%s/children/%s"; |
25 const char kDriveV2FileTrashUrlFormat[] = "/drive/v2/files/%s/trash"; | 25 const char kDriveV2FileTrashUrlFormat[] = "/drive/v2/files/%s/trash"; |
| 26 const char kDriveV2InitiateUploadNewFileUrl[] = "/upload/drive/v2/files"; |
| 27 const char kDriveV2InitiateUploadExistingFileUrlPrefix[] = |
| 28 "/upload/drive/v2/files/"; |
| 29 |
| 30 GURL AddResumableUploadParam(const GURL& url) { |
| 31 return net::AppendOrReplaceQueryParameter(url, "uploadType", "resumable"); |
| 32 } |
26 | 33 |
27 } // namespace | 34 } // namespace |
28 | 35 |
29 DriveApiUrlGenerator::DriveApiUrlGenerator(const GURL& base_url) | 36 DriveApiUrlGenerator::DriveApiUrlGenerator(const GURL& base_url) |
30 : base_url_(base_url) { | 37 : base_url_(base_url) { |
31 // Do nothing. | 38 // Do nothing. |
32 } | 39 } |
33 | 40 |
34 DriveApiUrlGenerator::~DriveApiUrlGenerator() { | 41 DriveApiUrlGenerator::~DriveApiUrlGenerator() { |
35 // Do nothing. | 42 // Do nothing. |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 96 } |
90 | 97 |
91 GURL DriveApiUrlGenerator::GetChildrenUrlForRemoval( | 98 GURL DriveApiUrlGenerator::GetChildrenUrlForRemoval( |
92 const std::string& folder_id, const std::string& child_id) const { | 99 const std::string& folder_id, const std::string& child_id) const { |
93 return base_url_.Resolve( | 100 return base_url_.Resolve( |
94 base::StringPrintf(kDriveV2ChildrenUrlForRemovalFormat, | 101 base::StringPrintf(kDriveV2ChildrenUrlForRemovalFormat, |
95 net::EscapePath(folder_id).c_str(), | 102 net::EscapePath(folder_id).c_str(), |
96 net::EscapePath(child_id).c_str())); | 103 net::EscapePath(child_id).c_str())); |
97 } | 104 } |
98 | 105 |
| 106 GURL DriveApiUrlGenerator::GetInitiateUploadNewFileUrl() const { |
| 107 return AddResumableUploadParam( |
| 108 base_url_.Resolve(kDriveV2InitiateUploadNewFileUrl)); |
| 109 } |
| 110 |
| 111 GURL DriveApiUrlGenerator::GetInitiateUploadExistingFileUrl( |
| 112 const std::string& resource_id) const { |
| 113 const GURL& url = base_url_.Resolve( |
| 114 kDriveV2InitiateUploadExistingFileUrlPrefix + |
| 115 net::EscapePath(resource_id)); |
| 116 return AddResumableUploadParam(url); |
| 117 } |
| 118 |
99 } // namespace google_apis | 119 } // namespace google_apis |
OLD | NEW |