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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/ref_counted_delete_on_message_loop.h" | 13 #include "base/memory/ref_counted_delete_on_message_loop.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 16 #include "base/single_thread_task_runner.h" |
16 #include "components/webdata/common/web_database_service.h" | 17 #include "components/webdata/common/web_database_service.h" |
17 #include "components/webdata/common/webdata_export.h" | 18 #include "components/webdata/common/webdata_export.h" |
18 | 19 |
19 class WebDatabase; | 20 class WebDatabase; |
20 class WebDatabaseTable; | 21 class WebDatabaseTable; |
21 class WebDataRequest; | 22 class WebDataRequest; |
22 class WebDataRequestManager; | 23 class WebDataRequestManager; |
23 | 24 |
24 namespace tracked_objects { | 25 namespace tracked_objects { |
25 class Location; | 26 class Location; |
26 } | 27 } |
27 | 28 |
28 // WebDatabaseBackend handles all database tasks posted by | 29 // WebDatabaseBackend handles all database tasks posted by |
29 // WebDatabaseService. It is refcounted to allow asynchronous destruction on the | 30 // WebDatabaseService. It is refcounted to allow asynchronous destruction on the |
30 // DB thread. | 31 // DB thread. |
31 | 32 |
32 class WEBDATA_EXPORT WebDatabaseBackend | 33 class WEBDATA_EXPORT WebDatabaseBackend |
33 : public base::RefCountedDeleteOnMessageLoop<WebDatabaseBackend> { | 34 : public base::RefCountedDeleteOnMessageLoop<WebDatabaseBackend> { |
34 public: | 35 public: |
35 class Delegate { | 36 class Delegate { |
36 public: | 37 public: |
37 virtual ~Delegate() {} | 38 virtual ~Delegate() {} |
38 | 39 |
39 // Invoked when the backend has finished loading the db. | 40 // Invoked when the backend has finished loading the db. |
40 virtual void DBLoaded(sql::InitStatus status) = 0; | 41 virtual void DBLoaded(sql::InitStatus status) = 0; |
41 }; | 42 }; |
42 | 43 |
43 WebDatabaseBackend(const base::FilePath& path, | 44 WebDatabaseBackend( |
44 Delegate* delegate, | 45 const base::FilePath& path, |
45 const scoped_refptr<base::MessageLoopProxy>& db_thread); | 46 Delegate* delegate, |
| 47 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread); |
46 | 48 |
47 // Must call only before InitDatabaseWithCallback. | 49 // Must call only before InitDatabaseWithCallback. |
48 void AddTable(scoped_ptr<WebDatabaseTable> table); | 50 void AddTable(scoped_ptr<WebDatabaseTable> table); |
49 | 51 |
50 // Initializes the database and notifies caller via callback when complete. | 52 // Initializes the database and notifies caller via callback when complete. |
51 // Callback is called synchronously. | 53 // Callback is called synchronously. |
52 void InitDatabase(); | 54 void InitDatabase(); |
53 | 55 |
54 // Opens the database file from the profile path if an init has not yet been | 56 // Opens the database file from the profile path if an init has not yet been |
55 // attempted. Separated from the constructor to ease construction/destruction | 57 // attempted. Separated from the constructor to ease construction/destruction |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // fails), used to avoid continually trying to reinit if the db init fails. | 118 // fails), used to avoid continually trying to reinit if the db init fails. |
117 bool init_complete_; | 119 bool init_complete_; |
118 | 120 |
119 // Delegate. See the class definition above for more information. | 121 // Delegate. See the class definition above for more information. |
120 scoped_ptr<Delegate> delegate_; | 122 scoped_ptr<Delegate> delegate_; |
121 | 123 |
122 DISALLOW_COPY_AND_ASSIGN(WebDatabaseBackend); | 124 DISALLOW_COPY_AND_ASSIGN(WebDatabaseBackend); |
123 }; | 125 }; |
124 | 126 |
125 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_BACKEND_H_ | 127 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_BACKEND_H_ |
OLD | NEW |