OLD | NEW |
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. |
| 49 // |
| 50 // Before calling this method, you must call AddTable for any |
| 51 // WebDatabaseTable objects that are supposed to participate in |
| 52 // managing the database. |
47 sql::InitStatus Init( | 53 sql::InitStatus Init( |
48 const base::FilePath& db_name, const std::string& app_locale); | 54 const base::FilePath& db_name, const std::string& app_locale); |
49 | 55 |
50 // Transactions management | 56 // Transactions management |
51 void BeginTransaction(); | 57 void BeginTransaction(); |
52 void CommitTransaction(); | 58 void CommitTransaction(); |
53 | 59 |
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. | 60 // Exposed for testing only. |
61 sql::Connection* GetSQLConnection(); | 61 sql::Connection* GetSQLConnection(); |
62 | 62 |
63 private: | 63 private: |
64 // Used by |Init()| to migration database schema from older versions to | 64 // 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 | 65 // 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. | 66 // the locale can only safely be queried on the UI thread. |
67 sql::InitStatus MigrateOldVersionsAsNeeded(const std::string& app_locale); | 67 sql::InitStatus MigrateOldVersionsAsNeeded(const std::string& app_locale); |
68 | 68 |
69 sql::Connection db_; | 69 sql::Connection db_; |
70 sql::MetaTable meta_table_; | 70 sql::MetaTable meta_table_; |
71 | 71 |
72 // TODO(joi): All of the typed pointers are going in a future | 72 // Map of all the different tables that have been added to this |
73 // change, as we remove knowledge of the specific types from this | 73 // object. Non-owning. |
74 // class. | 74 typedef std::map<WebDatabaseTable::TypeKey, WebDatabaseTable*> TableMap; |
75 AutofillTable* autofill_table_; | 75 TableMap tables_; |
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 | 76 |
87 scoped_ptr<content::NotificationService> notification_service_; | 77 scoped_ptr<content::NotificationService> notification_service_; |
88 | 78 |
89 DISALLOW_COPY_AND_ASSIGN(WebDatabase); | 79 DISALLOW_COPY_AND_ASSIGN(WebDatabase); |
90 }; | 80 }; |
91 | 81 |
92 #endif // CHROME_BROWSER_WEBDATA_WEB_DATABASE_H_ | 82 #endif // CHROME_BROWSER_WEBDATA_WEB_DATABASE_H_ |
OLD | NEW |