| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_NETWORK_ACTION_PREDICTOR_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_NETWORK_ACTION_PREDICTOR_H_ |
| 6 #define CHROME_BROWSER_AUTOCOMPLETE_NETWORK_ACTION_PREDICTOR_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_NETWORK_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/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/string16.h" | 14 #include "base/string16.h" |
| 15 #include "chrome/browser/autocomplete/network_action_predictor_database.h" | 15 #include "chrome/browser/autocomplete/network_action_predictor_database.h" |
| 16 #include "chrome/browser/profiles/profile_keyed_service.h" |
| 16 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 17 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 18 #include "googleurl/src/gurl.h" | 19 #include "googleurl/src/gurl.h" |
| 19 | 20 |
| 20 struct AutocompleteLog; | 21 struct AutocompleteLog; |
| 21 struct AutocompleteMatch; | 22 struct AutocompleteMatch; |
| 22 class AutocompleteResult; | 23 class AutocompleteResult; |
| 23 class HistoryService; | 24 class HistoryService; |
| 24 class Profile; | 25 class Profile; |
| 25 | 26 |
| 26 namespace history { | 27 namespace history { |
| 27 class URLDatabase; | 28 class URLDatabase; |
| 28 } | 29 } |
| 29 | 30 |
| 30 // This class is responsible for determining the correct predictive network | 31 // This class is responsible for determining the correct predictive network |
| 31 // action to take given for a given AutocompleteMatch and entered text. it uses | 32 // action to take given for a given AutocompleteMatch and entered text. it uses |
| 32 // a NetworkActionPredictorDatabase accessed asynchronously on the DB thread to | 33 // a NetworkActionPredictorDatabase accessed asynchronously on the DB thread to |
| 33 // permanently store the data used to make predictions, and keeps local caches | 34 // permanently store the data used to make predictions, and keeps local caches |
| 34 // of that data to be able to make predictions synchronously on the UI thread | 35 // of that data to be able to make predictions synchronously on the UI thread |
| 35 // where it lives. It can be accessed as a weak pointer so that it can safely | 36 // where it lives. It can be accessed as a weak pointer so that it can safely |
| 36 // use PostTaskAndReply without fear of crashes if it is destroyed before the | 37 // use PostTaskAndReply without fear of crashes if it is destroyed before the |
| 37 // reply triggers. This is necessary during initialization. | 38 // reply triggers. This is necessary during initialization. |
| 38 class NetworkActionPredictor | 39 class NetworkActionPredictor |
| 39 : public content::NotificationObserver, | 40 : public ProfileKeyedService, |
| 41 public content::NotificationObserver, |
| 40 public base::SupportsWeakPtr<NetworkActionPredictor> { | 42 public base::SupportsWeakPtr<NetworkActionPredictor> { |
| 41 public: | 43 public: |
| 42 enum Action { | 44 enum Action { |
| 43 ACTION_PRERENDER = 0, | 45 ACTION_PRERENDER = 0, |
| 44 ACTION_PRECONNECT, | 46 ACTION_PRECONNECT, |
| 45 ACTION_NONE, | 47 ACTION_NONE, |
| 46 LAST_PREDICT_ACTION = ACTION_NONE | 48 LAST_PREDICT_ACTION = ACTION_NONE |
| 47 }; | 49 }; |
| 48 | 50 |
| 49 explicit NetworkActionPredictor(Profile* profile); | 51 explicit NetworkActionPredictor(Profile* profile); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 int number_of_hits; | 107 int number_of_hits; |
| 106 int number_of_misses; | 108 int number_of_misses; |
| 107 }; | 109 }; |
| 108 | 110 |
| 109 typedef std::map<DBCacheKey, DBCacheValue> DBCacheMap; | 111 typedef std::map<DBCacheKey, DBCacheValue> DBCacheMap; |
| 110 typedef std::map<DBCacheKey, NetworkActionPredictorDatabase::Row::Id> | 112 typedef std::map<DBCacheKey, NetworkActionPredictorDatabase::Row::Id> |
| 111 DBIdCacheMap; | 113 DBIdCacheMap; |
| 112 | 114 |
| 113 static const int kMaximumDaysToKeepEntry; | 115 static const int kMaximumDaysToKeepEntry; |
| 114 | 116 |
| 117 // ProfileKeyedService |
| 118 virtual void Shutdown() OVERRIDE; |
| 119 |
| 115 // NotificationObserver | 120 // NotificationObserver |
| 116 virtual void Observe(int type, | 121 virtual void Observe(int type, |
| 117 const content::NotificationSource& source, | 122 const content::NotificationSource& source, |
| 118 const content::NotificationDetails& details) OVERRIDE; | 123 const content::NotificationDetails& details) OVERRIDE; |
| 119 | 124 |
| 120 // Called when NOTIFICATION_OMNIBOX_OPENED_URL is observed. | 125 // Called when NOTIFICATION_OMNIBOX_OPENED_URL is observed. |
| 121 void OnOmniboxOpenedUrl(const AutocompleteLog& log); | 126 void OnOmniboxOpenedUrl(const AutocompleteLog& log); |
| 122 | 127 |
| 123 // Deletes any old or invalid entries from the local caches. |url_db| and | 128 // Deletes any old or invalid entries from the local caches. |url_db| and |
| 124 // |id_list| must not be NULL. Every row id deleted will be added to id_list. | 129 // |id_list| must not be NULL. Every row id deleted will be added to id_list. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 177 |
| 173 DBCacheMap db_cache_; | 178 DBCacheMap db_cache_; |
| 174 DBIdCacheMap db_id_cache_; | 179 DBIdCacheMap db_id_cache_; |
| 175 | 180 |
| 176 bool initialized_; | 181 bool initialized_; |
| 177 | 182 |
| 178 DISALLOW_COPY_AND_ASSIGN(NetworkActionPredictor); | 183 DISALLOW_COPY_AND_ASSIGN(NetworkActionPredictor); |
| 179 }; | 184 }; |
| 180 | 185 |
| 181 #endif // CHROME_BROWSER_AUTOCOMPLETE_NETWORK_ACTION_PREDICTOR_H_ | 186 #endif // CHROME_BROWSER_AUTOCOMPLETE_NETWORK_ACTION_PREDICTOR_H_ |
| OLD | NEW |