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> | 8 #include <map> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 // Adds a database table. Ownership remains with the caller, which | 37 // Adds a database table. Ownership remains with the caller, which |
38 // must ensure that the lifetime of |table| exceeds this object's | 38 // must ensure that the lifetime of |table| exceeds this object's |
39 // lifetime. Must only be called before Init. | 39 // lifetime. Must only be called before Init. |
40 void AddTable(WebDatabaseTable* table); | 40 void AddTable(WebDatabaseTable* table); |
41 | 41 |
42 // Retrieves a table based on its |key|. | 42 // Retrieves a table based on its |key|. |
43 WebDatabaseTable* GetTable(WebDatabaseTable::TypeKey key); | 43 WebDatabaseTable* GetTable(WebDatabaseTable::TypeKey key); |
44 | 44 |
45 // 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 |
46 // 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. |
47 // Requires the |app_locale| to be passed as a parameter as the locale can | |
48 // only safely be queried on the UI thread. | |
49 // | 47 // |
50 // Before calling this method, you must call AddTable for any | 48 // Before calling this method, you must call AddTable for any |
51 // WebDatabaseTable objects that are supposed to participate in | 49 // WebDatabaseTable objects that are supposed to participate in |
52 // managing the database. | 50 // managing the database. |
53 sql::InitStatus Init( | 51 sql::InitStatus Init(const base::FilePath& db_name); |
54 const base::FilePath& db_name, const std::string& app_locale); | |
55 | 52 |
56 // Transactions management | 53 // Transactions management |
57 void BeginTransaction(); | 54 void BeginTransaction(); |
58 void CommitTransaction(); | 55 void CommitTransaction(); |
59 | 56 |
60 // Exposed for testing only. | 57 // Exposed for testing only. |
61 sql::Connection* GetSQLConnection(); | 58 sql::Connection* GetSQLConnection(); |
62 | 59 |
63 private: | 60 private: |
64 // Used by |Init()| to migration database schema from older versions to | 61 // 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 | 62 // current version. |
66 // the locale can only safely be queried on the UI thread. | 63 sql::InitStatus MigrateOldVersionsAsNeeded(); |
67 sql::InitStatus MigrateOldVersionsAsNeeded(const std::string& app_locale); | |
68 | 64 |
69 sql::Connection db_; | 65 sql::Connection db_; |
70 sql::MetaTable meta_table_; | 66 sql::MetaTable meta_table_; |
71 | 67 |
72 // Map of all the different tables that have been added to this | 68 // Map of all the different tables that have been added to this |
73 // object. Non-owning. | 69 // object. Non-owning. |
74 typedef std::map<WebDatabaseTable::TypeKey, WebDatabaseTable*> TableMap; | 70 typedef std::map<WebDatabaseTable::TypeKey, WebDatabaseTable*> TableMap; |
75 TableMap tables_; | 71 TableMap tables_; |
76 | 72 |
77 scoped_ptr<content::NotificationService> notification_service_; | 73 scoped_ptr<content::NotificationService> notification_service_; |
78 | 74 |
79 DISALLOW_COPY_AND_ASSIGN(WebDatabase); | 75 DISALLOW_COPY_AND_ASSIGN(WebDatabase); |
80 }; | 76 }; |
81 | 77 |
82 #endif // CHROME_BROWSER_WEBDATA_WEB_DATABASE_H_ | 78 #endif // CHROME_BROWSER_WEBDATA_WEB_DATABASE_H_ |
OLD | NEW |