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/gdata_wapi_url_util.h" | 5 #include "chrome/browser/google_apis/gdata_wapi_url_util.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.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 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
11 #include "net/base/escape.h" | 11 #include "net/base/escape.h" |
12 | 12 |
13 namespace google_apis { | 13 namespace google_apis { |
14 namespace gdata_wapi_url_util { | |
15 | |
16 namespace { | 14 namespace { |
17 | 15 |
18 // URL requesting documents list that belong to the authenticated user only | 16 // URL requesting documents list that belong to the authenticated user only |
19 // (handled with '/-/mine' part). | 17 // (handled with '/-/mine' part). |
20 const char kGetDocumentListURLForAllDocuments[] = | 18 const char kGetDocumentListURLForAllDocuments[] = |
21 "https://docs.google.com/feeds/default/private/full/-/mine"; | 19 "/feeds/default/private/full/-/mine"; |
22 | 20 |
23 // URL requesting documents list in a particular directory specified by "%s" | 21 // URL requesting documents list in a particular directory specified by "%s" |
24 // that belong to the authenticated user only (handled with '/-/mine' part). | 22 // that belong to the authenticated user only (handled with '/-/mine' part). |
25 const char kGetDocumentListURLForDirectoryFormat[] = | 23 const char kGetDocumentListURLForDirectoryFormat[] = |
26 "https://docs.google.com/feeds/default/private/full/%s/contents/-/mine"; | 24 "/feeds/default/private/full/%s/contents/-/mine"; |
27 | 25 |
28 // URL requesting single document entry whose resource id is specified by "%s". | 26 // URL requesting single document entry whose resource id is specified by "%s". |
29 const char kGetDocumentEntryURLFormat[] = | 27 const char kGetDocumentEntryURLFormat[] = "/feeds/default/private/full/%s"; |
30 "https://docs.google.com/feeds/default/private/full/%s"; | |
31 | 28 |
32 // Root document list url. | 29 // Root document list url. |
33 const char kDocumentListRootURL[] = | 30 const char kDocumentListRootURL[] = "/feeds/default/private/full"; |
34 "https://docs.google.com/feeds/default/private/full"; | |
35 | 31 |
36 // Metadata feed with things like user quota. | 32 // Metadata feed with things like user quota. |
37 const char kAccountMetadataURL[] = | 33 const char kAccountMetadataURL[] = "/feeds/metadata/default"; |
38 "https://docs.google.com/feeds/metadata/default"; | |
39 | 34 |
40 #ifndef NDEBUG | 35 #ifndef NDEBUG |
41 // Use smaller 'page' size while debugging to ensure we hit feed reload | 36 // Use smaller 'page' size while debugging to ensure we hit feed reload |
42 // almost always. Be careful not to use something too small on account that | 37 // almost always. Be careful not to use something too small on account that |
43 // have many items because server side 503 error might kick in. | 38 // have many items because server side 503 error might kick in. |
44 const int kMaxDocumentsPerFeed = 500; | 39 const int kMaxDocumentsPerFeed = 500; |
45 const int kMaxDocumentsPerSearchFeed = 50; | 40 const int kMaxDocumentsPerSearchFeed = 50; |
46 #else | 41 #else |
47 const int kMaxDocumentsPerFeed = 500; | 42 const int kMaxDocumentsPerFeed = 500; |
48 const int kMaxDocumentsPerSearchFeed = 50; | 43 const int kMaxDocumentsPerSearchFeed = 50; |
49 #endif | 44 #endif |
50 | 45 |
51 // URL requesting documents list that shared to the authenticated user only | 46 // URL requesting documents list that shared to the authenticated user only |
52 const char kGetDocumentListURLForSharedWithMe[] = | 47 const char kGetDocumentListURLForSharedWithMe[] = |
53 "https://docs.google.com/feeds/default/private/full/-/shared-with-me"; | 48 "/feeds/default/private/full/-/shared-with-me"; |
54 | 49 |
55 // URL requesting documents list of changes to documents collections. | 50 // URL requesting documents list of changes to documents collections. |
56 const char kGetChangesListURL[] = | 51 const char kGetChangesListURL[] = "/feeds/default/private/changes"; |
57 "https://docs.google.com/feeds/default/private/changes"; | |
58 | 52 |
59 } // namespace | 53 } // namespace |
60 | 54 |
| 55 namespace gdata_wapi_url_util { |
| 56 |
| 57 const char kBaseUrlForProduction[] = "https://docs.google.com/"; |
| 58 const char kBaseUrlForTesting[] = "http://127.0.0.1/"; |
| 59 |
61 GURL AddStandardUrlParams(const GURL& url) { | 60 GURL AddStandardUrlParams(const GURL& url) { |
62 GURL result = | 61 GURL result = |
63 chrome_common_net::AppendOrReplaceQueryParameter(url, "v", "3"); | 62 chrome_common_net::AppendOrReplaceQueryParameter(url, "v", "3"); |
64 result = | 63 result = |
65 chrome_common_net::AppendOrReplaceQueryParameter(result, "alt", "json"); | 64 chrome_common_net::AppendOrReplaceQueryParameter(result, "alt", "json"); |
66 return result; | 65 return result; |
67 } | 66 } |
68 | 67 |
69 GURL AddMetadataUrlParams(const GURL& url) { | 68 GURL AddMetadataUrlParams(const GURL& url) { |
70 GURL result = AddStandardUrlParams(url); | 69 GURL result = AddStandardUrlParams(url); |
(...skipping 25 matching lines...) Expand all Loading... |
96 base::StringPrintf("%d", changestamp)); | 95 base::StringPrintf("%d", changestamp)); |
97 } | 96 } |
98 | 97 |
99 if (!search_string.empty()) { | 98 if (!search_string.empty()) { |
100 result = chrome_common_net::AppendOrReplaceQueryParameter( | 99 result = chrome_common_net::AppendOrReplaceQueryParameter( |
101 result, "q", search_string); | 100 result, "q", search_string); |
102 } | 101 } |
103 return result; | 102 return result; |
104 } | 103 } |
105 | 104 |
106 GURL GenerateDocumentListUrl( | 105 } // namespace gdata_wapi_url_util |
| 106 |
| 107 |
| 108 // TODO(satorux): Move the following code to a separate file |
| 109 // gdata_wapi_url_generator.cc |
| 110 |
| 111 GDataWapiUrlGenerator::GDataWapiUrlGenerator(const GURL& base_url) |
| 112 : base_url_(GURL(base_url)) { |
| 113 } |
| 114 |
| 115 GDataWapiUrlGenerator::~GDataWapiUrlGenerator() { |
| 116 } |
| 117 |
| 118 GURL GDataWapiUrlGenerator::GenerateDocumentListUrl( |
107 const GURL& override_url, | 119 const GURL& override_url, |
108 int start_changestamp, | 120 int start_changestamp, |
109 const std::string& search_string, | 121 const std::string& search_string, |
110 bool shared_with_me, | 122 bool shared_with_me, |
111 const std::string& directory_resource_id) { | 123 const std::string& directory_resource_id) const { |
112 DCHECK_LE(0, start_changestamp); | 124 DCHECK_LE(0, start_changestamp); |
113 | 125 |
114 int max_docs = search_string.empty() ? kMaxDocumentsPerFeed : | 126 int max_docs = search_string.empty() ? kMaxDocumentsPerFeed : |
115 kMaxDocumentsPerSearchFeed; | 127 kMaxDocumentsPerSearchFeed; |
116 GURL url; | 128 GURL url; |
117 if (!override_url.is_empty()) { | 129 if (!override_url.is_empty()) { |
118 url = override_url; | 130 url = override_url; |
119 } else if (shared_with_me) { | 131 } else if (shared_with_me) { |
120 url = GURL(kGetDocumentListURLForSharedWithMe); | 132 url = base_url_.Resolve(kGetDocumentListURLForSharedWithMe); |
121 } else if (start_changestamp > 0) { | 133 } else if (start_changestamp > 0) { |
122 // The start changestamp shouldn't be used for a search. | 134 // The start changestamp shouldn't be used for a search. |
123 DCHECK(search_string.empty()); | 135 DCHECK(search_string.empty()); |
124 url = GURL(kGetChangesListURL); | 136 url = base_url_.Resolve(kGetChangesListURL); |
125 } else if (!directory_resource_id.empty()) { | 137 } else if (!directory_resource_id.empty()) { |
126 url = GURL(base::StringPrintf(kGetDocumentListURLForDirectoryFormat, | 138 url = base_url_.Resolve( |
127 net::EscapePath( | 139 base::StringPrintf(kGetDocumentListURLForDirectoryFormat, |
128 directory_resource_id).c_str())); | 140 net::EscapePath( |
| 141 directory_resource_id).c_str())); |
129 } else { | 142 } else { |
130 url = GURL(kGetDocumentListURLForAllDocuments); | 143 url = base_url_.Resolve(kGetDocumentListURLForAllDocuments); |
131 } | 144 } |
132 return AddFeedUrlParams(url, max_docs, start_changestamp, search_string); | 145 return gdata_wapi_url_util::AddFeedUrlParams( |
| 146 url, max_docs, start_changestamp, search_string); |
133 } | 147 } |
134 | 148 |
135 GURL GenerateDocumentEntryUrl(const std::string& resource_id) { | 149 GURL GDataWapiUrlGenerator::GenerateDocumentEntryUrl( |
136 GURL result = GURL(base::StringPrintf(kGetDocumentEntryURLFormat, | 150 const std::string& resource_id) const { |
137 net::EscapePath(resource_id).c_str())); | 151 GURL result = base_url_.Resolve( |
138 return AddStandardUrlParams(result); | 152 base::StringPrintf(kGetDocumentEntryURLFormat, |
| 153 net::EscapePath(resource_id).c_str())); |
| 154 return gdata_wapi_url_util::AddStandardUrlParams(result); |
139 } | 155 } |
140 | 156 |
141 GURL GenerateDocumentListRootUrl() { | 157 GURL GDataWapiUrlGenerator::GenerateDocumentListRootUrl() const { |
142 return AddStandardUrlParams(GURL(kDocumentListRootURL)); | 158 return gdata_wapi_url_util::AddStandardUrlParams( |
| 159 base_url_.Resolve(kDocumentListRootURL)); |
143 } | 160 } |
144 | 161 |
145 GURL GenerateAccountMetadataUrl() { | 162 GURL GDataWapiUrlGenerator::GenerateAccountMetadataUrl() const { |
146 return AddMetadataUrlParams(GURL(kAccountMetadataURL)); | 163 return gdata_wapi_url_util::AddMetadataUrlParams( |
| 164 base_url_.Resolve(kAccountMetadataURL)); |
147 } | 165 } |
148 | 166 |
149 } // namespace gdata_wapi_url_util | |
150 } // namespace google_apis | 167 } // namespace google_apis |
OLD | NEW |