OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_BACKEND_H_ | 5 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_BACKEND_H_ |
6 #define COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_BACKEND_H_ | 6 #define COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_BACKEND_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 // DB thread. | 32 // DB thread. |
33 | 33 |
34 class WEBDATA_EXPORT WebDatabaseBackend | 34 class WEBDATA_EXPORT WebDatabaseBackend |
35 : public base::RefCountedDeleteOnMessageLoop<WebDatabaseBackend> { | 35 : public base::RefCountedDeleteOnMessageLoop<WebDatabaseBackend> { |
36 public: | 36 public: |
37 class Delegate { | 37 class Delegate { |
38 public: | 38 public: |
39 virtual ~Delegate() {} | 39 virtual ~Delegate() {} |
40 | 40 |
41 // Invoked when the backend has finished loading the db. | 41 // Invoked when the backend has finished loading the db. |
42 virtual void DBLoaded(sql::InitStatus status) = 0; | 42 // |status| is the result of initializing the db. |
| 43 // |diagnostics| contains diagnostic information about the db, and it will |
| 44 // only be populated when an error occurs. |
| 45 virtual void DBLoaded(sql::InitStatus status, |
| 46 const std::string& diagnostics) = 0; |
43 }; | 47 }; |
44 | 48 |
45 WebDatabaseBackend( | 49 WebDatabaseBackend( |
46 const base::FilePath& path, | 50 const base::FilePath& path, |
47 Delegate* delegate, | 51 Delegate* delegate, |
48 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread); | 52 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread); |
49 | 53 |
50 // Must call only before InitDatabaseWithCallback. | 54 // Must call only before InitDatabaseWithCallback. |
51 void AddTable(std::unique_ptr<WebDatabaseTable> table); | 55 void AddTable(std::unique_ptr<WebDatabaseTable> table); |
52 | 56 |
(...skipping 30 matching lines...) Expand all Loading... |
83 | 87 |
84 WebDatabase* database() { return db_.get(); } | 88 WebDatabase* database() { return db_.get(); } |
85 | 89 |
86 protected: | 90 protected: |
87 friend class base::RefCountedDeleteOnMessageLoop<WebDatabaseBackend>; | 91 friend class base::RefCountedDeleteOnMessageLoop<WebDatabaseBackend>; |
88 friend class base::DeleteHelper<WebDatabaseBackend>; | 92 friend class base::DeleteHelper<WebDatabaseBackend>; |
89 | 93 |
90 virtual ~WebDatabaseBackend(); | 94 virtual ~WebDatabaseBackend(); |
91 | 95 |
92 private: | 96 private: |
| 97 // Invoked on a db error. |
| 98 void DatabaseErrorCallback(int error, sql::Statement* statement); |
| 99 |
93 // Commit the current transaction. | 100 // Commit the current transaction. |
94 void Commit(); | 101 void Commit(); |
95 | 102 |
96 // Path to database file. | 103 // Path to database file. |
97 base::FilePath db_path_; | 104 base::FilePath db_path_; |
98 | 105 |
99 // The tables that participate in managing the database. These are | 106 // The tables that participate in managing the database. These are |
100 // owned here but other than that this class does nothing with | 107 // owned here but other than that this class does nothing with |
101 // them. Their initialization is in whatever factory creates | 108 // them. Their initialization is in whatever factory creates |
102 // WebDatabaseService, and lookup by type is provided by the | 109 // WebDatabaseService, and lookup by type is provided by the |
103 // WebDatabase class. The tables need to be owned by this refcounted | 110 // WebDatabase class. The tables need to be owned by this refcounted |
104 // object, or they themselves would need to be refcounted. Owning | 111 // object, or they themselves would need to be refcounted. Owning |
105 // them here rather than having WebDatabase own them makes for | 112 // them here rather than having WebDatabase own them makes for |
106 // easier unit testing of WebDatabase. | 113 // easier unit testing of WebDatabase. |
107 ScopedVector<WebDatabaseTable> tables_; | 114 ScopedVector<WebDatabaseTable> tables_; |
108 | 115 |
109 std::unique_ptr<WebDatabase> db_; | 116 std::unique_ptr<WebDatabase> db_; |
110 | 117 |
111 // Keeps track of all pending requests made to the db. | 118 // Keeps track of all pending requests made to the db. |
112 scoped_refptr<WebDataRequestManager> request_manager_; | 119 scoped_refptr<WebDataRequestManager> request_manager_; |
113 | 120 |
114 // State of database initialization. Used to prevent the executing of tasks | 121 // State of database initialization. Used to prevent the executing of tasks |
115 // before the db is ready. | 122 // before the db is ready. |
116 sql::InitStatus init_status_; | 123 sql::InitStatus init_status_; |
117 | 124 |
118 // True if an attempt has been made to load the database (even if the attempt | 125 // True if an attempt has been made to load the database (even if the attempt |
119 // fails), used to avoid continually trying to reinit if the db init fails. | 126 // fails), used to avoid continually trying to reinit if the db init fails. |
120 bool init_complete_; | 127 bool init_complete_; |
121 | 128 |
| 129 // True if a catastrophic database error occurs and further error callbacks |
| 130 // from the database should be ignored. |
| 131 bool catastrophic_error_occurred_; |
| 132 |
| 133 // If a catastrophic database error has occurred, this contains any available |
| 134 // diagnostic information. |
| 135 std::string diagnostics_; |
| 136 |
122 // Delegate. See the class definition above for more information. | 137 // Delegate. See the class definition above for more information. |
123 std::unique_ptr<Delegate> delegate_; | 138 std::unique_ptr<Delegate> delegate_; |
124 | 139 |
125 DISALLOW_COPY_AND_ASSIGN(WebDatabaseBackend); | 140 DISALLOW_COPY_AND_ASSIGN(WebDatabaseBackend); |
126 }; | 141 }; |
127 | 142 |
128 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_BACKEND_H_ | 143 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_BACKEND_H_ |
OLD | NEW |