| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ | 5 #ifndef CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ |
| 6 #define CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ | 6 #define CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ |
| 7 | 7 |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 // Users of this class may provide a callback to handle errors | 33 // Users of this class may provide a callback to handle errors |
| 34 // (e.g. by showing a UI). The callback is called only on error, and | 34 // (e.g. by showing a UI). The callback is called only on error, and |
| 35 // takes a single parameter, the sql::InitStatus value from trying | 35 // takes a single parameter, the sql::InitStatus value from trying |
| 36 // to open the database. | 36 // to open the database. |
| 37 // TODO(joi): Should we combine this with WebDatabaseService::InitCallback? | 37 // TODO(joi): Should we combine this with WebDatabaseService::InitCallback? |
| 38 typedef base::Callback<void(sql::InitStatus)> ProfileErrorCallback; | 38 typedef base::Callback<void(sql::InitStatus)> ProfileErrorCallback; |
| 39 | 39 |
| 40 // |callback| will only be invoked on error, and only if | 40 // |callback| will only be invoked on error, and only if |
| 41 // |callback.is_null()| evaluates to false. | 41 // |callback.is_null()| evaluates to false. |
| 42 WebDataServiceBase(const base::FilePath& path, | 42 // |
| 43 // The ownership of |wdbs| is shared, with the primary owner being the |
| 44 // WebDataServiceWrapper, and secondary owners being subclasses of |
| 45 // WebDataServiceBase, which receive |wdbs| upon construction. The |
| 46 // WebDataServiceWrapper handles the initializing and shutting down and of |
| 47 // the |wdbs| object. |
| 48 WebDataServiceBase(scoped_refptr<WebDatabaseService> wdbs, |
| 43 const ProfileErrorCallback& callback); | 49 const ProfileErrorCallback& callback); |
| 44 | 50 |
| 45 // Cancel any pending request. You need to call this method if your | 51 // Cancel any pending request. You need to call this method if your |
| 46 // WebDataServiceConsumer is about to be deleted. | 52 // WebDataServiceConsumer is about to be deleted. |
| 47 virtual void CancelRequest(Handle h); | 53 virtual void CancelRequest(Handle h); |
| 48 | 54 |
| 49 // Returns the notification source for this service. This may use a | 55 // Returns the notification source for this service. This may use a |
| 50 // pointer other than this object's |this| pointer. | 56 // pointer other than this object's |this| pointer. |
| 51 virtual content::NotificationSource GetNotificationSource(); | 57 virtual content::NotificationSource GetNotificationSource(); |
| 52 | 58 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // owned by the DB thread on this object. Should be called only from | 92 // owned by the DB thread on this object. Should be called only from |
| 87 // the DB thread, and will be destroyed on the DB thread soon after | 93 // the DB thread, and will be destroyed on the DB thread soon after |
| 88 // |ShutdownOnUIThread()| is called. | 94 // |ShutdownOnUIThread()| is called. |
| 89 base::SupportsUserData* GetDBUserData(); | 95 base::SupportsUserData* GetDBUserData(); |
| 90 | 96 |
| 91 protected: | 97 protected: |
| 92 virtual ~WebDataServiceBase(); | 98 virtual ~WebDataServiceBase(); |
| 93 virtual void ShutdownOnDBThread(); | 99 virtual void ShutdownOnDBThread(); |
| 94 | 100 |
| 95 // Our database service. | 101 // Our database service. |
| 96 scoped_ptr<WebDatabaseService> wdbs_; | 102 scoped_refptr<WebDatabaseService> wdbs_; |
| 97 | 103 |
| 98 // True if we've received a notification that the WebDatabase has loaded. | 104 // True if we've received a notification that the WebDatabase has loaded. |
| 99 bool db_loaded_; | 105 bool db_loaded_; |
| 100 | 106 |
| 101 private: | 107 private: |
| 102 friend struct content::BrowserThread::DeleteOnThread< | 108 friend struct content::BrowserThread::DeleteOnThread< |
| 103 content::BrowserThread::UI>; | 109 content::BrowserThread::UI>; |
| 104 friend class base::DeleteHelper<WebDataServiceBase>; | 110 friend class base::DeleteHelper<WebDataServiceBase>; |
| 105 | 111 |
| 106 // TODO(caitkp): Get rid of this once we fully split | |
| 107 // AutofillWebDataService and WebDatabaseService away from | |
| 108 // WebDataService. | |
| 109 base::FilePath path_; | |
| 110 | |
| 111 ProfileErrorCallback profile_error_callback_; | 112 ProfileErrorCallback profile_error_callback_; |
| 112 | 113 |
| 113 // This makes the destructor public, and thus allows us to aggregate | 114 // This makes the destructor public, and thus allows us to aggregate |
| 114 // SupportsUserData. It is private by default to prevent incorrect | 115 // SupportsUserData. It is private by default to prevent incorrect |
| 115 // usage in class hierarchies where it is inherited by | 116 // usage in class hierarchies where it is inherited by |
| 116 // reference-counted objects. | 117 // reference-counted objects. |
| 117 class SupportsUserDataAggregatable : public base::SupportsUserData { | 118 class SupportsUserDataAggregatable : public base::SupportsUserData { |
| 118 public: | 119 public: |
| 119 SupportsUserDataAggregatable() {} | 120 SupportsUserDataAggregatable() {} |
| 120 virtual ~SupportsUserDataAggregatable() {} | 121 virtual ~SupportsUserDataAggregatable() {} |
| 121 private: | 122 private: |
| 122 DISALLOW_COPY_AND_ASSIGN(SupportsUserDataAggregatable); | 123 DISALLOW_COPY_AND_ASSIGN(SupportsUserDataAggregatable); |
| 123 }; | 124 }; |
| 124 | 125 |
| 125 // Storage for user data to be accessed only on the DB thread. May | 126 // Storage for user data to be accessed only on the DB thread. May |
| 126 // be used e.g. for SyncableService subclasses that need to be owned | 127 // be used e.g. for SyncableService subclasses that need to be owned |
| 127 // by this object. Is created on first call to |GetDBUserData()|. | 128 // by this object. Is created on first call to |GetDBUserData()|. |
| 128 scoped_ptr<SupportsUserDataAggregatable> db_thread_user_data_; | 129 scoped_ptr<SupportsUserDataAggregatable> db_thread_user_data_; |
| 129 | 130 |
| 130 void DBInitFailed(sql::InitStatus sql_status); | 131 void DBInitFailed(sql::InitStatus sql_status); |
| 131 void NotifyDatabaseLoadedOnUIThread(); | 132 void NotifyDatabaseLoadedOnUIThread(); |
| 132 void DatabaseInitOnDB(sql::InitStatus status); | 133 void DatabaseInitOnDB(sql::InitStatus status); |
| 133 }; | 134 }; |
| 134 | 135 |
| 135 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ | 136 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ |
| OLD | NEW |