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.
5 #ifndef CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_TABLE_H_
6 #define CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_TABLE_H_
11 #include "base/strings/string16.h"
12 #include "chrome/browser/predictors/predictor_table_base.h"
15 namespace predictors
{
17 // This manages the autocomplete predictor table within the SQLite database
18 // passed in to the constructor. It expects the following scheme:
20 // network_action_predictor
22 // user_text What the user typed.
23 // url The URL of the entry.
24 // number_of_hits Number of times the entry was shown to the user and
26 // number_of_misses Number of times the entry was shown to the user but not
29 // TODO(dominich): Consider adding this table to one of the history databases.
30 // In memory is currently used, but adding to the on-disk visits database
31 // would allow DeleteOldEntries to be cheaper through use of a join.
33 // All the functions apart from constructor and destructor have to be called in
35 class AutocompleteActionPredictorTable
: public PredictorTableBase
{
38 // TODO(dominich): Make this 64-bit integer as an optimization. This
39 // requires some investigation into how to make sure the id is unique for
40 // each user_text/url pair.
41 // http://crbug.com/102020
42 typedef std::string Id
;
46 // Only used by unit tests.
48 const base::string16
& user_text
,
51 int number_of_misses
);
56 base::string16 user_text
;
62 typedef std::vector
<Row
> Rows
;
64 // DB thread functions.
65 void GetRow(const Row::Id
& id
, Row
* row
);
66 void GetAllRows(Rows
* row_buffer
);
67 void AddRow(const Row
& row
);
68 void UpdateRow(const Row
& row
);
69 void AddAndUpdateRows(const Rows
& rows_to_add
, const Rows
& rows_to_update
);
70 void DeleteRows(const std::vector
<Row::Id
>& id_list
);
74 friend class PredictorDatabaseInternal
;
76 AutocompleteActionPredictorTable();
77 virtual ~AutocompleteActionPredictorTable();
79 // PredictorTableBase methods (DB thread).
80 virtual void CreateTableIfNonExistent() OVERRIDE
;
81 virtual void LogDatabaseStats() OVERRIDE
;
83 DISALLOW_COPY_AND_ASSIGN(AutocompleteActionPredictorTable
);
86 } // namespace predictors
88 #endif // CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_TABLE_H_