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

Side by Side Diff: chrome/browser/predictors/autocomplete_action_predictor.h

Issue 10553029: Handle interface to prerenders. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: some remediation, and deflaking browser tests. Created 8 years, 5 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_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"
22 #include "ui/gfx/size.h"
21 23
22 struct AutocompleteLog; 24 struct AutocompleteLog;
23 struct AutocompleteMatch; 25 struct AutocompleteMatch;
24 class AutocompleteResult; 26 class AutocompleteResult;
25 class HistoryService; 27 class HistoryService;
26 class PredictorsHandler; 28 class PredictorsHandler;
27 class Profile; 29 class Profile;
28 30
31 namespace content {
32 class SessionStorageNamespace;
mmenke 2012/07/09 18:06:57 nit: Don't indent.
gavinp 2012/07/11 17:04:00 Done.
33 }
34
29 namespace history { 35 namespace history {
30 class URLDatabase; 36 class URLDatabase;
31 } 37 }
32 38
39 namespace prerender {
40 class PrerenderHandle;
41 }
42
33 namespace predictors { 43 namespace predictors {
34 44
35 // This class is responsible for determining the correct predictive network 45 // This class is responsible for determining the correct predictive network
36 // action to take given for a given AutocompleteMatch and entered text. It can 46 // 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, 47 // be instantiated for both normal and incognito profiles. For normal profiles,
38 // it uses an AutocompleteActionPredictorTable accessed asynchronously on the DB 48 // it uses an AutocompleteActionPredictorTable accessed asynchronously on the DB
39 // thread to permanently store the data used to make predictions, and keeps 49 // 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 50 // 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 51 // 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 52 // local caches are copied from the main profile at creation and from there on
(...skipping 29 matching lines...) Expand all
72 82
73 // Return the recommended action given |user_text|, the text the user has 83 // Return the recommended action given |user_text|, the text the user has
74 // entered in the Omnibox, and |match|, the suggestion from Autocomplete. 84 // entered in the Omnibox, and |match|, the suggestion from Autocomplete.
75 // This method uses information from the ShortcutsBackend including how much 85 // 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 86 // 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 87 // visited the matching URL, to calculate a score between 0 and 1. This score
78 // is then mapped to an Action. 88 // is then mapped to an Action.
79 Action RecommendAction(const string16& user_text, 89 Action RecommendAction(const string16& user_text,
80 const AutocompleteMatch& match) const; 90 const AutocompleteMatch& match) const;
81 91
92 // Begin prerendering |url| with |session_storage_namespace|. The |size| gives
93 // the initial size for the target prerender. The predictor will run at most
94 // one prerender at a time, so launching a prerender will cancel our previous
95 // prerenders (if any).
96 void StartPrerendering(
97 const GURL& url,
98 content::SessionStorageNamespace* session_storage_namespace,
99 gfx::Size size);
mmenke 2012/07/09 18:06:57 Hmm... size is passed by reference to prerender_l
dominich 2012/07/09 18:25:43 IIRC, it was done like this to show that it might
gavinp 2012/07/11 17:04:00 Done, I went with by reference everywhere.
100
82 // Return true if the suggestion type warrants a TCP/IP preconnection. 101 // 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. 102 // i.e., it is now quite likely that the user will select the related domain.
84 static bool IsPreconnectable(const AutocompleteMatch& match); 103 static bool IsPreconnectable(const AutocompleteMatch& match);
85 104
86 private: 105 private:
87 friend class AutocompleteActionPredictorTest; 106 friend class AutocompleteActionPredictorTest;
88 friend class ::PredictorsHandler; 107 friend class ::PredictorsHandler;
89 108
90 struct TransitionalMatch { 109 struct TransitionalMatch {
91 TransitionalMatch(); 110 TransitionalMatch();
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 AutocompleteActionPredictor* incognito_predictor_; 211 AutocompleteActionPredictor* incognito_predictor_;
193 212
194 // The backing data store. This is NULL for incognito-owned predictors. 213 // The backing data store. This is NULL for incognito-owned predictors.
195 scoped_refptr<AutocompleteActionPredictorTable> table_; 214 scoped_refptr<AutocompleteActionPredictorTable> table_;
196 215
197 content::NotificationRegistrar notification_registrar_; 216 content::NotificationRegistrar notification_registrar_;
198 217
199 // This is cleared after every Omnibox navigation. 218 // This is cleared after every Omnibox navigation.
200 std::vector<TransitionalMatch> transitional_matches_; 219 std::vector<TransitionalMatch> transitional_matches_;
201 220
221 scoped_ptr<prerender::PrerenderHandle> prerender_handle_;
222
202 // This allows us to predict the effect of confidence threshold changes on 223 // This allows us to predict the effect of confidence threshold changes on
203 // accuracy. This is cleared after every omnibox navigation. 224 // accuracy. This is cleared after every omnibox navigation.
204 mutable std::vector<std::pair<GURL, double> > tracked_urls_; 225 mutable std::vector<std::pair<GURL, double> > tracked_urls_;
205 226
206 // Local caches of the data store. For incognito-owned predictors this is the 227 // Local caches of the data store. For incognito-owned predictors this is the
207 // only copy of the data. 228 // only copy of the data.
208 DBCacheMap db_cache_; 229 DBCacheMap db_cache_;
209 DBIdCacheMap db_id_cache_; 230 DBIdCacheMap db_id_cache_;
210 231
211 bool initialized_; 232 bool initialized_;
212 233
213 DISALLOW_COPY_AND_ASSIGN(AutocompleteActionPredictor); 234 DISALLOW_COPY_AND_ASSIGN(AutocompleteActionPredictor);
214 }; 235 };
215 236
216 } // namespace predictors 237 } // namespace predictors
217 238
218 #endif // CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_H_ 239 #endif // CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698