Commit 48b6601c authored by hidehiko@chromium.org's avatar hidehiko@chromium.org

Small clean up of GDataWapiUrlGenerator.

Removed unnecessary query parameter "include-installed-apps=true" from
AddFeedUrlParams. Use base::IntToString instead of StringPrintf for trivial
case.
This is a preparation to add new method into GDataWapiUrlGenerator to support
"search by title exact match".

BUG=232352
TEST=Ran unit_tests

Review URL: https://chromiumcodereview.appspot.com/14240004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195191 0039d316-1c4b-4281-b951-d872f2087c98
parent 4d82ea81
......@@ -163,7 +163,7 @@ GetResourceListOperation::GetResourceListOperation(
net::URLRequestContextGetter* url_request_context_getter,
const GDataWapiUrlGenerator& url_generator,
const GURL& override_url,
int start_changestamp,
int64 start_changestamp,
const std::string& search_string,
const std::string& directory_resource_id,
const GetResourceListCallback& callback)
......
......@@ -51,7 +51,7 @@ class GetResourceListOperation : public GetDataOperation {
net::URLRequestContextGetter* url_request_context_getter,
const GDataWapiUrlGenerator& url_generator,
const GURL& override_url,
int start_changestamp,
int64 start_changestamp,
const std::string& search_string,
const std::string& directory_resource_id,
const GetResourceListCallback& callback);
......@@ -64,7 +64,7 @@ class GetResourceListOperation : public GetDataOperation {
private:
const GDataWapiUrlGenerator url_generator_;
const GURL override_url_;
const int start_changestamp_;
const int64 start_changestamp_;
const std::string search_string_;
const std::string directory_resource_id_;
......
......@@ -339,8 +339,7 @@ TEST_F(GDataWapiOperationsTest, GetResourceListOperation_DefaultFeed) {
EXPECT_EQ(HTTP_SUCCESS, result_code);
EXPECT_EQ(test_server::METHOD_GET, http_request_.method);
EXPECT_EQ("/feeds/default/private/full?v=3&alt=json&showroot=true&"
"showfolders=true&include-shared=true&max-results=500&"
"include-installed-apps=true",
"showfolders=true&include-shared=true&max-results=500",
http_request_.relative_url);
// Sanity check of the result.
......@@ -373,8 +372,7 @@ TEST_F(GDataWapiOperationsTest, GetResourceListOperation_ValidFeed) {
EXPECT_EQ(HTTP_SUCCESS, result_code);
EXPECT_EQ(test_server::METHOD_GET, http_request_.method);
EXPECT_EQ("/files/chromeos/gdata/root_feed.json?v=3&alt=json&showroot=true&"
"showfolders=true&include-shared=true&max-results=500"
"&include-installed-apps=true",
"showfolders=true&include-shared=true&max-results=500",
http_request_.relative_url);
scoped_ptr<ResourceList> expected(
......@@ -408,8 +406,7 @@ TEST_F(GDataWapiOperationsTest, GetResourceListOperation_InvalidFeed) {
EXPECT_EQ(GDATA_PARSE_ERROR, result_code);
EXPECT_EQ(test_server::METHOD_GET, http_request_.method);
EXPECT_EQ("/files/chromeos/gdata/testfile.txt?v=3&alt=json&showroot=true&"
"showfolders=true&include-shared=true&max-results=500&"
"include-installed-apps=true",
"showfolders=true&include-shared=true&max-results=500",
http_request_.relative_url);
EXPECT_FALSE(result_data);
}
......
......@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/stringprintf.h"
#include "base/strings/string_number_conversions.h"
#include "googleurl/src/gurl.h"
#include "net/base/escape.h"
#include "net/base/url_util.h"
......@@ -74,22 +75,17 @@ GURL GDataWapiUrlGenerator::AddInitiateUploadUrlParams(const GURL& url) {
GURL GDataWapiUrlGenerator::AddFeedUrlParams(
const GURL& url,
int num_items_to_fetch,
int changestamp,
int64 changestamp,
const std::string& search_string) {
GURL result = AddStandardUrlParams(url);
result = net::AppendOrReplaceQueryParameter(result, "showfolders", "true");
result = net::AppendOrReplaceQueryParameter(result, "include-shared", "true");
result = net::AppendOrReplaceQueryParameter(
result,
"max-results",
base::StringPrintf("%d", num_items_to_fetch));
result = net::AppendOrReplaceQueryParameter(
result, "include-installed-apps", "true");
result, "max-results", base::IntToString(num_items_to_fetch));
if (changestamp) {
result = net::AppendQueryParameter(result,
"start-index",
base::StringPrintf("%d", changestamp));
result = net::AppendQueryParameter(
result, "start-index", base::Int64ToString(changestamp));
}
if (!search_string.empty()) {
......@@ -107,7 +103,7 @@ GDataWapiUrlGenerator::~GDataWapiUrlGenerator() {
GURL GDataWapiUrlGenerator::GenerateResourceListUrl(
const GURL& override_url,
int start_changestamp,
int64 start_changestamp,
const std::string& search_string,
const std::string& directory_resource_id) const {
DCHECK_LE(0, start_changestamp);
......
......@@ -37,7 +37,7 @@ class GDataWapiUrlGenerator {
// and adds q=... parameter if |search_string| is non-empty.
static GURL AddFeedUrlParams(const GURL& url,
int num_items_to_fetch,
int changestamp,
int64 changestamp,
const std::string& search_string);
// Generates a URL for getting the resource list feed.
......@@ -69,7 +69,7 @@ class GDataWapiUrlGenerator {
//
GURL GenerateResourceListUrl(
const GURL& override_url,
int start_changestamp,
int64 start_changestamp,
const std::string& search_string,
const std::string& directory_resource_id) const;
......
......@@ -36,8 +36,7 @@ TEST_F(GDataWapiUrlGeneratorTest, AddFeedUrlParams) {
"http://www.example.com/?v=3&alt=json&showroot=true&"
"showfolders=true"
"&include-shared=true"
"&max-results=100"
"&include-installed-apps=true",
"&max-results=100",
GDataWapiUrlGenerator::AddFeedUrlParams(GURL("http://www.example.com"),
100, // num_items_to_fetch
0, // changestamp
......@@ -48,7 +47,6 @@ TEST_F(GDataWapiUrlGeneratorTest, AddFeedUrlParams) {
"showfolders=true"
"&include-shared=true"
"&max-results=100"
"&include-installed-apps=true"
"&start-index=123",
GDataWapiUrlGenerator::AddFeedUrlParams(GURL("http://www.example.com"),
100, // num_items_to_fetch
......@@ -59,7 +57,6 @@ TEST_F(GDataWapiUrlGeneratorTest, AddFeedUrlParams) {
"showfolders=true"
"&include-shared=true"
"&max-results=100"
"&include-installed-apps=true"
"&start-index=123"
"&q=%22foo+bar%22",
GDataWapiUrlGenerator::AddFeedUrlParams(
......@@ -74,7 +71,7 @@ TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListUrl) {
// This is the very basic URL for the GetResourceList operation.
EXPECT_EQ("https://docs.google.com/feeds/default/private/full"
"?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
"&max-results=500&include-installed-apps=true",
"&max-results=500",
url_generator_.GenerateResourceListUrl(
GURL(), // override_url,
0, // start_changestamp,
......@@ -86,7 +83,7 @@ TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListUrl) {
// parameters remain as-is.
EXPECT_EQ("http://localhost/"
"?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
"&max-results=500&include-installed-apps=true",
"&max-results=500",
url_generator_.GenerateResourceListUrl(
GURL("http://localhost/"), // override_url,
0, // start_changestamp,
......@@ -98,8 +95,7 @@ TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListUrl) {
// "full" to "changes", and "start-index" parameter is added.
EXPECT_EQ("https://docs.google.com/feeds/default/private/changes"
"?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
"&max-results=500&include-installed-apps=true"
"&start-index=100",
"&max-results=500&start-index=100",
url_generator_.GenerateResourceListUrl(
GURL(), // override_url,
100, // start_changestamp,
......@@ -111,7 +107,7 @@ TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListUrl) {
// and "q" parameter is added.
EXPECT_EQ("https://docs.google.com/feeds/default/private/full"
"?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
"&max-results=50&include-installed-apps=true&q=foo",
"&max-results=50&q=foo",
url_generator_.GenerateResourceListUrl(
GURL(), // override_url,
0, // start_changestamp,
......@@ -124,7 +120,7 @@ TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListUrl) {
EXPECT_EQ(
"https://docs.google.com/feeds/default/private/full/XXX/contents"
"?v=3&alt=json&showroot=true&showfolders=true&include-shared=true"
"&max-results=500&include-installed-apps=true",
"&max-results=500",
url_generator_.GenerateResourceListUrl(GURL(), // override_url,
0, // start_changestamp,
std::string(), // search_string,
......@@ -136,7 +132,7 @@ TEST_F(GDataWapiUrlGeneratorTest, GenerateResourceListUrl) {
// overridden.
EXPECT_EQ("http://example.com/"
"?start-index=123&v=3&alt=json&showroot=true&showfolders=true"
"&include-shared=true&max-results=500&include-installed-apps=true",
"&include-shared=true&max-results=500",
url_generator_.GenerateResourceListUrl(
GURL("http://example.com/?start-index=123"), // override_url,
100, // start_changestamp,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment