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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATABASE_H_ 5 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATABASE_H_
6 #define CHROME_BROWSER_WEBDATA_WEB_DATABASE_H_ 6 #define CHROME_BROWSER_WEBDATA_WEB_DATABASE_H_
7 7
8 #include <map>
9
8 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/scoped_vector.h" 11 #include "chrome/browser/webdata/web_database_table.h"
10 #include "sql/connection.h" 12 #include "sql/connection.h"
11 #include "sql/init_status.h" 13 #include "sql/init_status.h"
12 #include "sql/meta_table.h" 14 #include "sql/meta_table.h"
13 15
14 class AutofillTable;
15 class KeywordTable;
16 class LoginsTable;
17 class TokenServiceTable;
18 class WebAppsTable;
19 class WebDatabaseTable;
20 class WebIntentsTable;
21
22 namespace base { 16 namespace base {
23 class FilePath; 17 class FilePath;
24 } 18 }
25 19
26 namespace content { 20 namespace content {
27 class NotificationService; 21 class NotificationService;
28 } 22 }
29 23
30 // This class manages a SQLite database that stores various web page meta data. 24 // This class manages a SQLite database that stores various web page meta data.
31 class WebDatabase { 25 class WebDatabase {
32 public: 26 public:
33 enum State { 27 enum State {
34 COMMIT_NOT_NEEDED, 28 COMMIT_NOT_NEEDED,
35 COMMIT_NEEDED 29 COMMIT_NEEDED
36 }; 30 };
37 // Exposed publicly so the keyword table can access it. 31 // Exposed publicly so the keyword table can access it.
38 static const int kCurrentVersionNumber; 32 static const int kCurrentVersionNumber;
39 33
40 WebDatabase(); 34 WebDatabase();
41 virtual ~WebDatabase(); 35 virtual ~WebDatabase();
42 36
37 // Adds a database table. Ownership remains with the caller, which
38 // must ensure that the lifetime of |table| exceeds this object's
39 // lifetime. Must only be called before Init.
40 void AddTable(WebDatabaseTable* table);
41
42 // Retrieves a table based on its |key|.
43 WebDatabaseTable* GetTable(WebDatabaseTable::TypeKey key);
44
43 // Initialize the database given a name. The name defines where the SQLite 45 // Initialize the database given a name. The name defines where the SQLite
44 // file is. If this returns an error code, no other method should be called. 46 // file is. If this returns an error code, no other method should be called.
45 // Requires the |app_locale| to be passed as a parameter as the locale can 47 // Requires the |app_locale| to be passed as a parameter as the locale can
46 // only safely be queried on the UI thread. 48 // only safely be queried on the UI thread.
47 sql::InitStatus Init(const base::FilePath& db_name, 49 //
48 const std::string& app_locale); 50 // Before calling this method, you must call AddTable for any
51 // WebDatabaseTable objects that are supposed to participate in
52 // managing the database.
53 sql::InitStatus Init(
54 const base::FilePath& db_name,
55 const std::string& app_locale);
49 56
50 // Transactions management 57 // Transactions management
51 void BeginTransaction(); 58 void BeginTransaction();
52 void CommitTransaction(); 59 void CommitTransaction();
53 60
54 virtual AutofillTable* GetAutofillTable();
55 virtual KeywordTable* GetKeywordTable();
56 virtual LoginsTable* GetLoginsTable();
57 virtual TokenServiceTable* GetTokenServiceTable();
58 virtual WebAppsTable* GetWebAppsTable();
59
60 // Exposed for testing only. 61 // Exposed for testing only.
61 sql::Connection* GetSQLConnection(); 62 sql::Connection* GetSQLConnection();
62 63
63 private: 64 private:
64 // Used by |Init()| to migration database schema from older versions to 65 // Used by |Init()| to migration database schema from older versions to
65 // current version. Requires the |app_locale| to be passed as a parameter as 66 // current version. Requires the |app_locale| to be passed as a parameter as
66 // the locale can only safely be queried on the UI thread. 67 // the locale can only safely be queried on the UI thread.
67 sql::InitStatus MigrateOldVersionsAsNeeded(const std::string& app_locale); 68 sql::InitStatus MigrateOldVersionsAsNeeded(const std::string& app_locale);
68 69
69 sql::Connection db_; 70 sql::Connection db_;
70 sql::MetaTable meta_table_; 71 sql::MetaTable meta_table_;
71 72
72 // TODO(joi): All of the typed pointers are going in a future 73 // Map of all the different tables that have been added to this
73 // change, as we remove knowledge of the specific types from this 74 // object. Non-owning.
74 // class. 75 typedef std::map<WebDatabaseTable::TypeKey, WebDatabaseTable*> TableMap;
75 AutofillTable* autofill_table_; 76 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
76 KeywordTable* keyword_table_;
77 LoginsTable* logins_table_;
78 TokenServiceTable* token_service_table_;
79 WebAppsTable* web_apps_table_;
80 // TODO(thakis): Add a migration to delete this table, then remove this.
81 WebIntentsTable* web_intents_table_;
82
83 // Owns all the different database tables that have been added to
84 // this object.
85 ScopedVector<WebDatabaseTable> tables_;
86 77
87 scoped_ptr<content::NotificationService> notification_service_; 78 scoped_ptr<content::NotificationService> notification_service_;
88 79
89 DISALLOW_COPY_AND_ASSIGN(WebDatabase); 80 DISALLOW_COPY_AND_ASSIGN(WebDatabase);
90 }; 81 };
91 82
92 #endif // CHROME_BROWSER_WEBDATA_WEB_DATABASE_H_ 83 #endif // CHROME_BROWSER_WEBDATA_WEB_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698