| 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 // Chromium settings and storage represent user-selected preferences and | 5 // Chromium settings and storage represent user-selected preferences and |
| 6 // information and MUST not be extracted, overwritten or modified except | 6 // information and MUST not be extracted, overwritten or modified except |
| 7 // through Chromium defined APIs. | 7 // through Chromium defined APIs. |
| 8 | 8 |
| 9 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ | 9 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ |
| 10 #define COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ | 10 #define COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 // with web pages). | 45 // with web pages). |
| 46 // | 46 // |
| 47 //////////////////////////////////////////////////////////////////////////////// | 47 //////////////////////////////////////////////////////////////////////////////// |
| 48 | 48 |
| 49 class WEBDATA_EXPORT WebDatabaseService | 49 class WEBDATA_EXPORT WebDatabaseService |
| 50 : public base::RefCountedDeleteOnMessageLoop<WebDatabaseService> { | 50 : public base::RefCountedDeleteOnMessageLoop<WebDatabaseService> { |
| 51 public: | 51 public: |
| 52 typedef base::Callback<scoped_ptr<WDTypedResult>(WebDatabase*)> ReadTask; | 52 typedef base::Callback<scoped_ptr<WDTypedResult>(WebDatabase*)> ReadTask; |
| 53 typedef base::Callback<WebDatabase::State(WebDatabase*)> WriteTask; | 53 typedef base::Callback<WebDatabase::State(WebDatabase*)> WriteTask; |
| 54 | 54 |
| 55 // Types for managing DB loading callbacks. |
| 56 typedef base::Closure DBLoadedCallback; |
| 57 typedef base::Callback<void(sql::InitStatus)> DBLoadErrorCallback; |
| 58 |
| 55 // Takes the path to the WebDatabase file. | 59 // Takes the path to the WebDatabase file. |
| 56 // WebDatabaseService lives on |ui_thread| and posts tasks to |db_thread|. | 60 // WebDatabaseService lives on |ui_thread| and posts tasks to |db_thread|. |
| 57 WebDatabaseService(const base::FilePath& path, | 61 WebDatabaseService(const base::FilePath& path, |
| 58 const scoped_refptr<base::MessageLoopProxy>& ui_thread, | 62 const scoped_refptr<base::MessageLoopProxy>& ui_thread, |
| 59 const scoped_refptr<base::MessageLoopProxy>& db_thread); | 63 const scoped_refptr<base::MessageLoopProxy>& db_thread); |
| 60 | 64 |
| 61 // Adds |table| as a WebDatabaseTable that will participate in | 65 // Adds |table| as a WebDatabaseTable that will participate in |
| 62 // managing the database, transferring ownership. All calls to this | 66 // managing the database, transferring ownership. All calls to this |
| 63 // method must be made before |LoadDatabase| is called. | 67 // method must be made before |LoadDatabase| is called. |
| 64 virtual void AddTable(scoped_ptr<WebDatabaseTable> table); | 68 virtual void AddTable(scoped_ptr<WebDatabaseTable> table); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 94 // Cancel an existing request for a task on the DB thread. | 98 // Cancel an existing request for a task on the DB thread. |
| 95 // TODO(caitkp): Think about moving the definition of the Handle type to | 99 // TODO(caitkp): Think about moving the definition of the Handle type to |
| 96 // somewhere else. | 100 // somewhere else. |
| 97 virtual void CancelRequest(WebDataServiceBase::Handle h); | 101 virtual void CancelRequest(WebDataServiceBase::Handle h); |
| 98 | 102 |
| 99 // Register a callback to be notified that the database has loaded. Multiple | 103 // Register a callback to be notified that the database has loaded. Multiple |
| 100 // callbacks may be registered, and each will be called at most once | 104 // callbacks may be registered, and each will be called at most once |
| 101 // (following a successful database load), then cleared. | 105 // (following a successful database load), then cleared. |
| 102 // Note: if the database load is already complete, then the callback will NOT | 106 // Note: if the database load is already complete, then the callback will NOT |
| 103 // be stored or called. | 107 // be stored or called. |
| 104 void RegisterDBLoadedCallback(const base::Callback<void(void)>& callback); | 108 void RegisterDBLoadedCallback(const DBLoadedCallback& callback); |
| 105 | 109 |
| 106 // Register a callback to be notified that the database has failed to load. | 110 // Register a callback to be notified that the database has failed to load. |
| 107 // Multiple callbacks may be registered, and each will be called at most once | 111 // Multiple callbacks may be registered, and each will be called at most once |
| 108 // (following a database load failure), then cleared. | 112 // (following a database load failure), then cleared. |
| 109 // Note: if the database load is already complete, then the callback will NOT | 113 // Note: if the database load is already complete, then the callback will NOT |
| 110 // be stored or called. | 114 // be stored or called. |
| 111 void RegisterDBErrorCallback( | 115 void RegisterDBErrorCallback(const DBLoadErrorCallback& callback); |
| 112 const base::Callback<void(sql::InitStatus)>& callback); | |
| 113 | 116 |
| 114 bool db_loaded() { return db_loaded_; }; | 117 bool db_loaded() const { return db_loaded_; }; |
| 115 | 118 |
| 116 private: | 119 private: |
| 117 class BackendDelegate; | 120 class BackendDelegate; |
| 118 friend class BackendDelegate; | 121 friend class BackendDelegate; |
| 119 friend class base::RefCountedDeleteOnMessageLoop<WebDatabaseService>; | 122 friend class base::RefCountedDeleteOnMessageLoop<WebDatabaseService>; |
| 120 friend class base::DeleteHelper<WebDatabaseService>; | 123 friend class base::DeleteHelper<WebDatabaseService>; |
| 121 | 124 |
| 125 typedef std::vector<DBLoadedCallback> LoadedCallbacks; |
| 126 typedef std::vector<DBLoadErrorCallback> ErrorCallbacks; |
| 127 |
| 122 virtual ~WebDatabaseService(); | 128 virtual ~WebDatabaseService(); |
| 123 | 129 |
| 124 void OnDatabaseLoadDone(sql::InitStatus status); | 130 void OnDatabaseLoadDone(sql::InitStatus status); |
| 125 | 131 |
| 126 base::FilePath path_; | 132 base::FilePath path_; |
| 127 | 133 |
| 128 // The primary owner is |WebDatabaseService| but is refcounted because | 134 // The primary owner is |WebDatabaseService| but is refcounted because |
| 129 // PostTask on DB thread may outlive us. | 135 // PostTask on DB thread may outlive us. |
| 130 scoped_refptr<WebDataServiceBackend> wds_backend_; | 136 scoped_refptr<WebDataServiceBackend> wds_backend_; |
| 131 | 137 |
| 132 // All vended weak pointers are invalidated in ShutdownDatabase(). | 138 // All vended weak pointers are invalidated in ShutdownDatabase(). |
| 133 base::WeakPtrFactory<WebDatabaseService> weak_ptr_factory_; | 139 base::WeakPtrFactory<WebDatabaseService> weak_ptr_factory_; |
| 134 | 140 |
| 135 // Types for managing DB loading callbacks. | |
| 136 typedef base::Callback<void(void)> DBLoadedCallback; | |
| 137 typedef std::vector<DBLoadedCallback> LoadedCallbacks; | |
| 138 | |
| 139 typedef base::Callback<void(sql::InitStatus)> DBLoadErrorCallback; | |
| 140 typedef std::vector<DBLoadErrorCallback> ErrorCallbacks; | |
| 141 | |
| 142 // Callbacks to be called once the DB has loaded. | 141 // Callbacks to be called once the DB has loaded. |
| 143 LoadedCallbacks loaded_callbacks_; | 142 LoadedCallbacks loaded_callbacks_; |
| 144 | 143 |
| 145 // Callbacks to be called if the DB has failed to load. | 144 // Callbacks to be called if the DB has failed to load. |
| 146 ErrorCallbacks error_callbacks_; | 145 ErrorCallbacks error_callbacks_; |
| 147 | 146 |
| 148 // True if the WebDatabase has loaded. | 147 // True if the WebDatabase has loaded. |
| 149 bool db_loaded_; | 148 bool db_loaded_; |
| 150 | 149 |
| 151 scoped_refptr<base::MessageLoopProxy> db_thread_; | 150 scoped_refptr<base::MessageLoopProxy> db_thread_; |
| 151 |
| 152 DISALLOW_COPY_AND_ASSIGN(WebDatabaseService); |
| 152 }; | 153 }; |
| 153 | 154 |
| 154 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ | 155 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ |
| OLD | NEW |