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

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

Issue 573553004: Eliminate NOTIFICATION_HISTORY_LOADED notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add ScopedObserver to InMemoryHistoryBackend,PrerenderLocalPredictor,ChromeTemplateURLServiceClient Created 6 years 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
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 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/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "base/scoped_observer.h"
14 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
15 #include "chrome/browser/predictors/autocomplete_action_predictor_table.h" 16 #include "chrome/browser/predictors/autocomplete_action_predictor_table.h"
17 #include "components/history/core/browser/history_service_observer.h"
16 #include "components/history/core/browser/history_types.h" 18 #include "components/history/core/browser/history_types.h"
17 #include "components/keyed_service/core/keyed_service.h" 19 #include "components/keyed_service/core/keyed_service.h"
18 #include "content/public/browser/navigation_controller.h" 20 #include "content/public/browser/navigation_controller.h"
19 #include "content/public/browser/notification_observer.h" 21 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h" 22 #include "content/public/browser/notification_registrar.h"
21 #include "url/gurl.h" 23 #include "url/gurl.h"
22 24
23 struct AutocompleteMatch; 25 struct AutocompleteMatch;
24 class AutocompleteResult; 26 class AutocompleteResult;
25 class HistoryService; 27 class HistoryService;
(...skipping 28 matching lines...) Expand all
54 // UI thread where it lives. For incognito profiles, there is no table; the 56 // UI thread where it lives. For incognito profiles, there is no table; the
55 // local caches are copied from the main profile at creation and from there on 57 // local caches are copied from the main profile at creation and from there on
56 // are the only thing used. 58 // are the only thing used.
57 // 59 //
58 // This class can be accessed as a weak pointer so that it can safely use 60 // This class can be accessed as a weak pointer so that it can safely use
59 // PostTaskAndReply without fear of crashes if it is destroyed before the reply 61 // PostTaskAndReply without fear of crashes if it is destroyed before the reply
60 // triggers. This is necessary during initialization. 62 // triggers. This is necessary during initialization.
61 class AutocompleteActionPredictor 63 class AutocompleteActionPredictor
62 : public KeyedService, 64 : public KeyedService,
63 public content::NotificationObserver, 65 public content::NotificationObserver,
66 public history::HistoryServiceObserver,
64 public base::SupportsWeakPtr<AutocompleteActionPredictor> { 67 public base::SupportsWeakPtr<AutocompleteActionPredictor> {
65 public: 68 public:
66 enum Action { 69 enum Action {
67 ACTION_PRERENDER = 0, 70 ACTION_PRERENDER = 0,
68 ACTION_PRECONNECT, 71 ACTION_PRECONNECT,
69 ACTION_NONE, 72 ACTION_NONE,
70 LAST_PREDICT_ACTION = ACTION_NONE 73 LAST_PREDICT_ACTION = ACTION_NONE
71 }; 74 };
72 75
73 explicit AutocompleteActionPredictor(Profile* profile); 76 explicit AutocompleteActionPredictor(Profile* profile);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // will take a particular match given what they have typed. |is_in_db| is set 211 // will take a particular match given what they have typed. |is_in_db| is set
209 // to differentiate trivial zero results resulting from a match not being 212 // to differentiate trivial zero results resulting from a match not being
210 // found from actual zero results where the calculation returns 0.0. 213 // found from actual zero results where the calculation returns 0.0.
211 double CalculateConfidence(const base::string16& user_text, 214 double CalculateConfidence(const base::string16& user_text,
212 const AutocompleteMatch& match, 215 const AutocompleteMatch& match,
213 bool* is_in_db) const; 216 bool* is_in_db) const;
214 217
215 // Calculates the confidence for an entry in the DBCacheMap. 218 // Calculates the confidence for an entry in the DBCacheMap.
216 double CalculateConfidenceForDbEntry(DBCacheMap::const_iterator iter) const; 219 double CalculateConfidenceForDbEntry(DBCacheMap::const_iterator iter) const;
217 220
221 // KeyedService:
222 void Shutdown() override;
223
224 // history::HistoryServiceObserver:
225 void OnHistoryServiceLoaded(HistoryService* history_service) override;
226
218 Profile* profile_; 227 Profile* profile_;
219 228
220 // Set when this is a predictor for an incognito profile. 229 // Set when this is a predictor for an incognito profile.
221 AutocompleteActionPredictor* main_profile_predictor_; 230 AutocompleteActionPredictor* main_profile_predictor_;
222 231
223 // Set when this is a predictor for a non-incognito profile, and the incognito 232 // Set when this is a predictor for a non-incognito profile, and the incognito
224 // profile creates a predictor. If this is non-NULL when we finish 233 // profile creates a predictor. If this is non-NULL when we finish
225 // initialization, we should call CopyFromMainProfile() on it. 234 // initialization, we should call CopyFromMainProfile() on it.
226 AutocompleteActionPredictor* incognito_predictor_; 235 AutocompleteActionPredictor* incognito_predictor_;
227 236
(...skipping 11 matching lines...) Expand all
239 // accuracy. This is cleared after every omnibox navigation. 248 // accuracy. This is cleared after every omnibox navigation.
240 mutable std::vector<std::pair<GURL, double> > tracked_urls_; 249 mutable std::vector<std::pair<GURL, double> > tracked_urls_;
241 250
242 // Local caches of the data store. For incognito-owned predictors this is the 251 // Local caches of the data store. For incognito-owned predictors this is the
243 // only copy of the data. 252 // only copy of the data.
244 DBCacheMap db_cache_; 253 DBCacheMap db_cache_;
245 DBIdCacheMap db_id_cache_; 254 DBIdCacheMap db_id_cache_;
246 255
247 bool initialized_; 256 bool initialized_;
248 257
258 ScopedObserver<HistoryService, HistoryServiceObserver>
259 history_service_observer_;
260
249 DISALLOW_COPY_AND_ASSIGN(AutocompleteActionPredictor); 261 DISALLOW_COPY_AND_ASSIGN(AutocompleteActionPredictor);
250 }; 262 };
251 263
252 } // namespace predictors 264 } // namespace predictors
253 265
254 #endif // CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_H_ 266 #endif // CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698