File: autocomplete_action_predictor_table.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (92 lines) | stat: -rw-r--r-- 3,049 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_TABLE_H_
#define CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_TABLE_H_

#include <string>
#include <vector>

#include "base/task/sequenced_task_runner.h"
#include "components/sqlite_proto/table_manager.h"
#include "url/gurl.h"

namespace predictors {

// This manages the autocomplete predictor table within the SQLite database
// passed in to the constructor. It expects the following scheme:
//
// network_action_predictor
//   id                 A unique id.
//   user_text          What the user typed.
//   url                The URL of the entry.
//   number_of_hits     Number of times the entry was shown to the user and
//                      selected.
//   number_of_misses   Number of times the entry was shown to the user but not
//                      selected.
//
// TODO(dominich): Consider adding this table to one of the history databases.
// In memory is currently used, but adding to the on-disk visits database
// would allow DeleteOldEntries to be cheaper through use of a join.
//
// All the functions apart from constructor and destructor have to be called in
// the DB sequence provided to the constructor of this class.
class AutocompleteActionPredictorTable : public sqlite_proto::TableManager {
 public:
  struct Row {
    // TODO(dominich): Make this 64-bit integer as an optimization. This
    // requires some investigation into how to make sure the id is unique for
    // each user_text/url pair.
    // http://crbug.com/102020
    typedef std::string Id;

    Row();

    // Only used by unit tests.
    Row(const Id& id,
        const std::u16string& user_text,
        const GURL& url,
        int number_of_hits,
        int number_of_misses);

    Row(const Row& row);

    Id id;
    std::u16string user_text;
    GURL url;
    int number_of_hits;
    int number_of_misses;
  };

  typedef std::vector<Row> Rows;

  AutocompleteActionPredictorTable(const AutocompleteActionPredictorTable&) =
      delete;
  AutocompleteActionPredictorTable& operator=(
      const AutocompleteActionPredictorTable&) = delete;

  // DB sequence functions.
  void GetRow(const Row::Id& id, Row* row);
  void GetAllRows(Rows* row_buffer);
  void AddRow(const Row& row);
  void UpdateRow(const Row& row);
  void AddAndUpdateRows(const Rows& rows_to_add, const Rows& rows_to_update);
  void DeleteRows(const std::vector<Row::Id>& id_list);
  void DeleteAllRows();

 private:
  friend class PredictorDatabaseInternal;

  explicit AutocompleteActionPredictorTable(
      scoped_refptr<base::SequencedTaskRunner> db_task_runner);
  ~AutocompleteActionPredictorTable() override;

  // TableManager methods (DB sequence).
  void CreateOrClearTablesIfNecessary() override;
  void LogDatabaseStats() override;
};

}  // namespace predictors

#endif  // CHROME_BROWSER_PREDICTORS_AUTOCOMPLETE_ACTION_PREDICTOR_TABLE_H_