Chromium Code Reviews| 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" |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 | 33 |
| 34 const char kHistoryOAuthScope[] = | 34 const char kHistoryOAuthScope[] = |
| 35 "https://www.googleapis.com/auth/chromesync"; | 35 "https://www.googleapis.com/auth/chromesync"; |
| 36 | 36 |
| 37 const char kHistoryQueryHistoryUrl[] = | 37 const char kHistoryQueryHistoryUrl[] = |
| 38 "https://history.google.com/history/api/lookup?client=chrome"; | 38 "https://history.google.com/history/api/lookup?client=chrome"; |
| 39 | 39 |
| 40 const char kHistoryDeleteHistoryUrl[] = | 40 const char kHistoryDeleteHistoryUrl[] = |
| 41 "https://history.google.com/history/api/delete?client=chrome"; | 41 "https://history.google.com/history/api/delete?client=chrome"; |
| 42 | 42 |
| 43 const char kHistoryAudioHistoryUrl[] = | |
| 44 "https://history.google.com/history/api/lookup?client=audio"; | |
| 45 | |
| 46 const char kHistoryAudioHistoryChangeUrl[] = | |
| 47 "https://history.google.com/history/api/change"; | |
| 48 | |
| 43 const char kPostDataMimeType[] = "text/plain"; | 49 const char kPostDataMimeType[] = "text/plain"; |
| 44 | 50 |
| 45 // The maximum number of retries for the URLFetcher requests. | 51 // The maximum number of retries for the URLFetcher requests. |
| 46 const size_t kMaxRetries = 1; | 52 const size_t kMaxRetries = 1; |
| 47 | 53 |
| 48 class RequestImpl : public WebHistoryService::Request, | 54 class RequestImpl : public WebHistoryService::Request, |
| 49 private OAuth2TokenService::Consumer, | 55 private OAuth2TokenService::Consumer, |
| 50 private net::URLFetcherDelegate { | 56 private net::URLFetcherDelegate { |
| 51 public: | 57 public: |
| 52 ~RequestImpl() override {} | 58 ~RequestImpl() override {} |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 WebHistoryService::Request::~Request() { | 302 WebHistoryService::Request::~Request() { |
| 297 } | 303 } |
| 298 | 304 |
| 299 WebHistoryService::WebHistoryService(Profile* profile) | 305 WebHistoryService::WebHistoryService(Profile* profile) |
| 300 : profile_(profile), | 306 : profile_(profile), |
| 301 weak_ptr_factory_(this) { | 307 weak_ptr_factory_(this) { |
| 302 } | 308 } |
| 303 | 309 |
| 304 WebHistoryService::~WebHistoryService() { | 310 WebHistoryService::~WebHistoryService() { |
| 305 STLDeleteElements(&pending_expire_requests_); | 311 STLDeleteElements(&pending_expire_requests_); |
| 312 STLDeleteElements(&pending_audio_history_requests_); | |
| 306 } | 313 } |
| 307 | 314 |
| 308 scoped_ptr<WebHistoryService::Request> WebHistoryService::QueryHistory( | 315 scoped_ptr<WebHistoryService::Request> WebHistoryService::QueryHistory( |
| 309 const base::string16& text_query, | 316 const base::string16& text_query, |
| 310 const QueryOptions& options, | 317 const QueryOptions& options, |
| 311 const WebHistoryService::QueryWebHistoryCallback& callback) { | 318 const WebHistoryService::QueryWebHistoryCallback& callback) { |
| 312 // Wrap the original callback into a generic completion callback. | 319 // Wrap the original callback into a generic completion callback. |
| 313 RequestImpl::CompletionCallback completion_callback = base::Bind( | 320 RequestImpl::CompletionCallback completion_callback = base::Bind( |
| 314 &WebHistoryService::QueryHistoryCompletionCallback, callback); | 321 &WebHistoryService::QueryHistoryCompletionCallback, callback); |
| 315 | 322 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 base::Time begin_time, | 382 base::Time begin_time, |
| 376 base::Time end_time, | 383 base::Time end_time, |
| 377 const ExpireWebHistoryCallback& callback) { | 384 const ExpireWebHistoryCallback& callback) { |
| 378 std::vector<ExpireHistoryArgs> expire_list(1); | 385 std::vector<ExpireHistoryArgs> expire_list(1); |
| 379 expire_list.back().urls = restrict_urls; | 386 expire_list.back().urls = restrict_urls; |
| 380 expire_list.back().begin_time = begin_time; | 387 expire_list.back().begin_time = begin_time; |
| 381 expire_list.back().end_time = end_time; | 388 expire_list.back().end_time = end_time; |
| 382 ExpireHistory(expire_list, callback); | 389 ExpireHistory(expire_list, callback); |
| 383 } | 390 } |
| 384 | 391 |
| 392 void WebHistoryService::GetAudioHistoryEnabled( | |
| 393 const AudioWebHistoryCallback& callback) { | |
| 394 // Wrap the original callback into a generic completion callback. | |
| 395 RequestImpl::CompletionCallback completion_callback = | |
| 396 base::Bind(&WebHistoryService::AudioHistoryCompletionCallback, | |
| 397 weak_ptr_factory_.GetWeakPtr(), | |
| 398 callback); | |
| 399 | |
| 400 GURL url(kHistoryAudioHistoryUrl); | |
| 401 scoped_ptr<RequestImpl> request( | |
| 402 new RequestImpl(profile_, url, completion_callback)); | |
| 403 request->Start(); | |
| 404 pending_audio_history_requests_.insert(request.release()); | |
| 405 } | |
| 406 | |
| 407 void WebHistoryService::SetAudioHistoryEnabled( | |
| 408 bool new_enabled_value, | |
| 409 const AudioWebHistoryCallback& callback) { | |
| 410 // Wrap the original callback into a generic completion callback. | |
| 411 RequestImpl::CompletionCallback completion_callback = | |
| 412 base::Bind(&WebHistoryService::AudioHistoryCompletionCallback, | |
| 413 weak_ptr_factory_.GetWeakPtr(), | |
| 414 callback); | |
| 415 | |
| 416 GURL url(kHistoryAudioHistoryChangeUrl); | |
| 417 scoped_ptr<RequestImpl> request( | |
| 418 new RequestImpl(profile_, url, completion_callback)); | |
| 419 | |
| 420 base::DictionaryValue enable_audio_history; | |
| 421 enable_audio_history.SetBoolean("enable_history_recording", | |
| 422 new_enabled_value); | |
| 423 enable_audio_history.SetString("client", "audio"); | |
| 424 std::string post_data; | |
| 425 base::JSONWriter::Write(&enable_audio_history, &post_data); | |
| 426 request->set_post_data(post_data); | |
| 427 | |
| 428 request->Start(); | |
| 429 pending_audio_history_requests_.insert(request.release()); | |
| 430 } | |
| 431 | |
| 385 // static | 432 // static |
| 386 void WebHistoryService::QueryHistoryCompletionCallback( | 433 void WebHistoryService::QueryHistoryCompletionCallback( |
| 387 const WebHistoryService::QueryWebHistoryCallback& callback, | 434 const WebHistoryService::QueryWebHistoryCallback& callback, |
| 388 WebHistoryService::Request* request, | 435 WebHistoryService::Request* request, |
| 389 bool success) { | 436 bool success) { |
| 390 scoped_ptr<base::DictionaryValue> response_value; | 437 scoped_ptr<base::DictionaryValue> response_value; |
| 391 if (success) | 438 if (success) |
| 392 response_value = ReadResponse(static_cast<RequestImpl*>(request)); | 439 response_value = ReadResponse(static_cast<RequestImpl*>(request)); |
| 393 callback.Run(request, response_value.get()); | 440 callback.Run(request, response_value.get()); |
| 394 } | 441 } |
| 395 | 442 |
| 396 void WebHistoryService::ExpireHistoryCompletionCallback( | 443 void WebHistoryService::ExpireHistoryCompletionCallback( |
| 397 const WebHistoryService::ExpireWebHistoryCallback& callback, | 444 const WebHistoryService::ExpireWebHistoryCallback& callback, |
| 398 WebHistoryService::Request* request, | 445 WebHistoryService::Request* request, |
| 399 bool success) { | 446 bool success) { |
| 400 scoped_ptr<base::DictionaryValue> response_value; | 447 scoped_ptr<base::DictionaryValue> response_value; |
| 401 if (success) { | 448 if (success) { |
| 402 response_value = ReadResponse(static_cast<RequestImpl*>(request)); | 449 response_value = ReadResponse(static_cast<RequestImpl*>(request)); |
| 403 if (response_value) | 450 if (response_value) |
| 404 response_value->GetString("version_info", &server_version_info_); | 451 response_value->GetString("version_info", &server_version_info_); |
| 405 } | 452 } |
| 406 callback.Run(response_value.get() && success); | 453 callback.Run(response_value.get() && success); |
| 407 // Clean up from pending requests. | 454 // Clean up from pending requests. |
| 408 pending_expire_requests_.erase(request); | 455 pending_expire_requests_.erase(request); |
| 409 delete request; | 456 delete request; |
| 410 } | 457 } |
| 411 | 458 |
| 459 void WebHistoryService::AudioHistoryCompletionCallback( | |
| 460 const WebHistoryService::AudioWebHistoryCallback& callback, | |
| 461 WebHistoryService::Request* request, | |
| 462 bool success) { | |
| 463 scoped_ptr<base::DictionaryValue> response_value; | |
| 464 bool enabled_value = false; | |
| 465 if (success) { | |
| 466 response_value = ReadResponse(static_cast<RequestImpl*>(request)); | |
| 467 if (response_value) | |
| 468 response_value->GetBoolean("history_recording_enabled", &enabled_value); | |
| 469 } | |
| 470 callback.Run(success, enabled_value); | |
| 471 pending_audio_history_requests_.erase(request); | |
|
sky
2014/11/11 20:30:10
Does this leak request?
rpetterson
2014/11/11 22:29:16
No, it should not. We use the pending_audio_histor
sky
2014/11/12 00:46:32
Where is the delete? From what I see you erase the
rpetterson
2014/11/12 00:58:42
Whoops. It's back.
| |
| 472 } | |
| 473 | |
| 412 } // namespace history | 474 } // namespace history |
| OLD | NEW |