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 COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_H_ | 5 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_H_ |
6 #define COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_H_ | 6 #define COMPONENTS_WEBDATA_COMMON_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" |
| 11 #include "base/memory/weak_ptr.h" |
11 #include "components/webdata/common/web_database_table.h" | 12 #include "components/webdata/common/web_database_table.h" |
12 #include "components/webdata/common/webdata_export.h" | 13 #include "components/webdata/common/webdata_export.h" |
13 #include "sql/connection.h" | 14 #include "sql/connection.h" |
14 #include "sql/init_status.h" | 15 #include "sql/init_status.h" |
15 #include "sql/meta_table.h" | 16 #include "sql/meta_table.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class FilePath; | 19 class FilePath; |
19 } | 20 } |
20 | 21 |
(...skipping 30 matching lines...) Expand all Loading... |
51 // managing the database. | 52 // managing the database. |
52 sql::InitStatus Init(const base::FilePath& db_name); | 53 sql::InitStatus Init(const base::FilePath& db_name); |
53 | 54 |
54 // Transactions management | 55 // Transactions management |
55 void BeginTransaction(); | 56 void BeginTransaction(); |
56 void CommitTransaction(); | 57 void CommitTransaction(); |
57 | 58 |
58 // Exposed for testing only. | 59 // Exposed for testing only. |
59 sql::Connection* GetSQLConnection(); | 60 sql::Connection* GetSQLConnection(); |
60 | 61 |
| 62 base::WeakPtr<WebDatabase> AsWeakPtr(); |
| 63 |
| 64 protected: |
| 65 // All vended weak pointers are invalidated in dtor. |
| 66 base::WeakPtrFactory<WebDatabase> weak_ptr_factory_; |
| 67 |
61 private: | 68 private: |
62 // Used by |Init()| to migration database schema from older versions to | 69 // Used by |Init()| to migration database schema from older versions to |
63 // current version. | 70 // current version. |
64 sql::InitStatus MigrateOldVersionsAsNeeded(); | 71 sql::InitStatus MigrateOldVersionsAsNeeded(); |
65 | 72 |
66 sql::Connection db_; | 73 sql::Connection db_; |
67 sql::MetaTable meta_table_; | 74 sql::MetaTable meta_table_; |
68 | 75 |
69 // Map of all the different tables that have been added to this | 76 // Map of all the different tables that have been added to this |
70 // object. Non-owning. | 77 // object. Non-owning. |
71 typedef std::map<WebDatabaseTable::TypeKey, WebDatabaseTable*> TableMap; | 78 typedef std::map<WebDatabaseTable::TypeKey, WebDatabaseTable*> TableMap; |
72 TableMap tables_; | 79 TableMap tables_; |
73 | 80 |
74 scoped_ptr<content::NotificationService> notification_service_; | 81 scoped_ptr<content::NotificationService> notification_service_; |
75 | 82 |
76 DISALLOW_COPY_AND_ASSIGN(WebDatabase); | 83 DISALLOW_COPY_AND_ASSIGN(WebDatabase); |
77 }; | 84 }; |
78 | 85 |
79 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_H_ | 86 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_H_ |
OLD | NEW |