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/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[] = |
|
hashimoto
2012/11/21 03:27:50
nit: No need to have newline?
satorux1
2012/11/21 03:58:56
Done.
| |
| 57 "https://docs.google.com/feeds/default/private/changes"; | 52 "/feeds/default/private/changes"; |
| 58 | 53 |
| 59 } // namespace | 54 } // namespace |
| 60 | 55 |
| 56 namespace gdata_wapi_url_util { | |
| 57 | |
| 58 const char kBaseUrlForProduction[] = "https://docs.google.com/"; | |
| 59 const char kBaseUrlForTesting[] = "http://127.0.0.1/"; | |
| 60 | |
| 61 GURL AddStandardUrlParams(const GURL& url) { | 61 GURL AddStandardUrlParams(const GURL& url) { |
| 62 GURL result = | 62 GURL result = |
| 63 chrome_common_net::AppendOrReplaceQueryParameter(url, "v", "3"); | 63 chrome_common_net::AppendOrReplaceQueryParameter(url, "v", "3"); |
| 64 result = | 64 result = |
| 65 chrome_common_net::AppendOrReplaceQueryParameter(result, "alt", "json"); | 65 chrome_common_net::AppendOrReplaceQueryParameter(result, "alt", "json"); |
| 66 return result; | 66 return result; |
| 67 } | 67 } |
| 68 | 68 |
| 69 GURL AddMetadataUrlParams(const GURL& url) { | 69 GURL AddMetadataUrlParams(const GURL& url) { |
| 70 GURL result = AddStandardUrlParams(url); | 70 GURL result = AddStandardUrlParams(url); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 96 base::StringPrintf("%d", changestamp)); | 96 base::StringPrintf("%d", changestamp)); |
| 97 } | 97 } |
| 98 | 98 |
| 99 if (!search_string.empty()) { | 99 if (!search_string.empty()) { |
| 100 result = chrome_common_net::AppendOrReplaceQueryParameter( | 100 result = chrome_common_net::AppendOrReplaceQueryParameter( |
| 101 result, "q", search_string); | 101 result, "q", search_string); |
| 102 } | 102 } |
| 103 return result; | 103 return result; |
| 104 } | 104 } |
| 105 | 105 |
| 106 GURL GenerateDocumentListUrl( | 106 } // namespace gdata_wapi_url_util |
| 107 | |
| 108 | |
| 109 // TODO(satorux): Move the following code to a separate file | |
| 110 // gdata_wapi_url_generator.cc | |
| 111 | |
| 112 GDataWapiUrlGenerator::GDataWapiUrlGenerator(const GURL& base_url) | |
| 113 : base_url_(GURL(base_url)) { | |
| 114 } | |
| 115 | |
| 116 GDataWapiUrlGenerator::~GDataWapiUrlGenerator() { | |
| 117 } | |
| 118 | |
| 119 GURL GDataWapiUrlGenerator::GenerateDocumentListUrl( | |
| 107 const GURL& override_url, | 120 const GURL& override_url, |
| 108 int start_changestamp, | 121 int start_changestamp, |
| 109 const std::string& search_string, | 122 const std::string& search_string, |
| 110 bool shared_with_me, | 123 bool shared_with_me, |
| 111 const std::string& directory_resource_id) { | 124 const std::string& directory_resource_id) const { |
| 112 DCHECK_LE(0, start_changestamp); | 125 DCHECK_LE(0, start_changestamp); |
| 113 | 126 |
| 114 int max_docs = search_string.empty() ? kMaxDocumentsPerFeed : | 127 int max_docs = search_string.empty() ? kMaxDocumentsPerFeed : |
| 115 kMaxDocumentsPerSearchFeed; | 128 kMaxDocumentsPerSearchFeed; |
| 116 GURL url; | 129 GURL url; |
| 117 if (!override_url.is_empty()) { | 130 if (!override_url.is_empty()) { |
| 118 url = override_url; | 131 url = override_url; |
| 119 } else if (shared_with_me) { | 132 } else if (shared_with_me) { |
| 120 url = GURL(kGetDocumentListURLForSharedWithMe); | 133 url = base_url_.Resolve(kGetDocumentListURLForSharedWithMe); |
| 121 } else if (start_changestamp > 0) { | 134 } else if (start_changestamp > 0) { |
| 122 // The start changestamp shouldn't be used for a search. | 135 // The start changestamp shouldn't be used for a search. |
| 123 DCHECK(search_string.empty()); | 136 DCHECK(search_string.empty()); |
| 124 url = GURL(kGetChangesListURL); | 137 url = base_url_.Resolve(kGetChangesListURL); |
| 125 } else if (!directory_resource_id.empty()) { | 138 } else if (!directory_resource_id.empty()) { |
| 126 url = GURL(base::StringPrintf(kGetDocumentListURLForDirectoryFormat, | 139 url = base_url_.Resolve( |
| 127 net::EscapePath( | 140 base::StringPrintf(kGetDocumentListURLForDirectoryFormat, |
| 128 directory_resource_id).c_str())); | 141 net::EscapePath( |
| 142 directory_resource_id).c_str())); | |
| 129 } else { | 143 } else { |
| 130 url = GURL(kGetDocumentListURLForAllDocuments); | 144 url = base_url_.Resolve(kGetDocumentListURLForAllDocuments); |
| 131 } | 145 } |
| 132 return AddFeedUrlParams(url, max_docs, start_changestamp, search_string); | 146 return gdata_wapi_url_util::AddFeedUrlParams( |
| 147 url, max_docs, start_changestamp, search_string); | |
| 133 } | 148 } |
| 134 | 149 |
| 135 GURL GenerateDocumentEntryUrl(const std::string& resource_id) { | 150 GURL GDataWapiUrlGenerator::GenerateDocumentEntryUrl( |
| 136 GURL result = GURL(base::StringPrintf(kGetDocumentEntryURLFormat, | 151 const std::string& resource_id) const { |
| 137 net::EscapePath(resource_id).c_str())); | 152 GURL result = base_url_.Resolve( |
| 138 return AddStandardUrlParams(result); | 153 base::StringPrintf(kGetDocumentEntryURLFormat, |
| 154 net::EscapePath(resource_id).c_str())); | |
| 155 return gdata_wapi_url_util::AddStandardUrlParams(result); | |
| 139 } | 156 } |
| 140 | 157 |
| 141 GURL GenerateDocumentListRootUrl() { | 158 GURL GDataWapiUrlGenerator::GenerateDocumentListRootUrl() const { |
| 142 return AddStandardUrlParams(GURL(kDocumentListRootURL)); | 159 return gdata_wapi_url_util::AddStandardUrlParams( |
| 160 base_url_.Resolve(kDocumentListRootURL)); | |
| 143 } | 161 } |
| 144 | 162 |
| 145 GURL GenerateAccountMetadataUrl() { | 163 GURL GDataWapiUrlGenerator::GenerateAccountMetadataUrl() const { |
| 146 return AddMetadataUrlParams(GURL(kAccountMetadataURL)); | 164 return gdata_wapi_url_util::AddMetadataUrlParams( |
| 165 base_url_.Resolve(kAccountMetadataURL)); | |
| 147 } | 166 } |
| 148 | 167 |
| 149 } // namespace gdata_wapi_url_util | |
| 150 } // namespace google_apis | 168 } // namespace google_apis |
| OLD | NEW |