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

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

Issue 11417108: google_apis: Get rid of gdata_wapi_url_util namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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_generator.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 { 14 namespace {
15 15
(...skipping 30 matching lines...) Expand all
46 // URL requesting documents list that shared to the authenticated user only 46 // URL requesting documents list that shared to the authenticated user only
47 const char kGetDocumentListURLForSharedWithMe[] = 47 const char kGetDocumentListURLForSharedWithMe[] =
48 "/feeds/default/private/full/-/shared-with-me"; 48 "/feeds/default/private/full/-/shared-with-me";
49 49
50 // URL requesting documents list of changes to documents collections. 50 // URL requesting documents list of changes to documents collections.
51 const char kGetChangesListURL[] = 51 const char kGetChangesListURL[] =
52 "/feeds/default/private/changes"; 52 "/feeds/default/private/changes";
53 53
54 } // namespace 54 } // namespace
55 55
56 namespace gdata_wapi_url_util { 56 const char GDataWapiUrlGenerator::kBaseUrlForProduction[] =
57 "https://docs.google.com/";
58 const char GDataWapiUrlGenerator::kBaseUrlForTesting[] = "http://127.0.0.1/";
57 59
58 const char kBaseUrlForProduction[] = "https://docs.google.com/"; 60 // static
59 const char kBaseUrlForTesting[] = "http://127.0.0.1/"; 61 GURL GDataWapiUrlGenerator::AddStandardUrlParams(const GURL& url) {
60
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 // static
70 GURL GDataWapiUrlGenerator::AddMetadataUrlParams(const GURL& url) {
70 GURL result = AddStandardUrlParams(url); 71 GURL result = AddStandardUrlParams(url);
71 result = chrome_common_net::AppendOrReplaceQueryParameter( 72 result = chrome_common_net::AppendOrReplaceQueryParameter(
72 result, "include-installed-apps", "true"); 73 result, "include-installed-apps", "true");
73 return result; 74 return result;
74 } 75 }
75 76
76 GURL AddFeedUrlParams(const GURL& url, 77 // static
77 int num_items_to_fetch, 78 GURL GDataWapiUrlGenerator::AddFeedUrlParams(
78 int changestamp, 79 const GURL& url,
79 const std::string& search_string) { 80 int num_items_to_fetch,
81 int changestamp,
82 const std::string& search_string) {
80 GURL result = AddStandardUrlParams(url); 83 GURL result = AddStandardUrlParams(url);
81 result = chrome_common_net::AppendOrReplaceQueryParameter( 84 result = chrome_common_net::AppendOrReplaceQueryParameter(
82 result, 85 result,
83 "showfolders", 86 "showfolders",
84 "true"); 87 "true");
85 result = chrome_common_net::AppendOrReplaceQueryParameter( 88 result = chrome_common_net::AppendOrReplaceQueryParameter(
86 result, 89 result,
87 "max-results", 90 "max-results",
88 base::StringPrintf("%d", num_items_to_fetch)); 91 base::StringPrintf("%d", num_items_to_fetch));
89 result = chrome_common_net::AppendOrReplaceQueryParameter( 92 result = chrome_common_net::AppendOrReplaceQueryParameter(
90 result, "include-installed-apps", "true"); 93 result, "include-installed-apps", "true");
91 94
92 if (changestamp) { 95 if (changestamp) {
93 result = chrome_common_net::AppendQueryParameter( 96 result = chrome_common_net::AppendQueryParameter(
94 result, 97 result,
95 "start-index", 98 "start-index",
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 } // 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) 109 GDataWapiUrlGenerator::GDataWapiUrlGenerator(const GURL& base_url)
113 : base_url_(GURL(base_url)) { 110 : base_url_(GURL(base_url)) {
114 } 111 }
115 112
116 GDataWapiUrlGenerator::~GDataWapiUrlGenerator() { 113 GDataWapiUrlGenerator::~GDataWapiUrlGenerator() {
117 } 114 }
118 115
119 GURL GDataWapiUrlGenerator::GenerateDocumentListUrl( 116 GURL GDataWapiUrlGenerator::GenerateDocumentListUrl(
120 const GURL& override_url, 117 const GURL& override_url,
121 int start_changestamp, 118 int start_changestamp,
(...skipping 14 matching lines...) Expand all
136 DCHECK(search_string.empty()); 133 DCHECK(search_string.empty());
137 url = base_url_.Resolve(kGetChangesListURL); 134 url = base_url_.Resolve(kGetChangesListURL);
138 } else if (!directory_resource_id.empty()) { 135 } else if (!directory_resource_id.empty()) {
139 url = base_url_.Resolve( 136 url = base_url_.Resolve(
140 base::StringPrintf(kGetDocumentListURLForDirectoryFormat, 137 base::StringPrintf(kGetDocumentListURLForDirectoryFormat,
141 net::EscapePath( 138 net::EscapePath(
142 directory_resource_id).c_str())); 139 directory_resource_id).c_str()));
143 } else { 140 } else {
144 url = base_url_.Resolve(kGetDocumentListURLForAllDocuments); 141 url = base_url_.Resolve(kGetDocumentListURLForAllDocuments);
145 } 142 }
146 return gdata_wapi_url_util::AddFeedUrlParams( 143 return AddFeedUrlParams(url, max_docs, start_changestamp, search_string);
147 url, max_docs, start_changestamp, search_string);
148 } 144 }
149 145
150 GURL GDataWapiUrlGenerator::GenerateDocumentEntryUrl( 146 GURL GDataWapiUrlGenerator::GenerateDocumentEntryUrl(
151 const std::string& resource_id) const { 147 const std::string& resource_id) const {
152 GURL result = base_url_.Resolve( 148 GURL result = base_url_.Resolve(
153 base::StringPrintf(kGetDocumentEntryURLFormat, 149 base::StringPrintf(kGetDocumentEntryURLFormat,
154 net::EscapePath(resource_id).c_str())); 150 net::EscapePath(resource_id).c_str()));
155 return gdata_wapi_url_util::AddStandardUrlParams(result); 151 return AddStandardUrlParams(result);
156 } 152 }
157 153
158 GURL GDataWapiUrlGenerator::GenerateDocumentListRootUrl() const { 154 GURL GDataWapiUrlGenerator::GenerateDocumentListRootUrl() const {
159 return gdata_wapi_url_util::AddStandardUrlParams( 155 return AddStandardUrlParams(base_url_.Resolve(kDocumentListRootURL));
160 base_url_.Resolve(kDocumentListRootURL));
161 } 156 }
162 157
163 GURL GDataWapiUrlGenerator::GenerateAccountMetadataUrl() const { 158 GURL GDataWapiUrlGenerator::GenerateAccountMetadataUrl() const {
164 return gdata_wapi_url_util::AddMetadataUrlParams( 159 return AddMetadataUrlParams(base_url_.Resolve(kAccountMetadataURL));
165 base_url_.Resolve(kAccountMetadataURL));
166 } 160 }
167 161
168 } // namespace google_apis 162 } // namespace google_apis
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698