Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Side by Side Diff: chrome/browser/autocomplete/shortcuts_provider.h

Issue 9689085: Clean up ShortcutsProvider and related classes. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifndef CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_H_ 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_H_
6 #define CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_H_ 6 #define CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map>
10 #include <set> 9 #include <set>
11 #include <string> 10 #include <string>
12 #include <vector>
13 11
14 #include "base/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
15 #include "base/time.h" 13 #include "base/time.h"
16 #include "chrome/browser/autocomplete/autocomplete_match.h" 14 #include "chrome/browser/autocomplete/autocomplete_match.h"
17 #include "chrome/browser/autocomplete/history_provider.h" 15 #include "chrome/browser/autocomplete/history_provider.h"
18 #include "chrome/browser/autocomplete/shortcuts_provider_shortcut.h"
19 #include "chrome/browser/history/shortcuts_backend.h" 16 #include "chrome/browser/history/shortcuts_backend.h"
20 17
21 class Profile; 18 class Profile;
22 19
23 // Provider of recently autocompleted links. Provides autocomplete suggestions 20 // Provider of recently autocompleted links. Provides autocomplete suggestions
24 // from previously selected suggestions. The more often a user selects a 21 // from previously selected suggestions. The more often a user selects a
25 // suggestion for a given search term the higher will be that suggestion's 22 // suggestion for a given search term the higher will be that suggestion's
26 // ranking for future uses of that search term. 23 // ranking for future uses of that search term.
27 class ShortcutsProvider 24 class ShortcutsProvider
28 : public AutocompleteProvider, 25 : public AutocompleteProvider,
(...skipping 20 matching lines...) Expand all
49 46
50 void DeleteMatchesWithURLs(const std::set<GURL>& urls); 47 void DeleteMatchesWithURLs(const std::set<GURL>& urls);
51 void DeleteShortcutsWithURLs(const std::set<GURL>& urls); 48 void DeleteShortcutsWithURLs(const std::set<GURL>& urls);
52 49
53 // Performs the autocomplete matching and scoring. 50 // Performs the autocomplete matching and scoring.
54 void GetMatches(const AutocompleteInput& input); 51 void GetMatches(const AutocompleteInput& input);
55 52
56 AutocompleteMatch ShortcutToACMatch( 53 AutocompleteMatch ShortcutToACMatch(
57 const AutocompleteInput& input, 54 const AutocompleteInput& input,
58 const string16& terms, 55 const string16& terms,
59 shortcuts_provider::ShortcutMap::const_iterator it); 56 const history::ShortcutsBackend::Shortcut& shortcut);
60 57
61 // Given |text| and a corresponding base set of classifications 58 // Given |text| and a corresponding base set of classifications
62 // |original_class|, adds ACMatchClassification::MATCH markers for all 59 // |original_class|, adds ACMatchClassification::MATCH markers for all
63 // instances of the words from |find_text| within |text| and returns the 60 // instances of the words from |find_text| within |text| and returns the
64 // resulting classifications. 61 // resulting classifications.
65 // 62 //
66 // For example, given the |text| 63 // For example, given the |text|
67 // "Sports and News at sports.somesite.com - visit us!" and |original_class| 64 // "Sports and News at sports.somesite.com - visit us!" and |original_class|
68 // {{0, NONE}, {18, URL}, {37, NONE}} (marking "sports.somesite.com" as a 65 // {{0, NONE}, {18, URL}, {37, NONE}} (marking "sports.somesite.com" as a
69 // URL), calling with |find_text| set to "sp ew" would return 66 // URL), calling with |find_text| set to "sp ew" would return
70 // {{0, MATCH}, {2, NONE}, {12, MATCH}, {14, NONE}, {18, URL|MATCH}, 67 // {{0, MATCH}, {2, NONE}, {12, MATCH}, {14, NONE}, {18, URL|MATCH},
71 // {20, URL}, {37, NONE}} 68 // {20, URL}, {37, NONE}}
72 static ACMatchClassifications ClassifyAllMatchesInString( 69 static ACMatchClassifications ClassifyAllMatchesInString(
73 const string16& find_text, 70 const string16& find_text,
74 const string16& text, 71 const string16& text,
75 const ACMatchClassifications& original_class); 72 const ACMatchClassifications& original_class);
76 73
77 // Returns iterator to first item in |shortcuts_map_| matching |keyword|. 74 // Returns iterator to first item in |shortcuts_map_| matching |keyword|.
78 // Returns shortcuts_map_.end() if there are no matches. 75 // Returns shortcuts_map_.end() if there are no matches.
79 shortcuts_provider::ShortcutMap::const_iterator FindFirstMatch( 76 history::ShortcutsBackend::ShortcutMap::const_iterator FindFirstMatch(
80 const string16& keyword); 77 const string16& keyword);
81 78
82 static int CalculateScore(const string16& terms, 79 static int CalculateScore(
83 const shortcuts_provider::Shortcut& shortcut); 80 const string16& terms,
81 const history::ShortcutsBackend::Shortcut& shortcut);
84 82
85 // For unit-test only. 83 // For unit-test only.
86 void set_shortcuts_backend(history::ShortcutsBackend* shortcuts_backend); 84 void set_shortcuts_backend(history::ShortcutsBackend* shortcuts_backend);
87 85
88 std::string languages_; 86 std::string languages_;
89 bool initialized_; 87 bool initialized_;
90 88
91 scoped_refptr<history::ShortcutsBackend> shortcuts_backend_; 89 scoped_refptr<history::ShortcutsBackend> shortcuts_backend_;
92 }; 90 };
93 91
94 #endif // CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_H_ 92 #endif // CHROME_BROWSER_AUTOCOMPLETE_SHORTCUTS_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698