| 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_generator.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" | |
| 10 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
| 11 #include "net/base/escape.h" | 10 #include "net/base/escape.h" |
| 11 #include "net/base/url_util.h" |
| 12 | 12 |
| 13 namespace google_apis { | 13 namespace google_apis { |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // URL requesting resource list that belong to the authenticated user only | 16 // URL requesting resource list that belong to the authenticated user only |
| 17 // (handled with '/-/mine' part). | 17 // (handled with '/-/mine' part). |
| 18 const char kGetResourceListURLForAllDocuments[] = | 18 const char kGetResourceListURLForAllDocuments[] = |
| 19 "/feeds/default/private/full/-/mine"; | 19 "/feeds/default/private/full/-/mine"; |
| 20 | 20 |
| 21 // URL requesting resource list in a particular directory specified by "%s" | 21 // URL requesting resource list in a particular directory specified by "%s" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // URL requesting documents list of changes to documents collections. | 59 // URL requesting documents list of changes to documents collections. |
| 60 const char kGetChangesListURL[] = "/feeds/default/private/changes"; | 60 const char kGetChangesListURL[] = "/feeds/default/private/changes"; |
| 61 | 61 |
| 62 } // namespace | 62 } // namespace |
| 63 | 63 |
| 64 const char GDataWapiUrlGenerator::kBaseUrlForProduction[] = | 64 const char GDataWapiUrlGenerator::kBaseUrlForProduction[] = |
| 65 "https://docs.google.com/"; | 65 "https://docs.google.com/"; |
| 66 | 66 |
| 67 // static | 67 // static |
| 68 GURL GDataWapiUrlGenerator::AddStandardUrlParams(const GURL& url) { | 68 GURL GDataWapiUrlGenerator::AddStandardUrlParams(const GURL& url) { |
| 69 GURL result = | 69 GURL result = net::AppendOrReplaceQueryParameter(url, "v", "3"); |
| 70 chrome_common_net::AppendOrReplaceQueryParameter(url, "v", "3"); | 70 result = net::AppendOrReplaceQueryParameter(result, "alt", "json"); |
| 71 result = | |
| 72 chrome_common_net::AppendOrReplaceQueryParameter(result, "alt", "json"); | |
| 73 return result; | 71 return result; |
| 74 } | 72 } |
| 75 | 73 |
| 76 // static | 74 // static |
| 77 GURL GDataWapiUrlGenerator::AddMetadataUrlParams(const GURL& url) { | 75 GURL GDataWapiUrlGenerator::AddMetadataUrlParams(const GURL& url) { |
| 78 GURL result = AddStandardUrlParams(url); | 76 GURL result = AddStandardUrlParams(url); |
| 79 result = chrome_common_net::AppendOrReplaceQueryParameter( | 77 result = net::AppendOrReplaceQueryParameter( |
| 80 result, "include-installed-apps", "true"); | 78 result, "include-installed-apps", "true"); |
| 81 return result; | 79 return result; |
| 82 } | 80 } |
| 83 | 81 |
| 84 // static | 82 // static |
| 85 GURL GDataWapiUrlGenerator::AddFeedUrlParams( | 83 GURL GDataWapiUrlGenerator::AddFeedUrlParams( |
| 86 const GURL& url, | 84 const GURL& url, |
| 87 int num_items_to_fetch, | 85 int num_items_to_fetch, |
| 88 int changestamp, | 86 int changestamp, |
| 89 const std::string& search_string) { | 87 const std::string& search_string) { |
| 90 GURL result = AddStandardUrlParams(url); | 88 GURL result = AddStandardUrlParams(url); |
| 91 result = chrome_common_net::AppendOrReplaceQueryParameter( | 89 result = net::AppendOrReplaceQueryParameter(result, "showfolders", "true"); |
| 92 result, | 90 result = net::AppendOrReplaceQueryParameter( |
| 93 "showfolders", | |
| 94 "true"); | |
| 95 result = chrome_common_net::AppendOrReplaceQueryParameter( | |
| 96 result, | 91 result, |
| 97 "max-results", | 92 "max-results", |
| 98 base::StringPrintf("%d", num_items_to_fetch)); | 93 base::StringPrintf("%d", num_items_to_fetch)); |
| 99 result = chrome_common_net::AppendOrReplaceQueryParameter( | 94 result = net::AppendOrReplaceQueryParameter( |
| 100 result, "include-installed-apps", "true"); | 95 result, "include-installed-apps", "true"); |
| 101 | 96 |
| 102 if (changestamp) { | 97 if (changestamp) { |
| 103 result = chrome_common_net::AppendQueryParameter( | 98 result = net::AppendQueryParameter(result, |
| 104 result, | 99 "start-index", |
| 105 "start-index", | 100 base::StringPrintf("%d", changestamp)); |
| 106 base::StringPrintf("%d", changestamp)); | |
| 107 } | 101 } |
| 108 | 102 |
| 109 if (!search_string.empty()) { | 103 if (!search_string.empty()) { |
| 110 result = chrome_common_net::AppendOrReplaceQueryParameter( | 104 result = net::AppendOrReplaceQueryParameter(result, "q", search_string); |
| 111 result, "q", search_string); | |
| 112 } | 105 } |
| 113 return result; | 106 return result; |
| 114 } | 107 } |
| 115 | 108 |
| 116 GDataWapiUrlGenerator::GDataWapiUrlGenerator(const GURL& base_url) | 109 GDataWapiUrlGenerator::GDataWapiUrlGenerator(const GURL& base_url) |
| 117 : base_url_(GURL(base_url)) { | 110 : base_url_(GURL(base_url)) { |
| 118 } | 111 } |
| 119 | 112 |
| 120 GDataWapiUrlGenerator::~GDataWapiUrlGenerator() { | 113 GDataWapiUrlGenerator::~GDataWapiUrlGenerator() { |
| 121 } | 114 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 186 |
| 194 GURL GDataWapiUrlGenerator::GenerateResourceListRootUrl() const { | 187 GURL GDataWapiUrlGenerator::GenerateResourceListRootUrl() const { |
| 195 return AddStandardUrlParams(base_url_.Resolve(kResourceListRootURL)); | 188 return AddStandardUrlParams(base_url_.Resolve(kResourceListRootURL)); |
| 196 } | 189 } |
| 197 | 190 |
| 198 GURL GDataWapiUrlGenerator::GenerateAccountMetadataUrl() const { | 191 GURL GDataWapiUrlGenerator::GenerateAccountMetadataUrl() const { |
| 199 return AddMetadataUrlParams(base_url_.Resolve(kAccountMetadataURL)); | 192 return AddMetadataUrlParams(base_url_.Resolve(kAccountMetadataURL)); |
| 200 } | 193 } |
| 201 | 194 |
| 202 } // namespace google_apis | 195 } // namespace google_apis |
| OLD | NEW |