Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_TABLE_H_ | |
| 6 #define CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_TABLE_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/string16.h" | |
| 13 #include "chrome/browser/predictors/predictor_table_base.h" | |
| 14 #include "googleurl/src/gurl.h" | |
| 15 | |
| 16 namespace predictors { | |
| 17 | |
| 18 // This manages the autocomplete predictor table within the SQLite database | |
| 19 // passed in to the constructor. It expects the following scheme: | |
| 20 // | |
| 21 // network_action_predictor | |
| 22 // id A unique id. | |
| 23 // user_text What the user typed. | |
| 24 // url The URL of the entry. | |
| 25 // number_of_hits Number of times the entry was shown to the user and | |
| 26 // selected. | |
| 27 // number_of_misses Number of times the entry was shown to the user but not | |
| 28 // selected. | |
| 29 // | |
| 30 // TODO(dominich): Consider adding this table to one of the history databases. | |
| 31 // In memory is currently used, but adding to the on-disk visits database | |
| 32 // would allow DeleteOldEntries to be cheaper through use of a join. | |
| 33 // | |
| 34 // All the functions apart from constructor and destructor have to be called in | |
| 35 // the DB thread. | |
| 36 class AutocompleteActionPredictorTable : public PredictorTableBase { | |
| 37 public: | |
| 38 struct Row { | |
| 39 // TODO(dominich): Make this 64-bit integer as an optimization. This | |
| 40 // requires some investigation into how to make sure the id is unique for | |
| 41 // each user_text/url pair. | |
| 42 // http://crbug.com/102020 | |
| 43 typedef std::string Id; | |
| 44 | |
| 45 Row(); | |
| 46 | |
| 47 // Only used by unit tests. | |
| 48 Row(const Id& id, | |
| 49 const string16& user_text, | |
| 50 const GURL& url, | |
| 51 int number_of_hits, | |
| 52 int number_of_misses); | |
| 53 | |
| 54 Row(const Row& row); | |
| 55 | |
| 56 Id id; | |
| 57 string16 user_text; | |
| 58 GURL url; | |
| 59 int number_of_hits; | |
| 60 int number_of_misses; | |
| 61 }; | |
| 62 | |
| 63 typedef std::vector<Row> Rows; | |
| 64 | |
| 65 // DB thread functions. | |
| 66 void GetRow(const Row::Id& id, Row* row); | |
| 67 void GetAllRows(Rows* row_buffer); | |
| 68 void AddRow(const Row& row); | |
| 69 void UpdateRow(const Row& row); | |
| 70 void AddAndUpdateRows(const Rows& rows_to_add, const Rows& rows_to_update); | |
| 71 void DeleteRow(const Row::Id& id); | |
|
Scott Hess - ex-Googler
2012/03/15 00:13:33
AFAICT, DeleteRow() is only called from tests.
Shishir
2012/03/15 07:55:48
Removed.
| |
| 72 void DeleteRows(const std::vector<Row::Id>& id_list); | |
| 73 void DeleteAllRows(); | |
| 74 | |
| 75 private: | |
| 76 friend class PredictorDatabaseInternal; | |
| 77 | |
| 78 AutocompleteActionPredictorTable(); | |
| 79 virtual ~AutocompleteActionPredictorTable(); | |
| 80 | |
| 81 // PredictorTableBase methods (DB thread). | |
| 82 virtual void CreateTableIfNonExistent() OVERRIDE; | |
| 83 virtual void LogDatabaseStats() OVERRIDE; | |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(AutocompleteActionPredictorTable); | |
| 86 }; | |
| 87 | |
| 88 } // namespace predictors | |
| 89 | |
| 90 #endif // CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_TABLE_H_ | |
| OLD | NEW |