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 "chrome/common/net/url_util.h" | 9 #include "chrome/common/net/url_util.h" |
10 | 10 |
11 namespace google_apis { | 11 namespace google_apis { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // Hard coded URLs for communication with a google drive server. | 15 // Hard coded URLs for communication with a google drive server. |
16 const char kDriveV2AboutUrl[] = "https://www.googleapis.com/drive/v2/about"; | 16 const char kDriveV2AboutUrl[] = "/drive/v2/about"; |
17 const char kDriveV2ApplistUrl[] = "https://www.googleapis.com/drive/v2/apps"; | 17 const char kDriveV2ApplistUrl[] = "/drive/v2/apps"; |
18 const char kDriveV2ChangelistUrl[] = | 18 const char kDriveV2ChangelistUrl[] = "/drive/v2/changes"; |
19 "https://www.googleapis.com/drive/v2/changes"; | 19 const char kDriveV2FilelistUrl[] = "/drive/v2/files"; |
20 | 20 const char kDriveV2FileUrlFormat[] = "/drive/v2/files/%s"; |
21 const char kDriveV2FilelistUrl[] = "https://www.googleapis.com/drive/v2/files"; | |
22 const char kDriveV2FileUrlFormat[] = | |
23 "https://www.googleapis.com/drive/v2/files/%s"; | |
24 | 21 |
25 } // namespace | 22 } // namespace |
26 | 23 |
27 DriveApiUrlGenerator::DriveApiUrlGenerator() { | 24 DriveApiUrlGenerator::DriveApiUrlGenerator(const GURL& base_url) |
| 25 : base_url_(base_url) { |
28 // Do nothing. | 26 // Do nothing. |
29 } | 27 } |
30 | 28 |
31 DriveApiUrlGenerator::~DriveApiUrlGenerator() { | 29 DriveApiUrlGenerator::~DriveApiUrlGenerator() { |
32 // Do nothing. | 30 // Do nothing. |
33 } | 31 } |
34 | 32 |
| 33 const char DriveApiUrlGenerator::kBaseUrlForProduction[] = |
| 34 "https://www.googleapis.com"; |
| 35 |
35 GURL DriveApiUrlGenerator::GetAboutUrl() const { | 36 GURL DriveApiUrlGenerator::GetAboutUrl() const { |
36 return GURL(kDriveV2AboutUrl); | 37 return base_url_.Resolve(kDriveV2AboutUrl); |
37 } | 38 } |
38 | 39 |
39 GURL DriveApiUrlGenerator::GetApplistUrl() const { | 40 GURL DriveApiUrlGenerator::GetApplistUrl() const { |
40 return GURL(kDriveV2ApplistUrl); | 41 return base_url_.Resolve(kDriveV2ApplistUrl); |
41 } | 42 } |
42 | 43 |
43 GURL DriveApiUrlGenerator::GetChangelistUrl( | 44 GURL DriveApiUrlGenerator::GetChangelistUrl( |
44 const GURL& override_url, int64 start_changestamp) const { | 45 const GURL& override_url, int64 start_changestamp) const { |
45 // Use override_url if not empty, | 46 // Use override_url if not empty, |
46 // otherwise use the default url (kDriveV2Changelisturl). | 47 // otherwise use the default url (kDriveV2Changelisturl based on base_url_). |
47 const GURL& url = | 48 const GURL& url = override_url.is_empty() ? |
48 override_url.is_empty() ? GURL(kDriveV2ChangelistUrl) : override_url; | 49 base_url_.Resolve(kDriveV2ChangelistUrl) : |
| 50 override_url; |
49 return start_changestamp ? | 51 return start_changestamp ? |
50 chrome_common_net::AppendOrReplaceQueryParameter( | 52 chrome_common_net::AppendOrReplaceQueryParameter( |
51 url, "startChangeId", base::Int64ToString(start_changestamp)) : | 53 url, "startChangeId", base::Int64ToString(start_changestamp)) : |
52 url; | 54 url; |
53 } | 55 } |
54 | 56 |
55 GURL DriveApiUrlGenerator::GetFilelistUrl( | 57 GURL DriveApiUrlGenerator::GetFilelistUrl( |
56 const GURL& override_url, const std::string& search_string) const { | 58 const GURL& override_url, const std::string& search_string) const { |
57 // Use override_url if not empty, | 59 // Use override_url if not empty, |
58 // otherwise use the default url (kDriveV2FilelistUrl). | 60 // otherwise use the default url (kDriveV2FilelistUrl based on base_url_). |
59 const GURL& url = | 61 const GURL& url = override_url.is_empty() ? |
60 override_url.is_empty() ? GURL(kDriveV2FilelistUrl) : override_url; | 62 base_url_.Resolve(kDriveV2FilelistUrl) : |
61 | 63 override_url; |
62 return search_string.empty() ? | 64 return search_string.empty() ? |
63 url : | 65 url : |
64 chrome_common_net::AppendOrReplaceQueryParameter( | 66 chrome_common_net::AppendOrReplaceQueryParameter( |
65 url, "q", search_string); | 67 url, "q", search_string); |
66 } | 68 } |
67 | 69 |
68 GURL DriveApiUrlGenerator::GetFileUrl(const std::string& file_id) const { | 70 GURL DriveApiUrlGenerator::GetFileUrl(const std::string& file_id) const { |
69 return GURL(base::StringPrintf(kDriveV2FileUrlFormat, file_id.c_str())); | 71 return base_url_.Resolve( |
| 72 base::StringPrintf(kDriveV2FileUrlFormat, file_id.c_str())); |
70 } | 73 } |
71 | 74 |
72 } // namespace google_apis | 75 } // namespace google_apis |
OLD | NEW |