| 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/predictors/autocomplete_action_predictor.h" | 5 #include "chrome/browser/predictors/autocomplete_action_predictor.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 typedef AutocompleteActionPredictor::DBCacheValue DBCacheValue; | 120 typedef AutocompleteActionPredictor::DBCacheValue DBCacheValue; |
| 121 typedef AutocompleteActionPredictor::DBCacheMap DBCacheMap; | 121 typedef AutocompleteActionPredictor::DBCacheMap DBCacheMap; |
| 122 typedef AutocompleteActionPredictor::DBIdCacheMap DBIdCacheMap; | 122 typedef AutocompleteActionPredictor::DBIdCacheMap DBIdCacheMap; |
| 123 | 123 |
| 124 void AddAllRowsToHistory() { | 124 void AddAllRowsToHistory() { |
| 125 for (size_t i = 0; i < arraysize(test_url_db); ++i) | 125 for (size_t i = 0; i < arraysize(test_url_db); ++i) |
| 126 ASSERT_TRUE(AddRowToHistory(test_url_db[i])); | 126 ASSERT_TRUE(AddRowToHistory(test_url_db[i])); |
| 127 } | 127 } |
| 128 | 128 |
| 129 history::URLID AddRowToHistory(const TestUrlInfo& test_row) { | 129 history::URLID AddRowToHistory(const TestUrlInfo& test_row) { |
| 130 HistoryService* history = | 130 HistoryService* history = HistoryServiceFactory::GetForProfile( |
| 131 HistoryServiceFactory::GetForProfile(profile_.get(), | 131 profile_.get(), ServiceAccessType::EXPLICIT_ACCESS); |
| 132 Profile::EXPLICIT_ACCESS); | |
| 133 CHECK(history); | 132 CHECK(history); |
| 134 history::URLDatabase* url_db = history->InMemoryDatabase(); | 133 history::URLDatabase* url_db = history->InMemoryDatabase(); |
| 135 CHECK(url_db); | 134 CHECK(url_db); |
| 136 | 135 |
| 137 const base::Time visit_time = | 136 const base::Time visit_time = |
| 138 base::Time::Now() - base::TimeDelta::FromDays( | 137 base::Time::Now() - base::TimeDelta::FromDays( |
| 139 test_row.days_from_now); | 138 test_row.days_from_now); |
| 140 | 139 |
| 141 history::URLRow row(test_row.url); | 140 history::URLRow row(test_row.url); |
| 142 row.set_title(test_row.title); | 141 row.set_title(test_row.title); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 void DeleteAllRows() { | 181 void DeleteAllRows() { |
| 183 predictor_->DeleteAllRows(); | 182 predictor_->DeleteAllRows(); |
| 184 } | 183 } |
| 185 | 184 |
| 186 void DeleteRowsWithURLs(const history::URLRows& rows) { | 185 void DeleteRowsWithURLs(const history::URLRows& rows) { |
| 187 predictor_->DeleteRowsWithURLs(rows); | 186 predictor_->DeleteRowsWithURLs(rows); |
| 188 } | 187 } |
| 189 | 188 |
| 190 void DeleteOldIdsFromCaches( | 189 void DeleteOldIdsFromCaches( |
| 191 std::vector<AutocompleteActionPredictorTable::Row::Id>* id_list) { | 190 std::vector<AutocompleteActionPredictorTable::Row::Id>* id_list) { |
| 192 HistoryService* history_service = | 191 HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
| 193 HistoryServiceFactory::GetForProfile(profile_.get(), | 192 profile_.get(), ServiceAccessType::EXPLICIT_ACCESS); |
| 194 Profile::EXPLICIT_ACCESS); | |
| 195 ASSERT_TRUE(history_service); | 193 ASSERT_TRUE(history_service); |
| 196 | 194 |
| 197 history::URLDatabase* url_db = history_service->InMemoryDatabase(); | 195 history::URLDatabase* url_db = history_service->InMemoryDatabase(); |
| 198 ASSERT_TRUE(url_db); | 196 ASSERT_TRUE(url_db); |
| 199 | 197 |
| 200 // Reset the predictor's |initialized_| flag for the life of this call, | 198 // Reset the predictor's |initialized_| flag for the life of this call, |
| 201 // since outside of testing this function is only supposed to be reached | 199 // since outside of testing this function is only supposed to be reached |
| 202 // before initialization is completed. | 200 // before initialization is completed. |
| 203 base::AutoReset<bool> initialized_reset(&predictor_->initialized_, false); | 201 base::AutoReset<bool> initialized_reset(&predictor_->initialized_, false); |
| 204 predictor_->DeleteOldIdsFromCaches(url_db, id_list); | 202 predictor_->DeleteOldIdsFromCaches(url_db, id_list); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 AutocompleteActionPredictor::ACTION_PRERENDER) ? | 373 AutocompleteActionPredictor::ACTION_PRERENDER) ? |
| 376 AutocompleteActionPredictor::ACTION_PRECONNECT : | 374 AutocompleteActionPredictor::ACTION_PRECONNECT : |
| 377 test_url_db[i].expected_action; | 375 test_url_db[i].expected_action; |
| 378 EXPECT_EQ(expected_action, | 376 EXPECT_EQ(expected_action, |
| 379 predictor()->RecommendAction(test_url_db[i].user_text, match)) | 377 predictor()->RecommendAction(test_url_db[i].user_text, match)) |
| 380 << "Unexpected action for " << match.destination_url; | 378 << "Unexpected action for " << match.destination_url; |
| 381 } | 379 } |
| 382 } | 380 } |
| 383 | 381 |
| 384 } // namespace predictors | 382 } // namespace predictors |
| OLD | NEW |