summaryrefslogtreecommitdiffstats
path: root/chrome/browser/predictors
diff options
context:
space:
mode:
authortburkard@chromium.org <tburkard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-25 20:13:42 +0000
committertburkard@chromium.org <tburkard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-04-25 20:13:42 +0000
commitb4374eadbeeb4f6a0ccdda91a08ce03290496da4 (patch)
tree4e0bdc606eb0fcebd9e6a06c5be101911ba182a7 /chrome/browser/predictors
parente491641306b64fabf3cf5bb6e3c29e9356102031 (diff)
downloadchromium_src-b4374eadbeeb4f6a0ccdda91a08ce03290496da4.zip
chromium_src-b4374eadbeeb4f6a0ccdda91a08ce03290496da4.tar.gz
chromium_src-b4374eadbeeb4f6a0ccdda91a08ce03290496da4.tar.bz2
Delete LoggedInPredictor state when the last cookie for a domain is deleted or expires.
Re-submit after fix of https://codereview.chromium.org/14238020/ Review URL: https://codereview.chromium.org/14230024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196471 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/predictors')
-rw-r--r--chrome/browser/predictors/logged_in_predictor_table.cc49
-rw-r--r--chrome/browser/predictors/logged_in_predictor_table.h15
2 files changed, 57 insertions, 7 deletions
diff --git a/chrome/browser/predictors/logged_in_predictor_table.cc b/chrome/browser/predictors/logged_in_predictor_table.cc
index f251ba6..10ed85d 100644
--- a/chrome/browser/predictors/logged_in_predictor_table.cc
+++ b/chrome/browser/predictors/logged_in_predictor_table.cc
@@ -32,11 +32,17 @@ LoggedInPredictorTable::LoggedInPredictorTable()
LoggedInPredictorTable::~LoggedInPredictorTable() {
}
-string LoggedInPredictorTable::GetKey(const GURL& url) const {
+// static
+string LoggedInPredictorTable::GetKey(const GURL& url) {
+ return GetKeyFromDomain(url.host());
+}
+
+// static
+string LoggedInPredictorTable::GetKeyFromDomain(const std::string& domain) {
string effective_domain(
- net::RegistryControlledDomainService::GetDomainAndRegistry(url.host()));
+ net::RegistryControlledDomainService::GetDomainAndRegistry(domain));
if (effective_domain.empty())
- effective_domain = url.host();
+ effective_domain = domain;
// Strip off a preceding ".", if present.
if (!effective_domain.empty() && effective_domain[0] == '.')
@@ -44,7 +50,7 @@ string LoggedInPredictorTable::GetKey(const GURL& url) const {
return effective_domain;
}
-void LoggedInPredictorTable::Add(const GURL& url) {
+void LoggedInPredictorTable::AddDomainFromURL(const GURL& url) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
if (CantAccessDatabase())
return;
@@ -59,6 +65,23 @@ void LoggedInPredictorTable::Add(const GURL& url) {
statement.Run();
}
+void LoggedInPredictorTable::DeleteDomainFromURL(const GURL& url) {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ if (CantAccessDatabase())
+ return;
+
+ Statement statement(DB()->GetCachedStatement(SQL_FROM_HERE,
+ base::StringPrintf("DELETE FROM %s WHERE domain=?", kTableName).c_str()));
+
+ statement.BindString(0, GetKey(url));
+
+ statement.Run();
+}
+
+void LoggedInPredictorTable::DeleteDomain(const std::string& domain) {
+ DeleteDomainFromURL(GURL("http://" + domain));
+}
+
void LoggedInPredictorTable::HasUserLoggedIn(const GURL& url, bool* is_present,
bool* lookup_succeeded) {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
@@ -94,6 +117,24 @@ void LoggedInPredictorTable::DeleteAllCreatedBetween(
statement.Run();
}
+void LoggedInPredictorTable::GetAllData(
+ LoggedInPredictorTable::LoggedInStateMap* state_map) {
+ CHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
+ DCHECK(state_map != NULL);
+ state_map->clear();
+ if (CantAccessDatabase())
+ return;
+
+ Statement statement(DB()->GetUniqueStatement(
+ base::StringPrintf("SELECT * FROM %s", kTableName).c_str()));
+
+ while (statement.Step()) {
+ string domain = statement.ColumnString(0);
+ int64 value = statement.ColumnInt64(1);
+ (*state_map)[domain] = value;
+ }
+}
+
void LoggedInPredictorTable::CreateTableIfNonExistent() {
CHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
if (CantAccessDatabase())
diff --git a/chrome/browser/predictors/logged_in_predictor_table.h b/chrome/browser/predictors/logged_in_predictor_table.h
index 4f2abce..bb14a40 100644
--- a/chrome/browser/predictors/logged_in_predictor_table.h
+++ b/chrome/browser/predictors/logged_in_predictor_table.h
@@ -7,6 +7,7 @@
#include <string>
+#include "base/hash_tables.h"
#include "base/time.h"
#include "chrome/browser/predictors/predictor_table_base.h"
#include "googleurl/src/gurl.h"
@@ -24,15 +25,25 @@ namespace predictors {
// 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 Add(const GURL& url);
+ 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;
@@ -44,8 +55,6 @@ class LoggedInPredictorTable : public PredictorTableBase {
virtual void CreateTableIfNonExistent() OVERRIDE;
virtual void LogDatabaseStats() OVERRIDE;
- std::string GetKey(const GURL& url) const;
-
DISALLOW_COPY_AND_ASSIGN(LoggedInPredictorTable);
};