diff options
author | tburkard@chromium.org <tburkard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-25 03:48:22 +0000 |
---|---|---|
committer | tburkard@chromium.org <tburkard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-25 03:48:22 +0000 |
commit | 77305123bb2c7d384abca045e3982e50be36ae70 (patch) | |
tree | 234e8d032dff88e6e5c9b0a5e72295412bade351 /chrome/browser/predictors | |
parent | e50f4703e50f8c17ba6a6e7032ca17f4d9296655 (diff) | |
download | chromium_src-77305123bb2c7d384abca045e3982e50be36ae70.zip chromium_src-77305123bb2c7d384abca045e3982e50be36ae70.tar.gz chromium_src-77305123bb2c7d384abca045e3982e50be36ae70.tar.bz2 |
Delete LoggedInPredictor state when the last cookie for a domain is deleted or expires.
Review URL: https://codereview.chromium.org/14238020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196304 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/predictors')
-rw-r--r-- | chrome/browser/predictors/logged_in_predictor_table.cc | 49 | ||||
-rw-r--r-- | chrome/browser/predictors/logged_in_predictor_table.h | 15 |
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); }; |