| 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/autocomplete/history_quick_provider.h" | 5 #include "chrome/browser/autocomplete/history_quick_provider.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 #include "components/search_engines/template_url.h" | 39 #include "components/search_engines/template_url.h" |
| 40 #include "components/search_engines/template_url_service.h" | 40 #include "components/search_engines/template_url_service.h" |
| 41 #include "content/public/browser/notification_source.h" | 41 #include "content/public/browser/notification_source.h" |
| 42 #include "content/public/browser/notification_types.h" | 42 #include "content/public/browser/notification_types.h" |
| 43 #include "net/base/escape.h" | 43 #include "net/base/escape.h" |
| 44 #include "net/base/net_util.h" | 44 #include "net/base/net_util.h" |
| 45 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 45 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 46 #include "url/url_parse.h" | 46 #include "url/url_parse.h" |
| 47 #include "url/url_util.h" | 47 #include "url/url_util.h" |
| 48 | 48 |
| 49 using history::InMemoryURLIndex; | |
| 50 using history::ScoredHistoryMatch; | |
| 51 using history::ScoredHistoryMatches; | |
| 52 | |
| 53 namespace { | 49 namespace { |
| 54 | 50 |
| 55 // Returns whether |url| is bookmarked in |bookmark_model| (which can be null | 51 // Returns whether |url| is bookmarked in |bookmark_model| (which can be null |
| 56 // during testing). Used for ScoredHistoryMatchBuilderImpl. | 52 // during testing). Used for ScoredHistoryMatchBuilderImpl. |
| 57 bool IsBookmarked(bookmarks::BookmarkModel* bookmark_model, const GURL& url) { | 53 bool IsBookmarked(bookmarks::BookmarkModel* bookmark_model, const GURL& url) { |
| 58 return bookmark_model && bookmark_model->IsBookmarked(url); | 54 return bookmark_model && bookmark_model->IsBookmarked(url); |
| 59 } | 55 } |
| 60 | 56 |
| 61 } // namespace | 57 } // namespace |
| 62 | 58 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 net::FormatUrl(info.url(), languages_, format_types, | 257 net::FormatUrl(info.url(), languages_, format_types, |
| 262 net::UnescapeRule::SPACES, NULL, NULL, NULL), | 258 net::UnescapeRule::SPACES, NULL, NULL, NULL), |
| 263 ChromeAutocompleteSchemeClassifier(profile_)); | 259 ChromeAutocompleteSchemeClassifier(profile_)); |
| 264 std::vector<size_t> offsets = | 260 std::vector<size_t> offsets = |
| 265 OffsetsFromTermMatches(history_match.url_matches); | 261 OffsetsFromTermMatches(history_match.url_matches); |
| 266 base::OffsetAdjuster::Adjustments adjustments; | 262 base::OffsetAdjuster::Adjustments adjustments; |
| 267 match.contents = net::FormatUrlWithAdjustments( | 263 match.contents = net::FormatUrlWithAdjustments( |
| 268 info.url(), languages_, format_types, net::UnescapeRule::SPACES, NULL, | 264 info.url(), languages_, format_types, net::UnescapeRule::SPACES, NULL, |
| 269 NULL, &adjustments); | 265 NULL, &adjustments); |
| 270 base::OffsetAdjuster::AdjustOffsets(adjustments, &offsets); | 266 base::OffsetAdjuster::AdjustOffsets(adjustments, &offsets); |
| 271 history::TermMatches new_matches = | 267 TermMatches new_matches = |
| 272 ReplaceOffsetsInTermMatches(history_match.url_matches, offsets); | 268 ReplaceOffsetsInTermMatches(history_match.url_matches, offsets); |
| 273 match.contents_class = | 269 match.contents_class = |
| 274 SpansFromTermMatch(new_matches, match.contents.length(), true); | 270 SpansFromTermMatch(new_matches, match.contents.length(), true); |
| 275 | 271 |
| 276 // Set |inline_autocompletion| and |allowed_to_be_default_match| if possible. | 272 // Set |inline_autocompletion| and |allowed_to_be_default_match| if possible. |
| 277 if (history_match.can_inline) { | 273 if (history_match.can_inline) { |
| 278 DCHECK(!new_matches.empty()); | 274 DCHECK(!new_matches.empty()); |
| 279 size_t inline_autocomplete_offset = new_matches[0].offset + | 275 size_t inline_autocomplete_offset = new_matches[0].offset + |
| 280 new_matches[0].length; | 276 new_matches[0].length; |
| 281 // |inline_autocomplete_offset| may be beyond the end of the | 277 // |inline_autocomplete_offset| may be beyond the end of the |
| (...skipping 16 matching lines...) Expand all Loading... |
| 298 match.description_class = SpansFromTermMatch( | 294 match.description_class = SpansFromTermMatch( |
| 299 history_match.title_matches, match.description.length(), false); | 295 history_match.title_matches, match.description.length(), false); |
| 300 | 296 |
| 301 match.RecordAdditionalInfo("typed count", info.typed_count()); | 297 match.RecordAdditionalInfo("typed count", info.typed_count()); |
| 302 match.RecordAdditionalInfo("visit count", info.visit_count()); | 298 match.RecordAdditionalInfo("visit count", info.visit_count()); |
| 303 match.RecordAdditionalInfo("last visit", info.last_visit()); | 299 match.RecordAdditionalInfo("last visit", info.last_visit()); |
| 304 | 300 |
| 305 return match; | 301 return match; |
| 306 } | 302 } |
| 307 | 303 |
| 308 history::InMemoryURLIndex* HistoryQuickProvider::GetIndex() { | 304 InMemoryURLIndex* HistoryQuickProvider::GetIndex() { |
| 309 if (index_for_testing_.get()) | 305 if (index_for_testing_.get()) |
| 310 return index_for_testing_.get(); | 306 return index_for_testing_.get(); |
| 311 | 307 |
| 312 HistoryService* const history_service = HistoryServiceFactory::GetForProfile( | 308 HistoryService* const history_service = HistoryServiceFactory::GetForProfile( |
| 313 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 309 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| 314 if (!history_service) | 310 if (!history_service) |
| 315 return NULL; | 311 return NULL; |
| 316 | 312 |
| 317 return history_service->InMemoryIndex(); | 313 return history_service->InMemoryIndex(); |
| 318 } | 314 } |
| OLD | NEW |