summaryrefslogtreecommitdiffstats
path: root/chrome/browser/predictors/logged_in_predictor_table.h
blob: 30d149578d64c608f2b0c96e552a06fdd08d1f73 (plain)
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
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_PREDICTORS_LOGGED_IN_PREDICTOR_TABLE_H_
#define CHROME_BROWSER_PREDICTORS_LOGGED_IN_PREDICTOR_TABLE_H_

#include <string>

#include "base/containers/hash_tables.h"
#include "base/time/time.h"
#include "chrome/browser/predictors/predictor_table_base.h"
#include "url/gurl.h"

namespace sql {
class Statement;
}

namespace predictors {

// Interface for database table to keep track of what sites a user is logged
// in to.
// All methods except the constructor and destructor need to be called on the DB
// thread.
// Manages one table { domain (primary key), added_timestamp }.
class LoggedInPredictorTable : public PredictorTableBase {
 public:
  typedef base::hash_map<std::string, int64> LoggedInStateMap;

  // Adds the relevant part of the domain of the URL provided to the database
  // as the user having performed a login action.
  void AddDomainFromURL(const GURL& url);
  // Deletes a record for the domain corresponding to the URL provided.
  void DeleteDomainFromURL(const GURL& url);
  // Deletes a record for the domain provided.
  void DeleteDomain(const std::string& domain);
  // Checks whether for the relevant part of the domain of the URL provided,
  // the user has performed a login action in the past.
  void HasUserLoggedIn(const GURL& url, bool* is_present,
                       bool* lookup_succeeded);
  void DeleteAllCreatedBetween(const base::Time& delete_begin,
                               const base::Time& delete_end);
  void GetAllData(LoggedInStateMap* state_map);

  static std::string GetKey(const GURL& url);
  static std::string GetKeyFromDomain(const std::string& domain);

 private:
  friend class PredictorDatabaseInternal;

  LoggedInPredictorTable();
  virtual ~LoggedInPredictorTable();

  // PredictorTableBase methods.
  virtual void CreateTableIfNonExistent() OVERRIDE;
  virtual void LogDatabaseStats() OVERRIDE;

  DISALLOW_COPY_AND_ASSIGN(LoggedInPredictorTable);
};

}  // namespace predictors

#endif  // CHROME_BROWSER_PREDICTORS_LOGGED_IN_PREDICTOR_TABLE_H_