Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BACKEND_H_ | |
| 6 #define COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BACKEND_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 #include "base/callback_forward.h" | |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "base/files/file_path.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/memory/scoped_vector.h" | |
| 15 #include "components/webdata/common/web_database_service.h" | |
| 16 #include "content/public/browser/browser_thread.h" | |
| 17 | |
| 18 | |
| 19 class WebDatabase; | |
| 20 class WebDatabaseTable; | |
| 21 class WebDataRequest; | |
| 22 class WebDataRequestManager; | |
| 23 | |
| 24 namespace tracked_objects { | |
| 25 class Location; | |
| 26 } | |
| 27 | |
| 28 //////////////////////////////////////////////////////////////////////////////// | |
|
Jói
2013/04/17 10:52:04
Suggest getting rid of this weird formatting of th
Cait (Slow)
2013/04/18 15:07:48
Done.
| |
| 29 // | |
| 30 // WebDataServiceBackend implementation. | |
| 31 // | |
| 32 //////////////////////////////////////////////////////////////////////////////// | |
| 33 // Refcounted to allow asynchronous destruction on the DB thread. | |
| 34 class WebDataServiceBackend | |
| 35 : public base::RefCountedThreadSafe< | |
| 36 WebDataServiceBackend, | |
| 37 content::BrowserThread::DeleteOnDBThread> { | |
| 38 public: | |
| 39 class Delegate { | |
| 40 public: | |
| 41 virtual ~Delegate() {} | |
| 42 | |
| 43 // Invoked when the backend has finished loading the db. | |
| 44 virtual void DBLoaded(sql::InitStatus status) = 0; | |
| 45 }; | |
| 46 | |
| 47 explicit WebDataServiceBackend(const base::FilePath& path, | |
| 48 Delegate* delegate); | |
| 49 | |
| 50 // Must call only before InitDatabaseWithCallback. | |
| 51 void AddTable(scoped_ptr<WebDatabaseTable> table); | |
| 52 | |
| 53 // Initializes the database and notifies caller via callback when complete. | |
| 54 // Callback is called synchronously. | |
| 55 void InitDatabase(); | |
| 56 | |
| 57 // Opens the database file from the profile path if an init has not yet been | |
| 58 // attempted. Separated from the constructor to ease construction/destruction | |
| 59 // of this object on one thread but database access on the DB thread. Returns | |
| 60 // the status of the database. | |
| 61 sql::InitStatus LoadDatabaseIfNecessary(); | |
| 62 | |
| 63 // Shuts down database. |should_reinit| tells us whether or not it should be | |
| 64 // possible to re-initialize the DB after the shutdown. | |
| 65 void ShutdownDatabase(bool should_reinit); | |
| 66 | |
| 67 // Task wrappers to run database tasks. | |
| 68 void DBWriteTaskWrapper( | |
| 69 const WebDatabaseService::WriteTask& task, | |
| 70 scoped_ptr<WebDataRequest> request); | |
| 71 void DBReadTaskWrapper( | |
| 72 const WebDatabaseService::ReadTask& task, | |
| 73 scoped_ptr<WebDataRequest> request); | |
| 74 | |
| 75 const scoped_refptr<WebDataRequestManager>& request_manager() { | |
| 76 return request_manager_; | |
| 77 } | |
| 78 | |
| 79 WebDatabase* database() { return db_.get(); } | |
| 80 | |
| 81 private: | |
| 82 friend struct content::BrowserThread::DeleteOnThread< | |
| 83 content::BrowserThread::DB>; | |
| 84 friend class base::DeleteHelper<WebDataServiceBackend>; | |
| 85 | |
| 86 virtual ~WebDataServiceBackend(); | |
| 87 | |
| 88 // Commit the current transaction. | |
| 89 void Commit(); | |
| 90 | |
| 91 // Path to database file. | |
| 92 base::FilePath db_path_; | |
| 93 | |
| 94 // The tables that participate in managing the database. These are | |
| 95 // owned here but other than that this class does nothing with | |
| 96 // them. Their initialization is in whatever factory creates | |
| 97 // WebDatabaseService, and lookup by type is provided by the | |
| 98 // WebDatabase class. The tables need to be owned by this refcounted | |
| 99 // object, or they themselves would need to be refcounted. Owning | |
| 100 // them here rather than having WebDatabase own them makes for | |
| 101 // easier unit testing of WebDatabase. | |
| 102 ScopedVector<WebDatabaseTable> tables_; | |
| 103 | |
| 104 scoped_ptr<WebDatabase> db_; | |
| 105 | |
| 106 // Keeps track of all pending requests made to the db. | |
| 107 scoped_refptr<WebDataRequestManager> request_manager_; | |
| 108 | |
| 109 // State of database initialization. Used to prevent the executing of tasks | |
| 110 // before the db is ready. | |
| 111 sql::InitStatus init_status_; | |
| 112 | |
| 113 // True if an attempt has been made to load the database (even if the attempt | |
| 114 // fails), used to avoid continually trying to reinit if the db init fails. | |
| 115 bool init_complete_; | |
| 116 | |
| 117 // Delegate. See the class definition above for more information. | |
| 118 scoped_ptr<Delegate> delegate_; | |
| 119 | |
| 120 DISALLOW_COPY_AND_ASSIGN(WebDataServiceBackend); | |
| 121 }; | |
| 122 | |
| 123 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BACKEND_H_ | |
| OLD | NEW |