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