Chromium Code Reviews| 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) { |
| 120 | 108 if (directory_resource_id.empty()) { |
|
hashimoto
2012/11/20 06:07:35
How about putting start_changestamp > 0 case befor
satorux1
2012/11/20 06:13:28
good idea. done.
| |
| 121 if (shared_with_me) { | 109 url = GURL(kGetDocumentListURLForAllDocuments); |
| 122 return gdata_wapi_url_util::AddFeedUrlParams( | 110 } else { |
| 123 GURL(kGetDocumentListURLForSharedWithMe), | 111 url = GURL(base::StringPrintf(kGetDocumentListURLForDirectoryFormat, |
| 124 max_docs, | 112 net::EscapePath( |
| 125 0, | 113 directory_resource_id).c_str())); |
| 126 search_string); | 114 } |
| 115 } else { | |
| 116 DCHECK_LT(0, start_changestamp); | |
| 117 // The start changestamp shouldn't be used for a search. | |
| 118 DCHECK(search_string.empty()); | |
| 119 url = GURL(kGetChangesListURL); | |
| 127 } | 120 } |
| 128 | 121 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 } | 122 } |
| 143 | 123 |
| 144 } // namespace gdata_wapi_url_util | 124 } // namespace gdata_wapi_url_util |
| 145 } // namespace google_apis | 125 } // namespace google_apis |
| OLD | NEW |