| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "ios/chrome/browser/ui/history/history_service_facade.h" | 5 #import "ios/chrome/browser/ui/history/history_service_facade.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 71 |
| 72 } // namespace | 72 } // namespace |
| 73 | 73 |
| 74 #pragma mark - QueryResult | 74 #pragma mark - QueryResult |
| 75 | 75 |
| 76 HistoryServiceFacade::QueryResult::QueryResult() | 76 HistoryServiceFacade::QueryResult::QueryResult() |
| 77 : query(base::string16()), | 77 : query(base::string16()), |
| 78 query_start_time(base::string16()), | 78 query_start_time(base::string16()), |
| 79 query_end_time(base::string16()), | 79 query_end_time(base::string16()), |
| 80 finished(false), | 80 finished(false), |
| 81 sync_returned(false), |
| 81 has_synced_results(false), | 82 has_synced_results(false), |
| 82 sync_finished(false), | 83 sync_finished(false), |
| 83 entries(std::vector<history::HistoryEntry>()) {} | 84 entries(std::vector<history::HistoryEntry>()) {} |
| 84 | 85 |
| 85 HistoryServiceFacade::QueryResult::QueryResult(const QueryResult& other) = | 86 HistoryServiceFacade::QueryResult::QueryResult(const QueryResult& other) = |
| 86 default; | 87 default; |
| 87 | 88 |
| 88 HistoryServiceFacade::QueryResult::~QueryResult() {} | 89 HistoryServiceFacade::QueryResult::~QueryResult() {} |
| 89 | 90 |
| 90 #pragma mark - RemovedEntry | 91 #pragma mark - RemovedEntry |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 void HistoryServiceFacade::QueryHistory(const base::string16& search_text, | 134 void HistoryServiceFacade::QueryHistory(const base::string16& search_text, |
| 134 const history::QueryOptions& options) { | 135 const history::QueryOptions& options) { |
| 135 // Anything in-flight is invalid. | 136 // Anything in-flight is invalid. |
| 136 query_task_tracker_.TryCancelAll(); | 137 query_task_tracker_.TryCancelAll(); |
| 137 web_history_request_.reset(); | 138 web_history_request_.reset(); |
| 138 | 139 |
| 139 // Reset results. | 140 // Reset results. |
| 140 query_results_.clear(); | 141 query_results_.clear(); |
| 141 results_info_value_ = QueryResult(); | 142 results_info_value_ = QueryResult(); |
| 142 | 143 |
| 143 // Query local history. | |
| 144 history::HistoryService* history_service = | |
| 145 ios::HistoryServiceFactory::GetForBrowserState( | |
| 146 browser_state_, ServiceAccessType::EXPLICIT_ACCESS); | |
| 147 if (history_service) { | |
| 148 history_service->QueryHistory( | |
| 149 search_text, options, | |
| 150 base::Bind(&HistoryServiceFacade::QueryComplete, base::Unretained(this), | |
| 151 search_text, options), | |
| 152 &query_task_tracker_); | |
| 153 } | |
| 154 | |
| 155 // Query synced history. | 144 // Query synced history. |
| 156 history::WebHistoryService* web_history = | 145 history::WebHistoryService* web_history = |
| 157 ios::WebHistoryServiceFactory::GetForBrowserState(browser_state_); | 146 ios::WebHistoryServiceFactory::GetForBrowserState(browser_state_); |
| 158 if (web_history) { | 147 if (web_history) { |
| 159 web_history_query_results_.clear(); | 148 web_history_query_results_.clear(); |
| 160 web_history_request_ = web_history->QueryHistory( | 149 web_history_request_ = web_history->QueryHistory( |
| 161 search_text, options, | 150 search_text, options, |
| 162 base::Bind(&HistoryServiceFacade::WebHistoryQueryComplete, | 151 base::Bind(&HistoryServiceFacade::WebHistoryQueryComplete, |
| 163 base::Unretained(this), search_text, options, | 152 base::Unretained(this), search_text, options, |
| 164 base::TimeTicks::Now())); | 153 base::TimeTicks::Now())); |
| 165 // Start a timer so we know when to give up. | 154 // Start a timer so we know when to give up. |
| 166 web_history_timer_.Start( | 155 web_history_timer_.Start( |
| 167 FROM_HERE, base::TimeDelta::FromSeconds(kWebHistoryTimeoutSeconds), | 156 FROM_HERE, base::TimeDelta::FromSeconds(kWebHistoryTimeoutSeconds), |
| 168 this, &HistoryServiceFacade::WebHistoryTimeout); | 157 this, &HistoryServiceFacade::WebHistoryTimeout); |
| 169 } | 158 } |
| 159 |
| 160 // Query local history. |
| 161 history::HistoryService* history_service = |
| 162 ios::HistoryServiceFactory::GetForBrowserState( |
| 163 browser_state_, ServiceAccessType::EXPLICIT_ACCESS); |
| 164 if (history_service) { |
| 165 history_service->QueryHistory( |
| 166 search_text, options, |
| 167 base::Bind(&HistoryServiceFacade::QueryComplete, base::Unretained(this), |
| 168 search_text, options), |
| 169 &query_task_tracker_); |
| 170 } |
| 170 } | 171 } |
| 171 | 172 |
| 172 void HistoryServiceFacade::RemoveHistoryEntries( | 173 void HistoryServiceFacade::RemoveHistoryEntries( |
| 173 const std::vector<RemovedEntry>& entries) { | 174 const std::vector<RemovedEntry>& entries) { |
| 174 // Early return if there is a deletion in progress. | 175 // Early return if there is a deletion in progress. |
| 175 if (delete_task_tracker_.HasTrackedTasks() || has_pending_delete_request_) { | 176 if (delete_task_tracker_.HasTrackedTasks() || has_pending_delete_request_) { |
| 176 return; | 177 return; |
| 177 } | 178 } |
| 178 | 179 |
| 179 history::HistoryService* history_service = | 180 history::HistoryService* history_service = |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 368 |
| 368 web_history_query_results_.push_back(history::HistoryEntry( | 369 web_history_query_results_.push_back(history::HistoryEntry( |
| 369 history::HistoryEntry::REMOTE_ENTRY, gurl, title, time, client_id, | 370 history::HistoryEntry::REMOTE_ENTRY, gurl, title, time, client_id, |
| 370 !search_text.empty(), base::string16(), | 371 !search_text.empty(), base::string16(), |
| 371 /* blocked_visit */ false)); | 372 /* blocked_visit */ false)); |
| 372 } | 373 } |
| 373 } | 374 } |
| 374 } | 375 } |
| 375 | 376 |
| 376 results_info_value_.has_synced_results = results_value != NULL; | 377 results_info_value_.has_synced_results = results_value != NULL; |
| 378 results_info_value_.sync_returned = true; |
| 377 if (results_value) { | 379 if (results_value) { |
| 378 std::string continuation_token; | 380 std::string continuation_token; |
| 379 results_value->GetString("continuation_token", &continuation_token); | 381 results_value->GetString("continuation_token", &continuation_token); |
| 380 results_info_value_.sync_finished = continuation_token.empty(); | 382 results_info_value_.sync_finished = continuation_token.empty(); |
| 381 } | 383 } |
| 382 if (!query_task_tracker_.HasTrackedTasks()) | 384 if (!query_task_tracker_.HasTrackedTasks()) |
| 383 ReturnResultsToFrontEnd(); | 385 ReturnResultsToFrontEnd(); |
| 384 } | 386 } |
| 385 | 387 |
| 386 void HistoryServiceFacade::RemoveComplete() { | 388 void HistoryServiceFacade::RemoveComplete() { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 const history::URLRows& deleted_rows, | 456 const history::URLRows& deleted_rows, |
| 455 const std::set<GURL>& favicon_urls) { | 457 const std::set<GURL>& favicon_urls) { |
| 456 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) { | 458 if (all_history || DeletionsDiffer(deleted_rows, urls_to_be_deleted_)) { |
| 457 if ([delegate_ | 459 if ([delegate_ |
| 458 respondsToSelector: | 460 respondsToSelector: |
| 459 @selector(historyServiceFacadeDidObserveHistoryDeletion:)]) { | 461 @selector(historyServiceFacadeDidObserveHistoryDeletion:)]) { |
| 460 [delegate_ historyServiceFacadeDidObserveHistoryDeletion:this]; | 462 [delegate_ historyServiceFacadeDidObserveHistoryDeletion:this]; |
| 461 } | 463 } |
| 462 } | 464 } |
| 463 } | 465 } |
| OLD | NEW |