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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/stl_util.h" |
11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
13 #include "base/values.h" | 14 #include "base/values.h" |
14 #include "chrome/browser/signin/profile_oauth2_token_service.h" | 15 #include "chrome/browser/signin/profile_oauth2_token_service.h" |
15 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
16 #include "chrome/browser/signin/signin_manager.h" | 17 #include "chrome/browser/signin/signin_manager.h" |
17 #include "chrome/browser/signin/signin_manager_factory.h" | 18 #include "chrome/browser/signin/signin_manager_factory.h" |
18 #include "google_apis/gaia/gaia_urls.h" | 19 #include "google_apis/gaia/gaia_urls.h" |
19 #include "google_apis/gaia/google_service_auth_error.h" | 20 #include "google_apis/gaia/google_service_auth_error.h" |
20 #include "google_apis/gaia/oauth2_token_service.h" | 21 #include "google_apis/gaia/oauth2_token_service.h" |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 | 298 |
298 WebHistoryService::Request::~Request() { | 299 WebHistoryService::Request::~Request() { |
299 } | 300 } |
300 | 301 |
301 WebHistoryService::WebHistoryService(Profile* profile) | 302 WebHistoryService::WebHistoryService(Profile* profile) |
302 : profile_(profile), | 303 : profile_(profile), |
303 weak_ptr_factory_(this) { | 304 weak_ptr_factory_(this) { |
304 } | 305 } |
305 | 306 |
306 WebHistoryService::~WebHistoryService() { | 307 WebHistoryService::~WebHistoryService() { |
| 308 STLDeleteElements(&pending_expire_requests_); |
307 } | 309 } |
308 | 310 |
309 scoped_ptr<WebHistoryService::Request> WebHistoryService::QueryHistory( | 311 scoped_ptr<WebHistoryService::Request> WebHistoryService::QueryHistory( |
310 const base::string16& text_query, | 312 const base::string16& text_query, |
311 const QueryOptions& options, | 313 const QueryOptions& options, |
312 const WebHistoryService::QueryWebHistoryCallback& callback) { | 314 const WebHistoryService::QueryWebHistoryCallback& callback) { |
313 // Wrap the original callback into a generic completion callback. | 315 // Wrap the original callback into a generic completion callback. |
314 RequestImpl::CompletionCallback completion_callback = base::Bind( | 316 RequestImpl::CompletionCallback completion_callback = base::Bind( |
315 &WebHistoryService::QueryHistoryCompletionCallback, callback); | 317 &WebHistoryService::QueryHistoryCompletionCallback, callback); |
316 | 318 |
317 GURL url = GetQueryUrl(text_query, options, server_version_info_); | 319 GURL url = GetQueryUrl(text_query, options, server_version_info_); |
318 scoped_ptr<RequestImpl> request( | 320 scoped_ptr<RequestImpl> request( |
319 new RequestImpl(profile_, url, completion_callback)); | 321 new RequestImpl(profile_, url, completion_callback)); |
320 request->Start(); | 322 request->Start(); |
321 return request.PassAs<Request>(); | 323 return request.PassAs<Request>(); |
322 } | 324 } |
323 | 325 |
324 scoped_ptr<WebHistoryService::Request> WebHistoryService::ExpireHistory( | 326 void WebHistoryService::ExpireHistory( |
325 const std::vector<ExpireHistoryArgs>& expire_list, | 327 const std::vector<ExpireHistoryArgs>& expire_list, |
326 const ExpireWebHistoryCallback& callback) { | 328 const ExpireWebHistoryCallback& callback) { |
327 base::DictionaryValue delete_request; | 329 base::DictionaryValue delete_request; |
328 scoped_ptr<base::ListValue> deletions(new base::ListValue); | 330 scoped_ptr<base::ListValue> deletions(new base::ListValue); |
329 base::Time now = base::Time::Now(); | 331 base::Time now = base::Time::Now(); |
330 | 332 |
331 for (std::vector<ExpireHistoryArgs>::const_iterator it = expire_list.begin(); | 333 for (std::vector<ExpireHistoryArgs>::const_iterator it = expire_list.begin(); |
332 it != expire_list.end(); ++it) { | 334 it != expire_list.end(); ++it) { |
333 // Convert the times to server timestamps. | 335 // Convert the times to server timestamps. |
334 std::string min_timestamp = ServerTimeString(it->begin_time); | 336 std::string min_timestamp = ServerTimeString(it->begin_time); |
(...skipping 26 matching lines...) Expand all Loading... |
361 // Wrap the original callback into a generic completion callback. | 363 // Wrap the original callback into a generic completion callback. |
362 RequestImpl::CompletionCallback completion_callback = | 364 RequestImpl::CompletionCallback completion_callback = |
363 base::Bind(&WebHistoryService::ExpireHistoryCompletionCallback, | 365 base::Bind(&WebHistoryService::ExpireHistoryCompletionCallback, |
364 weak_ptr_factory_.GetWeakPtr(), | 366 weak_ptr_factory_.GetWeakPtr(), |
365 callback); | 367 callback); |
366 | 368 |
367 scoped_ptr<RequestImpl> request( | 369 scoped_ptr<RequestImpl> request( |
368 new RequestImpl(profile_, url, completion_callback)); | 370 new RequestImpl(profile_, url, completion_callback)); |
369 request->set_post_data(post_data); | 371 request->set_post_data(post_data); |
370 request->Start(); | 372 request->Start(); |
371 return request.PassAs<Request>(); | 373 pending_expire_requests_.insert(request.release()); |
372 } | 374 } |
373 | 375 |
374 scoped_ptr<WebHistoryService::Request> WebHistoryService::ExpireHistoryBetween( | 376 void WebHistoryService::ExpireHistoryBetween( |
375 const std::set<GURL>& restrict_urls, | 377 const std::set<GURL>& restrict_urls, |
376 base::Time begin_time, | 378 base::Time begin_time, |
377 base::Time end_time, | 379 base::Time end_time, |
378 const ExpireWebHistoryCallback& callback) { | 380 const ExpireWebHistoryCallback& callback) { |
379 std::vector<ExpireHistoryArgs> expire_list(1); | 381 std::vector<ExpireHistoryArgs> expire_list(1); |
380 expire_list.back().urls = restrict_urls; | 382 expire_list.back().urls = restrict_urls; |
381 expire_list.back().begin_time = begin_time; | 383 expire_list.back().begin_time = begin_time; |
382 expire_list.back().end_time = end_time; | 384 expire_list.back().end_time = end_time; |
383 return ExpireHistory(expire_list, callback); | 385 ExpireHistory(expire_list, callback); |
384 } | 386 } |
385 | 387 |
386 // static | 388 // static |
387 void WebHistoryService::QueryHistoryCompletionCallback( | 389 void WebHistoryService::QueryHistoryCompletionCallback( |
388 const WebHistoryService::QueryWebHistoryCallback& callback, | 390 const WebHistoryService::QueryWebHistoryCallback& callback, |
389 WebHistoryService::Request* request, | 391 WebHistoryService::Request* request, |
390 bool success) { | 392 bool success) { |
391 scoped_ptr<base::DictionaryValue> response_value; | 393 scoped_ptr<base::DictionaryValue> response_value; |
392 if (success) | 394 if (success) |
393 response_value = ReadResponse(static_cast<RequestImpl*>(request)); | 395 response_value = ReadResponse(static_cast<RequestImpl*>(request)); |
394 callback.Run(request, response_value.get()); | 396 callback.Run(request, response_value.get()); |
395 } | 397 } |
396 | 398 |
397 void WebHistoryService::ExpireHistoryCompletionCallback( | 399 void WebHistoryService::ExpireHistoryCompletionCallback( |
398 const WebHistoryService::ExpireWebHistoryCallback& callback, | 400 const WebHistoryService::ExpireWebHistoryCallback& callback, |
399 WebHistoryService::Request* request, | 401 WebHistoryService::Request* request, |
400 bool success) { | 402 bool success) { |
401 scoped_ptr<base::DictionaryValue> response_value; | 403 scoped_ptr<base::DictionaryValue> response_value; |
402 if (success) { | 404 if (success) { |
403 response_value = ReadResponse(static_cast<RequestImpl*>(request)); | 405 response_value = ReadResponse(static_cast<RequestImpl*>(request)); |
404 if (response_value) | 406 if (response_value) |
405 response_value->GetString("version_info", &server_version_info_); | 407 response_value->GetString("version_info", &server_version_info_); |
406 } | 408 } |
407 callback.Run(request, response_value.get() && success); | 409 callback.Run(response_value.get() && success); |
| 410 // Clean up from pending requests. |
| 411 pending_expire_requests_.erase(request); |
| 412 delete request; |
408 } | 413 } |
409 | 414 |
410 } // namespace history | 415 } // namespace history |
OLD | NEW |