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_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 29 matching lines...) Expand all Loading... |
45 | 45 |
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[] = "/feeds/default/private/changes"; | 51 const char kGetChangesListURL[] = "/feeds/default/private/changes"; |
52 | 52 |
53 } // namespace | 53 } // namespace |
54 | 54 |
55 namespace gdata_wapi_url_util { | 55 const char GDataWapiUrlGenerator::kBaseUrlForProduction[] = |
| 56 "https://docs.google.com/"; |
| 57 const char GDataWapiUrlGenerator::kBaseUrlForTesting[] = "http://127.0.0.1/"; |
56 | 58 |
57 const char kBaseUrlForProduction[] = "https://docs.google.com/"; | 59 // static |
58 const char kBaseUrlForTesting[] = "http://127.0.0.1/"; | 60 GURL GDataWapiUrlGenerator::AddStandardUrlParams(const GURL& url) { |
59 | |
60 GURL AddStandardUrlParams(const GURL& url) { | |
61 GURL result = | 61 GURL result = |
62 chrome_common_net::AppendOrReplaceQueryParameter(url, "v", "3"); | 62 chrome_common_net::AppendOrReplaceQueryParameter(url, "v", "3"); |
63 result = | 63 result = |
64 chrome_common_net::AppendOrReplaceQueryParameter(result, "alt", "json"); | 64 chrome_common_net::AppendOrReplaceQueryParameter(result, "alt", "json"); |
65 return result; | 65 return result; |
66 } | 66 } |
67 | 67 |
68 GURL AddMetadataUrlParams(const GURL& url) { | 68 // static |
| 69 GURL GDataWapiUrlGenerator::AddMetadataUrlParams(const GURL& url) { |
69 GURL result = AddStandardUrlParams(url); | 70 GURL result = AddStandardUrlParams(url); |
70 result = chrome_common_net::AppendOrReplaceQueryParameter( | 71 result = chrome_common_net::AppendOrReplaceQueryParameter( |
71 result, "include-installed-apps", "true"); | 72 result, "include-installed-apps", "true"); |
72 return result; | 73 return result; |
73 } | 74 } |
74 | 75 |
75 GURL AddFeedUrlParams(const GURL& url, | 76 // static |
76 int num_items_to_fetch, | 77 GURL GDataWapiUrlGenerator::AddFeedUrlParams( |
77 int changestamp, | 78 const GURL& url, |
78 const std::string& search_string) { | 79 int num_items_to_fetch, |
| 80 int changestamp, |
| 81 const std::string& search_string) { |
79 GURL result = AddStandardUrlParams(url); | 82 GURL result = AddStandardUrlParams(url); |
80 result = chrome_common_net::AppendOrReplaceQueryParameter( | 83 result = chrome_common_net::AppendOrReplaceQueryParameter( |
81 result, | 84 result, |
82 "showfolders", | 85 "showfolders", |
83 "true"); | 86 "true"); |
84 result = chrome_common_net::AppendOrReplaceQueryParameter( | 87 result = chrome_common_net::AppendOrReplaceQueryParameter( |
85 result, | 88 result, |
86 "max-results", | 89 "max-results", |
87 base::StringPrintf("%d", num_items_to_fetch)); | 90 base::StringPrintf("%d", num_items_to_fetch)); |
88 result = chrome_common_net::AppendOrReplaceQueryParameter( | 91 result = chrome_common_net::AppendOrReplaceQueryParameter( |
89 result, "include-installed-apps", "true"); | 92 result, "include-installed-apps", "true"); |
90 | 93 |
91 if (changestamp) { | 94 if (changestamp) { |
92 result = chrome_common_net::AppendQueryParameter( | 95 result = chrome_common_net::AppendQueryParameter( |
93 result, | 96 result, |
94 "start-index", | 97 "start-index", |
95 base::StringPrintf("%d", changestamp)); | 98 base::StringPrintf("%d", changestamp)); |
96 } | 99 } |
97 | 100 |
98 if (!search_string.empty()) { | 101 if (!search_string.empty()) { |
99 result = chrome_common_net::AppendOrReplaceQueryParameter( | 102 result = chrome_common_net::AppendOrReplaceQueryParameter( |
100 result, "q", search_string); | 103 result, "q", search_string); |
101 } | 104 } |
102 return result; | 105 return result; |
103 } | 106 } |
104 | 107 |
105 } // namespace gdata_wapi_url_util | |
106 | |
107 | |
108 // TODO(satorux): Move the following code to a separate file | |
109 // gdata_wapi_url_generator.cc | |
110 | |
111 GDataWapiUrlGenerator::GDataWapiUrlGenerator(const GURL& base_url) | 108 GDataWapiUrlGenerator::GDataWapiUrlGenerator(const GURL& base_url) |
112 : base_url_(GURL(base_url)) { | 109 : base_url_(GURL(base_url)) { |
113 } | 110 } |
114 | 111 |
115 GDataWapiUrlGenerator::~GDataWapiUrlGenerator() { | 112 GDataWapiUrlGenerator::~GDataWapiUrlGenerator() { |
116 } | 113 } |
117 | 114 |
118 GURL GDataWapiUrlGenerator::GenerateDocumentListUrl( | 115 GURL GDataWapiUrlGenerator::GenerateDocumentListUrl( |
119 const GURL& override_url, | 116 const GURL& override_url, |
120 int start_changestamp, | 117 int start_changestamp, |
(...skipping 14 matching lines...) Expand all Loading... |
135 DCHECK(search_string.empty()); | 132 DCHECK(search_string.empty()); |
136 url = base_url_.Resolve(kGetChangesListURL); | 133 url = base_url_.Resolve(kGetChangesListURL); |
137 } else if (!directory_resource_id.empty()) { | 134 } else if (!directory_resource_id.empty()) { |
138 url = base_url_.Resolve( | 135 url = base_url_.Resolve( |
139 base::StringPrintf(kGetDocumentListURLForDirectoryFormat, | 136 base::StringPrintf(kGetDocumentListURLForDirectoryFormat, |
140 net::EscapePath( | 137 net::EscapePath( |
141 directory_resource_id).c_str())); | 138 directory_resource_id).c_str())); |
142 } else { | 139 } else { |
143 url = base_url_.Resolve(kGetDocumentListURLForAllDocuments); | 140 url = base_url_.Resolve(kGetDocumentListURLForAllDocuments); |
144 } | 141 } |
145 return gdata_wapi_url_util::AddFeedUrlParams( | 142 return AddFeedUrlParams(url, max_docs, start_changestamp, search_string); |
146 url, max_docs, start_changestamp, search_string); | |
147 } | 143 } |
148 | 144 |
149 GURL GDataWapiUrlGenerator::GenerateDocumentEntryUrl( | 145 GURL GDataWapiUrlGenerator::GenerateDocumentEntryUrl( |
150 const std::string& resource_id) const { | 146 const std::string& resource_id) const { |
151 GURL result = base_url_.Resolve( | 147 GURL result = base_url_.Resolve( |
152 base::StringPrintf(kGetDocumentEntryURLFormat, | 148 base::StringPrintf(kGetDocumentEntryURLFormat, |
153 net::EscapePath(resource_id).c_str())); | 149 net::EscapePath(resource_id).c_str())); |
154 return gdata_wapi_url_util::AddStandardUrlParams(result); | 150 return AddStandardUrlParams(result); |
155 } | 151 } |
156 | 152 |
157 GURL GDataWapiUrlGenerator::GenerateDocumentListRootUrl() const { | 153 GURL GDataWapiUrlGenerator::GenerateDocumentListRootUrl() const { |
158 return gdata_wapi_url_util::AddStandardUrlParams( | 154 return AddStandardUrlParams(base_url_.Resolve(kDocumentListRootURL)); |
159 base_url_.Resolve(kDocumentListRootURL)); | |
160 } | 155 } |
161 | 156 |
162 GURL GDataWapiUrlGenerator::GenerateAccountMetadataUrl() const { | 157 GURL GDataWapiUrlGenerator::GenerateAccountMetadataUrl() const { |
163 return gdata_wapi_url_util::AddMetadataUrlParams( | 158 return AddMetadataUrlParams(base_url_.Resolve(kAccountMetadataURL)); |
164 base_url_.Resolve(kAccountMetadataURL)); | |
165 } | 159 } |
166 | 160 |
167 } // namespace google_apis | 161 } // namespace google_apis |
OLD | NEW |