| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/in_memory_url_index.h" | 5 #include "chrome/browser/history/in_memory_url_index.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 const GURL& gurl(row.url()); | 164 const GURL& gurl(row.url()); |
| 165 | 165 |
| 166 // Index only URLs with a whitelisted scheme. | 166 // Index only URLs with a whitelisted scheme. |
| 167 if (!InMemoryURLIndex::URLSchemeIsWhitelisted(gurl)) | 167 if (!InMemoryURLIndex::URLSchemeIsWhitelisted(gurl)) |
| 168 return; | 168 return; |
| 169 | 169 |
| 170 URLID row_id = row.id(); | 170 URLID row_id = row.id(); |
| 171 // Strip out username and password before saving and indexing. | 171 // Strip out username and password before saving and indexing. |
| 172 string16 url(net::FormatUrl(gurl, languages_, | 172 string16 url(net::FormatUrl(gurl, languages_, |
| 173 net::kFormatUrlOmitUsernamePassword, | 173 net::kFormatUrlOmitUsernamePassword, |
| 174 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS, | 174 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS, |
| 175 NULL, NULL, NULL)); | 175 NULL, NULL, NULL)); |
| 176 | 176 |
| 177 HistoryID history_id = static_cast<HistoryID>(row_id); | 177 HistoryID history_id = static_cast<HistoryID>(row_id); |
| 178 DCHECK_LT(history_id, std::numeric_limits<HistoryID>::max()); | 178 DCHECK_LT(history_id, std::numeric_limits<HistoryID>::max()); |
| 179 | 179 |
| 180 // Add the row for quick lookup in the history info store. | 180 // Add the row for quick lookup in the history info store. |
| 181 URLRow new_row(GURL(url), row_id); | 181 URLRow new_row(GURL(url), row_id); |
| 182 new_row.set_visit_count(row.visit_count()); | 182 new_row.set_visit_count(row.visit_count()); |
| 183 new_row.set_typed_count(row.typed_count()); | 183 new_row.set_typed_count(row.typed_count()); |
| 184 new_row.set_last_visit(row.last_visit()); | 184 new_row.set_last_visit(row.last_visit()); |
| 185 new_row.set_title(row.title()); | 185 new_row.set_title(row.title()); |
| 186 private_data_->history_info_map_[history_id] = new_row; | 186 private_data_->history_info_map_[history_id] = new_row; |
| 187 | 187 |
| 188 // Index the words contained in the URL and title of the row. | 188 // Index the words contained in the URL and title of the row. |
| 189 AddRowWordsToIndex(new_row); | 189 AddRowWordsToIndex(new_row); |
| 190 return; | 190 return; |
| 191 } | 191 } |
| 192 | 192 |
| 193 void InMemoryURLIndex::AddRowWordsToIndex(const URLRow& row) { | 193 void InMemoryURLIndex::AddRowWordsToIndex(const URLRow& row) { |
| 194 HistoryID history_id = static_cast<HistoryID>(row.id()); | 194 HistoryID history_id = static_cast<HistoryID>(row.id()); |
| 195 // Split URL into individual, unique words then add in the title words. | 195 // Split URL into individual, unique words then add in the title words. |
| 196 const GURL& gurl(row.url()); | 196 const GURL& gurl(row.url()); |
| 197 string16 url(net::FormatUrl(gurl, languages_, | 197 string16 url(net::FormatUrl(gurl, languages_, |
| 198 net::kFormatUrlOmitUsernamePassword, | 198 net::kFormatUrlOmitUsernamePassword, |
| 199 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS, | 199 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS, |
| 200 NULL, NULL, NULL)); | 200 NULL, NULL, NULL)); |
| 201 url = base::i18n::ToLower(url); | 201 url = base::i18n::ToLower(url); |
| 202 String16Set url_words = String16SetFromString16(url); | 202 String16Set url_words = String16SetFromString16(url); |
| 203 String16Set title_words = String16SetFromString16(row.title()); | 203 String16Set title_words = String16SetFromString16(row.title()); |
| 204 String16Set words; | 204 String16Set words; |
| 205 std::set_union(url_words.begin(), url_words.end(), | 205 std::set_union(url_words.begin(), url_words.end(), |
| 206 title_words.begin(), title_words.end(), | 206 title_words.begin(), title_words.end(), |
| 207 std::insert_iterator<String16Set>(words, words.begin())); | 207 std::insert_iterator<String16Set>(words, words.begin())); |
| 208 for (String16Set::iterator word_iter = words.begin(); | 208 for (String16Set::iterator word_iter = words.begin(); |
| 209 word_iter != words.end(); ++word_iter) | 209 word_iter != words.end(); ++word_iter) |
| (...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 if (iter->has_title()) { | 1069 if (iter->has_title()) { |
| 1070 string16 title(UTF8ToUTF16(iter->title())); | 1070 string16 title(UTF8ToUTF16(iter->title())); |
| 1071 url_row.set_title(title); | 1071 url_row.set_title(title); |
| 1072 } | 1072 } |
| 1073 private_data_->history_info_map_[history_id] = url_row; | 1073 private_data_->history_info_map_[history_id] = url_row; |
| 1074 } | 1074 } |
| 1075 return true; | 1075 return true; |
| 1076 } | 1076 } |
| 1077 | 1077 |
| 1078 } // namespace history | 1078 } // namespace history |
| OLD | NEW |