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/stringprintf.h" | 8 #include "base/stringprintf.h" |
8 #include "chrome/common/net/url_util.h" | 9 #include "chrome/common/net/url_util.h" |
9 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
10 #include "net/base/escape.h" | 11 #include "net/base/escape.h" |
11 | 12 |
12 namespace google_apis { | 13 namespace google_apis { |
13 namespace gdata_wapi_url_util { | 14 namespace gdata_wapi_url_util { |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
(...skipping 19 matching lines...) Expand all Loading... | |
36 #endif | 37 #endif |
37 | 38 |
38 // URL requesting documents list that shared to the authenticated user only | 39 // URL requesting documents list that shared to the authenticated user only |
39 const char kGetDocumentListURLForSharedWithMe[] = | 40 const char kGetDocumentListURLForSharedWithMe[] = |
40 "https://docs.google.com/feeds/default/private/full/-/shared-with-me"; | 41 "https://docs.google.com/feeds/default/private/full/-/shared-with-me"; |
41 | 42 |
42 // URL requesting documents list of changes to documents collections. | 43 // URL requesting documents list of changes to documents collections. |
43 const char kGetChangesListURL[] = | 44 const char kGetChangesListURL[] = |
44 "https://docs.google.com/feeds/default/private/changes"; | 45 "https://docs.google.com/feeds/default/private/changes"; |
45 | 46 |
46 // Generates a URL for getting document list. If |directory_resource_id| is | |
47 // empty, returns a URL for fetching all documents. If it's given, returns a | |
48 // URL for fetching documents in a particular directory. | |
49 // This function is used to implement GenerateGetDocumentsURL(). | |
50 GURL GenerateDocumentListURL(const std::string& directory_resource_id) { | |
51 if (directory_resource_id.empty()) | |
52 return GURL(kGetDocumentListURLForAllDocuments); | |
53 | |
54 return GURL(base::StringPrintf(kGetDocumentListURLForDirectoryFormat, | |
55 net::EscapePath( | |
56 directory_resource_id).c_str())); | |
57 } | |
58 | |
59 } // namespace | 47 } // namespace |
60 | 48 |
61 GURL AddStandardUrlParams(const GURL& url) { | 49 GURL AddStandardUrlParams(const GURL& url) { |
62 GURL result = | 50 GURL result = |
63 chrome_common_net::AppendOrReplaceQueryParameter(url, "v", "3"); | 51 chrome_common_net::AppendOrReplaceQueryParameter(url, "v", "3"); |
64 result = | 52 result = |
65 chrome_common_net::AppendOrReplaceQueryParameter(result, "alt", "json"); | 53 chrome_common_net::AppendOrReplaceQueryParameter(result, "alt", "json"); |
66 return result; | 54 return result; |
67 } | 55 } |
68 | 56 |
(...skipping 27 matching lines...) Expand all Loading... | |
96 base::StringPrintf("%d", changestamp)); | 84 base::StringPrintf("%d", changestamp)); |
97 } | 85 } |
98 | 86 |
99 if (!search_string.empty()) { | 87 if (!search_string.empty()) { |
100 result = chrome_common_net::AppendOrReplaceQueryParameter( | 88 result = chrome_common_net::AppendOrReplaceQueryParameter( |
101 result, "q", search_string); | 89 result, "q", search_string); |
102 } | 90 } |
103 return result; | 91 return result; |
104 } | 92 } |
105 | 93 |
106 GURL GenerateGetDocumentsURL( | 94 GURL GenerateDocumentListUrl( |
107 const GURL& override_url, | 95 const GURL& override_url, |
108 int start_changestamp, | 96 int start_changestamp, |
109 const std::string& search_string, | 97 const std::string& search_string, |
110 bool shared_with_me, | 98 bool shared_with_me, |
111 const std::string& directory_resource_id) { | 99 const std::string& directory_resource_id) { |
112 int max_docs = search_string.empty() ? kMaxDocumentsPerFeed : | 100 int max_docs = search_string.empty() ? kMaxDocumentsPerFeed : |
113 kMaxDocumentsPerSearchFeed; | 101 kMaxDocumentsPerSearchFeed; |
114 | 102 GURL url; |
115 if (!override_url.is_empty()) | 103 if (!override_url.is_empty()) { |
116 return gdata_wapi_url_util::AddFeedUrlParams(override_url, | 104 url = override_url; |
117 max_docs, | 105 } else if (shared_with_me) { |
118 0, | 106 url = GURL(kGetDocumentListURLForSharedWithMe); |
119 search_string); | 107 } else if (start_changestamp > 0) { |
hashimoto
2012/11/20 06:16:06
Ah, sorry, '!= 0' and DCHECK_LE(0, start_changesta
satorux1
2012/11/20 06:27:33
Added a DCHECK at the beginning of the function.
| |
120 | 108 // The start changestamp shouldn't be used for a search. |
121 if (shared_with_me) { | 109 DCHECK(search_string.empty()); |
122 return gdata_wapi_url_util::AddFeedUrlParams( | 110 url = GURL(kGetChangesListURL); |
123 GURL(kGetDocumentListURLForSharedWithMe), | 111 } else if (!directory_resource_id.empty()) { |
124 max_docs, | 112 DCHECK_EQ(0, start_changestamp); |
125 0, | 113 url = GURL(base::StringPrintf(kGetDocumentListURLForDirectoryFormat, |
126 search_string); | 114 net::EscapePath( |
115 directory_resource_id).c_str())); | |
116 } else { | |
117 DCHECK_EQ(0, start_changestamp); | |
118 url = GURL(kGetDocumentListURLForAllDocuments); | |
127 } | 119 } |
128 | 120 return AddFeedUrlParams(url, max_docs, start_changestamp, search_string); |
129 if (start_changestamp == 0) { | |
130 return gdata_wapi_url_util::AddFeedUrlParams( | |
131 gdata_wapi_url_util::GenerateDocumentListURL(directory_resource_id), | |
132 max_docs, | |
133 0, | |
134 search_string); | |
135 } | |
136 | |
137 return gdata_wapi_url_util::AddFeedUrlParams( | |
138 GURL(kGetChangesListURL), | |
139 kMaxDocumentsPerFeed, | |
140 start_changestamp, | |
141 std::string()); | |
142 } | 121 } |
143 | 122 |
144 } // namespace gdata_wapi_url_util | 123 } // namespace gdata_wapi_url_util |
145 } // namespace google_apis | 124 } // namespace google_apis |
OLD | NEW |