cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / components / password_manager / core / browser / statistics_table.cc
blob1246ee97985a51e0c701895005c6b04b67e297ff
1 // Copyright 2015 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 #include "components/password_manager/core/browser/statistics_table.h"
7 #include "sql/connection.h"
8 #include "sql/statement.h"
10 namespace password_manager {
11 namespace {
13 // Convenience enum for interacting with SQL queries that use all the columns.
14 enum LoginTableColumns {
15 COLUMN_ORIGIN_DOMAIN = 0,
16 COLUMN_NOPES,
17 COLUMN_DISMISSALS,
18 COLUMN_DATE,
21 } // namespace
23 StatisticsTable::StatisticsTable() : db_(nullptr) {
26 StatisticsTable::~StatisticsTable() {
29 bool StatisticsTable::Init(sql::Connection* db) {
30 db_ = db;
31 if (!db_->DoesTableExist("stats")) {
32 const char query[] =
33 "CREATE TABLE stats ("
34 "origin_domain VARCHAR NOT NULL PRIMARY KEY, "
35 "nopes_count INTEGER, "
36 "dismissal_count INTEGER, "
37 "start_date INTEGER NOT NULL)";
38 if (!db_->Execute(query))
39 return false;
41 return true;
44 bool StatisticsTable::AddRow(const InteractionsStats& stats) {
45 sql::Statement s(db_->GetCachedStatement(
46 SQL_FROM_HERE,
47 "INSERT OR REPLACE INTO stats "
48 "(origin_domain, nopes_count, dismissal_count, start_date) "
49 "VALUES (?, ?, ?, ?)"));
50 s.BindString(COLUMN_ORIGIN_DOMAIN, stats.origin_domain.spec());
51 s.BindInt(COLUMN_NOPES, stats.nopes_count);
52 s.BindInt(COLUMN_DISMISSALS, stats.dismissal_count);
53 s.BindInt64(COLUMN_DATE, stats.start_date.ToInternalValue());
54 return s.Run();
57 bool StatisticsTable::RemoveRow(const GURL& domain) {
58 sql::Statement s(db_->GetCachedStatement(SQL_FROM_HERE,
59 "DELETE FROM stats WHERE "
60 "origin_domain = ? "));
61 s.BindString(0, domain.spec());
62 return s.Run();
65 scoped_ptr<InteractionsStats> StatisticsTable::GetRow(const GURL& domain) {
66 const char query[] =
67 "SELECT origin_domain, nopes_count, "
68 "dismissal_count, start_date FROM stats WHERE origin_domain == ?";
69 sql::Statement s(db_->GetCachedStatement(SQL_FROM_HERE, query));
70 s.BindString(0, domain.spec());
71 if (s.Step()) {
72 scoped_ptr<InteractionsStats> stats(new InteractionsStats);
73 stats->origin_domain = GURL(s.ColumnString(COLUMN_ORIGIN_DOMAIN));
74 stats->nopes_count = s.ColumnInt(COLUMN_NOPES);
75 stats->dismissal_count = s.ColumnInt(COLUMN_DISMISSALS);
76 stats->start_date =
77 base::Time::FromInternalValue(s.ColumnInt64(COLUMN_DATE));
78 return stats.Pass();
80 return scoped_ptr<InteractionsStats>();
83 } // namespace password_manager