Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: chrome/browser/google_apis/gdata_wapi_url_util.cc

Issue 11418084: google_apis: Introduce GDataWapiUrlGenerator class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: polish Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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[] =
hashimoto 2012/11/20 09:10:17 Please remove newline from where possible.
satorux1 2012/11/21 00:34:18 Done.
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[] =
30 "https://docs.google.com/feeds/default/private/full/%s"; 28 "/feeds/default/private/full/%s";
31 29
32 // Root document list url. 30 // Root document list url.
33 const char kDocumentListRootURL[] = 31 const char kDocumentListRootURL[] =
34 "https://docs.google.com/feeds/default/private/full"; 32 "/feeds/default/private/full";
35 33
36 // Metadata feed with things like user quota. 34 // Metadata feed with things like user quota.
37 const char kAccountMetadataURL[] = 35 const char kAccountMetadataURL[] =
38 "https://docs.google.com/feeds/metadata/default"; 36 "/feeds/metadata/default";
39 37
40 #ifndef NDEBUG 38 #ifndef NDEBUG
41 // Use smaller 'page' size while debugging to ensure we hit feed reload 39 // 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 40 // 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. 41 // have many items because server side 503 error might kick in.
44 const int kMaxDocumentsPerFeed = 500; 42 const int kMaxDocumentsPerFeed = 500;
45 const int kMaxDocumentsPerSearchFeed = 50; 43 const int kMaxDocumentsPerSearchFeed = 50;
46 #else 44 #else
47 const int kMaxDocumentsPerFeed = 500; 45 const int kMaxDocumentsPerFeed = 500;
48 const int kMaxDocumentsPerSearchFeed = 50; 46 const int kMaxDocumentsPerSearchFeed = 50;
49 #endif 47 #endif
50 48
51 // URL requesting documents list that shared to the authenticated user only 49 // URL requesting documents list that shared to the authenticated user only
52 const char kGetDocumentListURLForSharedWithMe[] = 50 const char kGetDocumentListURLForSharedWithMe[] =
53 "https://docs.google.com/feeds/default/private/full/-/shared-with-me"; 51 "/feeds/default/private/full/-/shared-with-me";
54 52
55 // URL requesting documents list of changes to documents collections. 53 // URL requesting documents list of changes to documents collections.
56 const char kGetChangesListURL[] = 54 const char kGetChangesListURL[] =
57 "https://docs.google.com/feeds/default/private/changes"; 55 "/feeds/default/private/changes";
58 56
59 } // namespace 57 } // namespace
60 58
59 namespace gdata_wapi_url_util {
60
61 const char kBaseUrlForProduction[] = "https://docs.google.com/";
62 const char kBaseUrlForTesting[] = "http://127.0.0.1/";
63
61 GURL AddStandardUrlParams(const GURL& url) { 64 GURL AddStandardUrlParams(const GURL& url) {
62 GURL result = 65 GURL result =
63 chrome_common_net::AppendOrReplaceQueryParameter(url, "v", "3"); 66 chrome_common_net::AppendOrReplaceQueryParameter(url, "v", "3");
64 result = 67 result =
65 chrome_common_net::AppendOrReplaceQueryParameter(result, "alt", "json"); 68 chrome_common_net::AppendOrReplaceQueryParameter(result, "alt", "json");
66 return result; 69 return result;
67 } 70 }
68 71
69 GURL AddMetadataUrlParams(const GURL& url) { 72 GURL AddMetadataUrlParams(const GURL& url) {
70 GURL result = AddStandardUrlParams(url); 73 GURL result = AddStandardUrlParams(url);
(...skipping 25 matching lines...) Expand all
96 base::StringPrintf("%d", changestamp)); 99 base::StringPrintf("%d", changestamp));
97 } 100 }
98 101
99 if (!search_string.empty()) { 102 if (!search_string.empty()) {
100 result = chrome_common_net::AppendOrReplaceQueryParameter( 103 result = chrome_common_net::AppendOrReplaceQueryParameter(
101 result, "q", search_string); 104 result, "q", search_string);
102 } 105 }
103 return result; 106 return result;
104 } 107 }
105 108
106 GURL GenerateDocumentListUrl( 109 } // namespace gdata_wapi_url_util
110
111
112 // TODO(satorux): Move the following code to a separate file
113 // gdata_wapi_url_generator.cc
114
115 GDataWapiUrlGenerator::GDataWapiUrlGenerator(const std::string& base_url)
116 : base_url_(GURL(base_url)) {
117 }
118
119 GDataWapiUrlGenerator::~GDataWapiUrlGenerator() {
120 }
121
122 GURL GDataWapiUrlGenerator::GenerateDocumentListUrl(
107 const GURL& override_url, 123 const GURL& override_url,
108 int start_changestamp, 124 int start_changestamp,
109 const std::string& search_string, 125 const std::string& search_string,
110 bool shared_with_me, 126 bool shared_with_me,
111 const std::string& directory_resource_id) { 127 const std::string& directory_resource_id) const {
112 DCHECK_LE(0, start_changestamp); 128 DCHECK_LE(0, start_changestamp);
113 129
114 int max_docs = search_string.empty() ? kMaxDocumentsPerFeed : 130 int max_docs = search_string.empty() ? kMaxDocumentsPerFeed :
115 kMaxDocumentsPerSearchFeed; 131 kMaxDocumentsPerSearchFeed;
116 GURL url; 132 GURL url;
117 if (!override_url.is_empty()) { 133 if (!override_url.is_empty()) {
118 url = override_url; 134 url = override_url;
119 } else if (shared_with_me) { 135 } else if (shared_with_me) {
120 url = GURL(kGetDocumentListURLForSharedWithMe); 136 url = base_url_.Resolve(kGetDocumentListURLForSharedWithMe);
121 } else if (start_changestamp > 0) { 137 } else if (start_changestamp > 0) {
122 // The start changestamp shouldn't be used for a search. 138 // The start changestamp shouldn't be used for a search.
123 DCHECK(search_string.empty()); 139 DCHECK(search_string.empty());
124 url = GURL(kGetChangesListURL); 140 url = base_url_.Resolve(kGetChangesListURL);
125 } else if (!directory_resource_id.empty()) { 141 } else if (!directory_resource_id.empty()) {
126 url = GURL(base::StringPrintf(kGetDocumentListURLForDirectoryFormat, 142 url = base_url_.Resolve(
127 net::EscapePath( 143 base::StringPrintf(kGetDocumentListURLForDirectoryFormat,
128 directory_resource_id).c_str())); 144 net::EscapePath(
145 directory_resource_id).c_str()));
129 } else { 146 } else {
130 url = GURL(kGetDocumentListURLForAllDocuments); 147 url = base_url_.Resolve(kGetDocumentListURLForAllDocuments);
131 } 148 }
132 return AddFeedUrlParams(url, max_docs, start_changestamp, search_string); 149 return gdata_wapi_url_util::AddFeedUrlParams(
150 url, max_docs, start_changestamp, search_string);
133 } 151 }
134 152
135 GURL GenerateDocumentEntryUrl(const std::string& resource_id) { 153 GURL GDataWapiUrlGenerator::GenerateDocumentEntryUrl(
136 GURL result = GURL(base::StringPrintf(kGetDocumentEntryURLFormat, 154 const std::string& resource_id) const {
137 net::EscapePath(resource_id).c_str())); 155 GURL result = base_url_.Resolve(
138 return AddStandardUrlParams(result); 156 base::StringPrintf(kGetDocumentEntryURLFormat,
157 net::EscapePath(resource_id).c_str()));
158 return gdata_wapi_url_util::AddStandardUrlParams(result);
139 } 159 }
140 160
141 GURL GenerateDocumentListRootUrl() { 161 GURL GDataWapiUrlGenerator::GenerateDocumentListRootUrl() const {
142 return AddStandardUrlParams(GURL(kDocumentListRootURL)); 162 return gdata_wapi_url_util::AddStandardUrlParams(
163 base_url_.Resolve(kDocumentListRootURL));
143 } 164 }
144 165
145 GURL GenerateAccountMetadataUrl() { 166 GURL GDataWapiUrlGenerator::GenerateAccountMetadataUrl() const {
146 return AddMetadataUrlParams(GURL(kAccountMetadataURL)); 167 return gdata_wapi_url_util::AddMetadataUrlParams(
168 base_url_.Resolve(kAccountMetadataURL));
147 } 169 }
148 170
149 } // namespace gdata_wapi_url_util
150 } // namespace google_apis 171 } // namespace google_apis
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698