Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4626)

Unified Diff: chrome/browser/webdata/web_database.h

Issue 12543034: Move creation of the various WebDatabaseTable types out of WebDatabase. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Self review. Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/webdata/web_database.h
diff --git a/chrome/browser/webdata/web_database.h b/chrome/browser/webdata/web_database.h
index 3b47d2ae877df72872f3ad47b416809d75bbba7d..3f92779a2eae00d1153744176a5be07ba732dcf1 100644
--- a/chrome/browser/webdata/web_database.h
+++ b/chrome/browser/webdata/web_database.h
@@ -5,20 +5,14 @@
#ifndef CHROME_BROWSER_WEBDATA_WEB_DATABASE_H_
#define CHROME_BROWSER_WEBDATA_WEB_DATABASE_H_
+#include <map>
+
#include "base/memory/scoped_ptr.h"
-#include "base/memory/scoped_vector.h"
+#include "chrome/browser/webdata/web_database_table.h"
#include "sql/connection.h"
#include "sql/init_status.h"
#include "sql/meta_table.h"
-class AutofillTable;
-class KeywordTable;
-class LoginsTable;
-class TokenServiceTable;
-class WebAppsTable;
-class WebDatabaseTable;
-class WebIntentsTable;
-
namespace base {
class FilePath;
}
@@ -40,23 +34,30 @@ class WebDatabase {
WebDatabase();
virtual ~WebDatabase();
+ // Adds a database table. Ownership remains with the caller, which
+ // must ensure that the lifetime of |table| exceeds this object's
+ // lifetime. Must only be called before Init.
+ void AddTable(WebDatabaseTable* table);
+
+ // Retrieves a table based on its |key|.
+ WebDatabaseTable* GetTable(WebDatabaseTable::TypeKey key);
+
// Initialize the database given a name. The name defines where the SQLite
// file is. If this returns an error code, no other method should be called.
// Requires the |app_locale| to be passed as a parameter as the locale can
// only safely be queried on the UI thread.
- sql::InitStatus Init(const base::FilePath& db_name,
- const std::string& app_locale);
+ //
+ // Before calling this method, you must call AddTable for any
+ // WebDatabaseTable objects that are supposed to participate in
+ // managing the database.
+ sql::InitStatus Init(
+ const base::FilePath& db_name,
+ const std::string& app_locale);
// Transactions management
void BeginTransaction();
void CommitTransaction();
- virtual AutofillTable* GetAutofillTable();
- virtual KeywordTable* GetKeywordTable();
- virtual LoginsTable* GetLoginsTable();
- virtual TokenServiceTable* GetTokenServiceTable();
- virtual WebAppsTable* GetWebAppsTable();
-
// Exposed for testing only.
sql::Connection* GetSQLConnection();
@@ -69,20 +70,10 @@ class WebDatabase {
sql::Connection db_;
sql::MetaTable meta_table_;
- // TODO(joi): All of the typed pointers are going in a future
- // change, as we remove knowledge of the specific types from this
- // class.
- AutofillTable* autofill_table_;
- KeywordTable* keyword_table_;
- LoginsTable* logins_table_;
- TokenServiceTable* token_service_table_;
- WebAppsTable* web_apps_table_;
- // TODO(thakis): Add a migration to delete this table, then remove this.
- WebIntentsTable* web_intents_table_;
-
- // Owns all the different database tables that have been added to
- // this object.
- ScopedVector<WebDatabaseTable> tables_;
+ // Map of all the different tables that have been added to this
+ // object. Non-owning.
+ typedef std::map<WebDatabaseTable::TypeKey, WebDatabaseTable*> TableMap;
+ TableMap tables_;
dhollowa 2013/03/12 21:29:38 Did you consider using base::SupportsUserData for
Jói 2013/03/12 21:59:53 I thought about it, and that's where the static-as
dhollowa 2013/03/12 23:34:37 Ya, the ownership semantics and iteration are sign
scoped_ptr<content::NotificationService> notification_service_;

Powered by Google App Engine
This is Rietveld 408576698