| 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> |
| 9 |
| 8 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 10 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 11 #include "base/macros.h" | 13 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/ref_counted_delete_on_message_loop.h" | 15 #include "base/memory/ref_counted_delete_on_message_loop.h" |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
| 16 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 17 #include "components/webdata/common/web_database_service.h" | 18 #include "components/webdata/common/web_database_service.h" |
| 18 #include "components/webdata/common/webdata_export.h" | 19 #include "components/webdata/common/webdata_export.h" |
| 19 | 20 |
| 20 class WebDatabase; | 21 class WebDatabase; |
| 21 class WebDatabaseTable; | 22 class WebDatabaseTable; |
| 22 class WebDataRequest; | 23 class WebDataRequest; |
| 23 class WebDataRequestManager; | 24 class WebDataRequestManager; |
| 24 | 25 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 40 // Invoked when the backend has finished loading the db. | 41 // Invoked when the backend has finished loading the db. |
| 41 virtual void DBLoaded(sql::InitStatus status) = 0; | 42 virtual void DBLoaded(sql::InitStatus status) = 0; |
| 42 }; | 43 }; |
| 43 | 44 |
| 44 WebDatabaseBackend( | 45 WebDatabaseBackend( |
| 45 const base::FilePath& path, | 46 const base::FilePath& path, |
| 46 Delegate* delegate, | 47 Delegate* delegate, |
| 47 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread); | 48 const scoped_refptr<base::SingleThreadTaskRunner>& db_thread); |
| 48 | 49 |
| 49 // Must call only before InitDatabaseWithCallback. | 50 // Must call only before InitDatabaseWithCallback. |
| 50 void AddTable(scoped_ptr<WebDatabaseTable> table); | 51 void AddTable(std::unique_ptr<WebDatabaseTable> table); |
| 51 | 52 |
| 52 // Initializes the database and notifies caller via callback when complete. | 53 // Initializes the database and notifies caller via callback when complete. |
| 53 // Callback is called synchronously. | 54 // Callback is called synchronously. |
| 54 void InitDatabase(); | 55 void InitDatabase(); |
| 55 | 56 |
| 56 // Opens the database file from the profile path if an init has not yet been | 57 // Opens the database file from the profile path if an init has not yet been |
| 57 // attempted. Separated from the constructor to ease construction/destruction | 58 // attempted. Separated from the constructor to ease construction/destruction |
| 58 // of this object on one thread but database access on the DB thread. Returns | 59 // of this object on one thread but database access on the DB thread. Returns |
| 59 // the status of the database. | 60 // the status of the database. |
| 60 sql::InitStatus LoadDatabaseIfNecessary(); | 61 sql::InitStatus LoadDatabaseIfNecessary(); |
| 61 | 62 |
| 62 // Shuts down the database. | 63 // Shuts down the database. |
| 63 void ShutdownDatabase(); | 64 void ShutdownDatabase(); |
| 64 | 65 |
| 65 // Task wrappers to update requests and and notify |request_manager_|. These | 66 // Task wrappers to update requests and and notify |request_manager_|. These |
| 66 // are used in cases where the request is being made from the UI thread and an | 67 // are used in cases where the request is being made from the UI thread and an |
| 67 // asyncronous callback is required to notify the client of |request|'s | 68 // asyncronous callback is required to notify the client of |request|'s |
| 68 // completion. | 69 // completion. |
| 69 void DBWriteTaskWrapper(const WebDatabaseService::WriteTask& task, | 70 void DBWriteTaskWrapper(const WebDatabaseService::WriteTask& task, |
| 70 scoped_ptr<WebDataRequest> request); | 71 std::unique_ptr<WebDataRequest> request); |
| 71 void DBReadTaskWrapper(const WebDatabaseService::ReadTask& task, | 72 void DBReadTaskWrapper(const WebDatabaseService::ReadTask& task, |
| 72 scoped_ptr<WebDataRequest> request); | 73 std::unique_ptr<WebDataRequest> request); |
| 73 | 74 |
| 74 // Task runners to run database tasks. | 75 // Task runners to run database tasks. |
| 75 void ExecuteWriteTask(const WebDatabaseService::WriteTask& task); | 76 void ExecuteWriteTask(const WebDatabaseService::WriteTask& task); |
| 76 scoped_ptr<WDTypedResult> ExecuteReadTask( | 77 std::unique_ptr<WDTypedResult> ExecuteReadTask( |
| 77 const WebDatabaseService::ReadTask& task); | 78 const WebDatabaseService::ReadTask& task); |
| 78 | 79 |
| 79 const scoped_refptr<WebDataRequestManager>& request_manager() { | 80 const scoped_refptr<WebDataRequestManager>& request_manager() { |
| 80 return request_manager_; | 81 return request_manager_; |
| 81 } | 82 } |
| 82 | 83 |
| 83 WebDatabase* database() { return db_.get(); } | 84 WebDatabase* database() { return db_.get(); } |
| 84 | 85 |
| 85 protected: | 86 protected: |
| 86 friend class base::RefCountedDeleteOnMessageLoop<WebDatabaseBackend>; | 87 friend class base::RefCountedDeleteOnMessageLoop<WebDatabaseBackend>; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 98 // The tables that participate in managing the database. These are | 99 // The tables that participate in managing the database. These are |
| 99 // owned here but other than that this class does nothing with | 100 // owned here but other than that this class does nothing with |
| 100 // them. Their initialization is in whatever factory creates | 101 // them. Their initialization is in whatever factory creates |
| 101 // WebDatabaseService, and lookup by type is provided by the | 102 // WebDatabaseService, and lookup by type is provided by the |
| 102 // WebDatabase class. The tables need to be owned by this refcounted | 103 // WebDatabase class. The tables need to be owned by this refcounted |
| 103 // object, or they themselves would need to be refcounted. Owning | 104 // object, or they themselves would need to be refcounted. Owning |
| 104 // them here rather than having WebDatabase own them makes for | 105 // them here rather than having WebDatabase own them makes for |
| 105 // easier unit testing of WebDatabase. | 106 // easier unit testing of WebDatabase. |
| 106 ScopedVector<WebDatabaseTable> tables_; | 107 ScopedVector<WebDatabaseTable> tables_; |
| 107 | 108 |
| 108 scoped_ptr<WebDatabase> db_; | 109 std::unique_ptr<WebDatabase> db_; |
| 109 | 110 |
| 110 // Keeps track of all pending requests made to the db. | 111 // Keeps track of all pending requests made to the db. |
| 111 scoped_refptr<WebDataRequestManager> request_manager_; | 112 scoped_refptr<WebDataRequestManager> request_manager_; |
| 112 | 113 |
| 113 // State of database initialization. Used to prevent the executing of tasks | 114 // State of database initialization. Used to prevent the executing of tasks |
| 114 // before the db is ready. | 115 // before the db is ready. |
| 115 sql::InitStatus init_status_; | 116 sql::InitStatus init_status_; |
| 116 | 117 |
| 117 // True if an attempt has been made to load the database (even if the attempt | 118 // True if an attempt has been made to load the database (even if the attempt |
| 118 // fails), used to avoid continually trying to reinit if the db init fails. | 119 // fails), used to avoid continually trying to reinit if the db init fails. |
| 119 bool init_complete_; | 120 bool init_complete_; |
| 120 | 121 |
| 121 // Delegate. See the class definition above for more information. | 122 // Delegate. See the class definition above for more information. |
| 122 scoped_ptr<Delegate> delegate_; | 123 std::unique_ptr<Delegate> delegate_; |
| 123 | 124 |
| 124 DISALLOW_COPY_AND_ASSIGN(WebDatabaseBackend); | 125 DISALLOW_COPY_AND_ASSIGN(WebDatabaseBackend); |
| 125 }; | 126 }; |
| 126 | 127 |
| 127 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_BACKEND_H_ | 128 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_BACKEND_H_ |
| OLD | NEW |