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 #ifndef CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_H_ | 5 #ifndef CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_H_ |
6 #define CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_H_ | 6 #define CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "base/string16.h" | 14 #include "base/string16.h" |
14 #include "chrome/browser/history/history_types.h" | 15 #include "chrome/browser/history/history_types.h" |
15 #include "chrome/browser/predictors/autocomplete_action_predictor_table.h" | 16 #include "chrome/browser/predictors/autocomplete_action_predictor_table.h" |
16 #include "chrome/browser/profiles/profile_keyed_service.h" | 17 #include "chrome/browser/profiles/profile_keyed_service.h" |
17 #include "content/public/browser/notification_observer.h" | 18 #include "content/public/browser/notification_observer.h" |
18 #include "content/public/browser/notification_registrar.h" | 19 #include "content/public/browser/notification_registrar.h" |
19 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
20 | 21 |
21 struct AutocompleteLog; | 22 struct AutocompleteLog; |
22 struct AutocompleteMatch; | 23 struct AutocompleteMatch; |
23 class AutocompleteResult; | 24 class AutocompleteResult; |
24 class HistoryService; | 25 class HistoryService; |
25 class PredictorsHandler; | 26 class PredictorsHandler; |
26 class Profile; | 27 class Profile; |
27 | 28 |
| 29 namespace content { |
| 30 class SessionStorageNamespace; |
| 31 } |
| 32 |
| 33 namespace gfx { |
| 34 class Size; |
| 35 } |
| 36 |
28 namespace history { | 37 namespace history { |
29 class URLDatabase; | 38 class URLDatabase; |
30 } | 39 } |
31 | 40 |
| 41 namespace prerender { |
| 42 class PrerenderHandle; |
| 43 } |
| 44 |
32 namespace predictors { | 45 namespace predictors { |
33 | 46 |
34 // This class is responsible for determining the correct predictive network | 47 // This class is responsible for determining the correct predictive network |
35 // action to take given for a given AutocompleteMatch and entered text. It can | 48 // action to take given for a given AutocompleteMatch and entered text. It can |
36 // be instantiated for both normal and incognito profiles. For normal profiles, | 49 // be instantiated for both normal and incognito profiles. For normal profiles, |
37 // it uses an AutocompleteActionPredictorTable accessed asynchronously on the DB | 50 // it uses an AutocompleteActionPredictorTable accessed asynchronously on the DB |
38 // thread to permanently store the data used to make predictions, and keeps | 51 // thread to permanently store the data used to make predictions, and keeps |
39 // local caches of that data to be able to make predictions synchronously on the | 52 // local caches of that data to be able to make predictions synchronously on the |
40 // UI thread where it lives. For incognito profiles, there is no table; the | 53 // UI thread where it lives. For incognito profiles, there is no table; the |
41 // local caches are copied from the main profile at creation and from there on | 54 // local caches are copied from the main profile at creation and from there on |
(...skipping 29 matching lines...) Expand all Loading... |
71 | 84 |
72 // Return the recommended action given |user_text|, the text the user has | 85 // Return the recommended action given |user_text|, the text the user has |
73 // entered in the Omnibox, and |match|, the suggestion from Autocomplete. | 86 // entered in the Omnibox, and |match|, the suggestion from Autocomplete. |
74 // This method uses information from the ShortcutsBackend including how much | 87 // This method uses information from the ShortcutsBackend including how much |
75 // of the matching entry the user typed, and how long it's been since the user | 88 // of the matching entry the user typed, and how long it's been since the user |
76 // visited the matching URL, to calculate a score between 0 and 1. This score | 89 // visited the matching URL, to calculate a score between 0 and 1. This score |
77 // is then mapped to an Action. | 90 // is then mapped to an Action. |
78 Action RecommendAction(const string16& user_text, | 91 Action RecommendAction(const string16& user_text, |
79 const AutocompleteMatch& match) const; | 92 const AutocompleteMatch& match) const; |
80 | 93 |
| 94 // Begin prerendering |url| with |session_storage_namespace|. The |size| gives |
| 95 // the initial size for the target prerender. The predictor will run at most |
| 96 // one prerender at a time, so launching a prerender will cancel our previous |
| 97 // prerenders (if any). |
| 98 void StartPrerendering( |
| 99 const GURL& url, |
| 100 content::SessionStorageNamespace* session_storage_namespace, |
| 101 const gfx::Size& size); |
| 102 |
81 // Return true if the suggestion type warrants a TCP/IP preconnection. | 103 // Return true if the suggestion type warrants a TCP/IP preconnection. |
82 // i.e., it is now quite likely that the user will select the related domain. | 104 // i.e., it is now quite likely that the user will select the related domain. |
83 static bool IsPreconnectable(const AutocompleteMatch& match); | 105 static bool IsPreconnectable(const AutocompleteMatch& match); |
84 | 106 |
85 private: | 107 private: |
86 friend class AutocompleteActionPredictorTest; | 108 friend class AutocompleteActionPredictorTest; |
87 friend class ::PredictorsHandler; | 109 friend class ::PredictorsHandler; |
88 | 110 |
89 struct TransitionalMatch { | 111 struct TransitionalMatch { |
90 TransitionalMatch(); | 112 TransitionalMatch(); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 AutocompleteActionPredictor* incognito_predictor_; | 213 AutocompleteActionPredictor* incognito_predictor_; |
192 | 214 |
193 // The backing data store. This is NULL for incognito-owned predictors. | 215 // The backing data store. This is NULL for incognito-owned predictors. |
194 scoped_refptr<AutocompleteActionPredictorTable> table_; | 216 scoped_refptr<AutocompleteActionPredictorTable> table_; |
195 | 217 |
196 content::NotificationRegistrar notification_registrar_; | 218 content::NotificationRegistrar notification_registrar_; |
197 | 219 |
198 // This is cleared after every Omnibox navigation. | 220 // This is cleared after every Omnibox navigation. |
199 std::vector<TransitionalMatch> transitional_matches_; | 221 std::vector<TransitionalMatch> transitional_matches_; |
200 | 222 |
| 223 scoped_ptr<prerender::PrerenderHandle> prerender_handle_; |
| 224 |
201 // This allows us to predict the effect of confidence threshold changes on | 225 // This allows us to predict the effect of confidence threshold changes on |
202 // accuracy. This is cleared after every omnibox navigation. | 226 // accuracy. This is cleared after every omnibox navigation. |
203 mutable std::vector<std::pair<GURL, double> > tracked_urls_; | 227 mutable std::vector<std::pair<GURL, double> > tracked_urls_; |
204 | 228 |
205 // Local caches of the data store. For incognito-owned predictors this is the | 229 // Local caches of the data store. For incognito-owned predictors this is the |
206 // only copy of the data. | 230 // only copy of the data. |
207 DBCacheMap db_cache_; | 231 DBCacheMap db_cache_; |
208 DBIdCacheMap db_id_cache_; | 232 DBIdCacheMap db_id_cache_; |
209 | 233 |
210 bool initialized_; | 234 bool initialized_; |
211 | 235 |
212 DISALLOW_COPY_AND_ASSIGN(AutocompleteActionPredictor); | 236 DISALLOW_COPY_AND_ASSIGN(AutocompleteActionPredictor); |
213 }; | 237 }; |
214 | 238 |
215 } // namespace predictors | 239 } // namespace predictors |
216 | 240 |
217 #endif // CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_H_ | 241 #endif // CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_H_ |
OLD | NEW |