| 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/history/web_history_service.h" | 5 #include "chrome/browser/history/web_history_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/utf_string_conversions.h" |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "chrome/browser/signin/oauth2_token_service.h" | 13 #include "chrome/browser/signin/oauth2_token_service.h" |
| 13 #include "chrome/browser/signin/oauth2_token_service_factory.h" | 14 #include "chrome/browser/signin/oauth2_token_service_factory.h" |
| 14 #include "google_apis/gaia/gaia_urls.h" | 15 #include "google_apis/gaia/gaia_urls.h" |
| 15 #include "google_apis/gaia/google_service_auth_error.h" | 16 #include "google_apis/gaia/google_service_auth_error.h" |
| 16 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 17 #include "net/base/load_flags.h" | 18 #include "net/base/load_flags.h" |
| 18 #include "net/base/url_util.h" | 19 #include "net/base/url_util.h" |
| 19 #include "net/http/http_status_code.h" | 20 #include "net/http/http_status_code.h" |
| 20 #include "net/url_request/url_fetcher.h" | 21 #include "net/url_request/url_fetcher.h" |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } | 171 } |
| 171 | 172 |
| 172 // Converts a time into a string for use as a parameter in a request to the | 173 // Converts a time into a string for use as a parameter in a request to the |
| 173 // history server. | 174 // history server. |
| 174 std::string ServerTimeString(base::Time time) { | 175 std::string ServerTimeString(base::Time time) { |
| 175 return base::Int64ToString((time - base::Time::UnixEpoch()).InMicroseconds()); | 176 return base::Int64ToString((time - base::Time::UnixEpoch()).InMicroseconds()); |
| 176 } | 177 } |
| 177 | 178 |
| 178 // Returns a URL for querying the history server for a query specified by | 179 // Returns a URL for querying the history server for a query specified by |
| 179 // |options|. | 180 // |options|. |
| 180 std::string GetQueryUrl(const QueryOptions& options) { | 181 std::string GetQueryUrl(const string16& text_query, |
| 182 const QueryOptions& options) { |
| 181 GURL url = GURL(kHistoryQueryHistoryUrl); | 183 GURL url = GURL(kHistoryQueryHistoryUrl); |
| 182 url = net::AppendQueryParameter(url, "titles", "1"); | 184 url = net::AppendQueryParameter(url, "titles", "1"); |
| 183 | 185 |
| 184 // Take |begin_time|, |end_time|, and |max_count| from the original query | 186 // Take |begin_time|, |end_time|, and |max_count| from the original query |
| 185 // options, and convert them to the equivalent URL parameters. | 187 // options, and convert them to the equivalent URL parameters. |
| 186 | 188 |
| 187 base::Time end_time = | 189 base::Time end_time = |
| 188 std::min(base::Time::FromInternalValue(options.EffectiveEndTime()), | 190 std::min(base::Time::FromInternalValue(options.EffectiveEndTime()), |
| 189 base::Time::Now()); | 191 base::Time::Now()); |
| 190 url = net::AppendQueryParameter(url, "max", ServerTimeString(end_time)); | 192 url = net::AppendQueryParameter(url, "max", ServerTimeString(end_time)); |
| 191 | 193 |
| 192 if (!options.begin_time.is_null()) { | 194 if (!options.begin_time.is_null()) { |
| 193 url = net::AppendQueryParameter( | 195 url = net::AppendQueryParameter( |
| 194 url, "min", ServerTimeString(options.begin_time)); | 196 url, "min", ServerTimeString(options.begin_time)); |
| 195 } | 197 } |
| 196 | 198 |
| 197 if (options.max_count) { | 199 if (options.max_count) { |
| 198 url = net::AppendQueryParameter( | 200 url = net::AppendQueryParameter( |
| 199 url, "num", base::IntToString(options.max_count)); | 201 url, "num", base::IntToString(options.max_count)); |
| 200 } | 202 } |
| 201 | 203 |
| 204 if (!text_query.empty()) |
| 205 url = net::AppendQueryParameter(url, "q", UTF16ToUTF8(text_query)); |
| 206 |
| 202 return url.spec(); | 207 return url.spec(); |
| 203 } | 208 } |
| 204 | 209 |
| 205 // Creates a DictionaryValue to hold the parameters for a deletion. | 210 // Creates a DictionaryValue to hold the parameters for a deletion. |
| 206 // Ownership is passed to the caller. | 211 // Ownership is passed to the caller. |
| 207 // |url| may be empty, indicating a time-range deletion. | 212 // |url| may be empty, indicating a time-range deletion. |
| 208 DictionaryValue* CreateDeletion( | 213 DictionaryValue* CreateDeletion( |
| 209 const std::string& min_time, | 214 const std::string& min_time, |
| 210 const std::string& max_time, | 215 const std::string& max_time, |
| 211 const GURL& url) { | 216 const GURL& url) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 234 } | 239 } |
| 235 | 240 |
| 236 scoped_ptr<WebHistoryService::Request> WebHistoryService::QueryHistory( | 241 scoped_ptr<WebHistoryService::Request> WebHistoryService::QueryHistory( |
| 237 const string16& text_query, | 242 const string16& text_query, |
| 238 const QueryOptions& options, | 243 const QueryOptions& options, |
| 239 const WebHistoryService::QueryWebHistoryCallback& callback) { | 244 const WebHistoryService::QueryWebHistoryCallback& callback) { |
| 240 // Wrap the original callback into a generic completion callback. | 245 // Wrap the original callback into a generic completion callback. |
| 241 RequestImpl::CompletionCallback completion_callback = base::Bind( | 246 RequestImpl::CompletionCallback completion_callback = base::Bind( |
| 242 &QueryHistoryCompletionCallback, callback); | 247 &QueryHistoryCompletionCallback, callback); |
| 243 | 248 |
| 249 std::string url = GetQueryUrl(text_query, options); |
| 244 scoped_ptr<RequestImpl> request( | 250 scoped_ptr<RequestImpl> request( |
| 245 new RequestImpl(profile_, GetQueryUrl(options), completion_callback)); | 251 new RequestImpl(profile_, url, completion_callback)); |
| 246 request->Start(); | 252 request->Start(); |
| 247 return request.PassAs<Request>(); | 253 return request.PassAs<Request>(); |
| 248 } | 254 } |
| 249 | 255 |
| 250 scoped_ptr<WebHistoryService::Request> WebHistoryService::ExpireHistory( | 256 scoped_ptr<WebHistoryService::Request> WebHistoryService::ExpireHistory( |
| 251 const std::vector<ExpireHistoryArgs>& expire_list, | 257 const std::vector<ExpireHistoryArgs>& expire_list, |
| 252 const ExpireWebHistoryCallback& callback) { | 258 const ExpireWebHistoryCallback& callback) { |
| 253 DictionaryValue delete_request; | 259 DictionaryValue delete_request; |
| 254 scoped_ptr<ListValue> deletions(new ListValue); | 260 scoped_ptr<ListValue> deletions(new ListValue); |
| 255 base::Time now = base::Time::Now(); | 261 base::Time now = base::Time::Now(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 base::Time end_time, | 296 base::Time end_time, |
| 291 const ExpireWebHistoryCallback& callback) { | 297 const ExpireWebHistoryCallback& callback) { |
| 292 std::vector<ExpireHistoryArgs> expire_list(1); | 298 std::vector<ExpireHistoryArgs> expire_list(1); |
| 293 expire_list.back().urls = restrict_urls; | 299 expire_list.back().urls = restrict_urls; |
| 294 expire_list.back().begin_time = begin_time; | 300 expire_list.back().begin_time = begin_time; |
| 295 expire_list.back().end_time = end_time; | 301 expire_list.back().end_time = end_time; |
| 296 return ExpireHistory(expire_list, callback); | 302 return ExpireHistory(expire_list, callback); |
| 297 } | 303 } |
| 298 | 304 |
| 299 } // namespace history | 305 } // namespace history |
| OLD | NEW |