| 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 COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BASE_H_ | 5 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BASE_H_ |
| 6 #define COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BASE_H_ | 6 #define COMPONENTS_WEBDATA_COMMON_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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "components/webdata/common/webdata_export.h" | 12 #include "components/webdata/common/webdata_export.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
| 15 #include "sql/init_status.h" | 15 #include "sql/init_status.h" |
| 16 | 16 |
| 17 class WebDatabase; | 17 class WebDatabase; |
| 18 class WebDatabaseService; | 18 class WebDatabaseService; |
| 19 class WebDatabaseTable; | 19 class WebDatabaseTable; |
| 20 | 20 |
| 21 namespace base { | 21 namespace base { |
| 22 class Thread; | 22 class Thread; |
| 23 } | 23 } |
| 24 | 24 |
| 25 // Base for WebDataService class hierarchy. | 25 // Base for WebDataService class hierarchy. |
| 26 class WEBDATA_EXPORT WebDataServiceBase | 26 class WEBDATA_EXPORT WebDataServiceBase { |
| 27 : public base::RefCountedThreadSafe<WebDataServiceBase, | |
| 28 content::BrowserThread::DeleteOnUIThread> { | |
| 29 public: | 27 public: |
| 30 // All requests return an opaque handle of the following type. | 28 // All requests return an opaque handle of the following type. |
| 31 typedef int Handle; | 29 typedef int Handle; |
| 32 | 30 |
| 33 // Users of this class may provide a callback to handle errors | 31 // 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 | 32 // (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 | 33 // takes a single parameter, the sql::InitStatus value from trying |
| 36 // to open the database. | 34 // to open the database. |
| 37 // TODO(joi): Should we combine this with WebDatabaseService::InitCallback? | 35 // TODO(joi): Should we combine this with WebDatabaseService::InitCallback? |
| 38 typedef base::Callback<void(sql::InitStatus)> ProfileErrorCallback; | 36 typedef base::Callback<void(sql::InitStatus)> ProfileErrorCallback; |
| 39 | 37 |
| 40 // |callback| will only be invoked on error, and only if | 38 // |callback| will only be invoked on error, and only if |
| 41 // |callback.is_null()| evaluates to false. | 39 // |callback.is_null()| evaluates to false. |
| 42 // | 40 // |
| 43 // The ownership of |wdbs| is shared, with the primary owner being the | 41 // The ownership of |wdbs| is shared, with the primary owner being the |
| 44 // WebDataServiceWrapper, and secondary owners being subclasses of | 42 // WebDataServiceWrapper, and secondary owners being subclasses of |
| 45 // WebDataServiceBase, which receive |wdbs| upon construction. The | 43 // WebDataServiceBase, which receive |wdbs| upon construction. The |
| 46 // WebDataServiceWrapper handles the initializing and shutting down and of | 44 // WebDataServiceWrapper handles the initializing and shutting down and of |
| 47 // the |wdbs| object. | 45 // the |wdbs| object. |
| 48 WebDataServiceBase(scoped_refptr<WebDatabaseService> wdbs, | 46 WebDataServiceBase(scoped_refptr<WebDatabaseService> wdbs, |
| 49 const ProfileErrorCallback& callback); | 47 const ProfileErrorCallback& callback); |
| 50 | 48 |
| 49 virtual ~WebDataServiceBase(); |
| 50 |
| 51 // 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 |
| 52 // WebDataServiceConsumer is about to be deleted. | 52 // WebDataServiceConsumer is about to be deleted. |
| 53 virtual void CancelRequest(Handle h); | 53 virtual void CancelRequest(Handle h); |
| 54 | 54 |
| 55 // Returns the notification source for this service. This may use a | 55 // Returns the notification source for this service. This may use a |
| 56 // pointer other than this object's |this| pointer. | 56 // pointer other than this object's |this| pointer. |
| 57 virtual content::NotificationSource GetNotificationSource(); | 57 virtual content::NotificationSource GetNotificationSource(); |
| 58 | 58 |
| 59 // Shutdown the web data service. The service can no longer be used after this | 59 // Shutdown the web data service. The service can no longer be used after this |
| 60 // call. | 60 // call. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 81 // Returns true if the database load has completetd successfully, and | 81 // Returns true if the database load has completetd successfully, and |
| 82 // ShutdownOnUIThread has not yet been called. | 82 // ShutdownOnUIThread has not yet been called. |
| 83 virtual bool IsDatabaseLoaded(); | 83 virtual bool IsDatabaseLoaded(); |
| 84 | 84 |
| 85 // Returns a pointer to the DB (used by SyncableServices). May return NULL if | 85 // Returns a pointer to the DB (used by SyncableServices). May return NULL if |
| 86 // the database is not loaded or otherwise unavailable. Must be called on | 86 // the database is not loaded or otherwise unavailable. Must be called on |
| 87 // DBThread. | 87 // DBThread. |
| 88 virtual WebDatabase* GetDatabase(); | 88 virtual WebDatabase* GetDatabase(); |
| 89 | 89 |
| 90 protected: | 90 protected: |
| 91 virtual ~WebDataServiceBase(); | |
| 92 | |
| 93 // Our database service. | 91 // Our database service. |
| 94 scoped_refptr<WebDatabaseService> wdbs_; | 92 scoped_refptr<WebDatabaseService> wdbs_; |
| 95 | 93 |
| 96 private: | 94 private: |
| 97 friend struct content::BrowserThread::DeleteOnThread< | 95 ProfileErrorCallback profile_error_callback_; |
| 98 content::BrowserThread::UI>; | |
| 99 friend class base::DeleteHelper<WebDataServiceBase>; | |
| 100 // We have to friend RCTS<> so WIN shared-lib build is happy (crbug/112250). | |
| 101 friend class base::RefCountedThreadSafe<WebDataServiceBase, | |
| 102 content::BrowserThread::DeleteOnUIThread>; | |
| 103 | 96 |
| 104 ProfileErrorCallback profile_error_callback_; | 97 DISALLOW_COPY_AND_ASSIGN(WebDataServiceBase); |
| 105 }; | 98 }; |
| 106 | 99 |
| 107 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BASE_H_ | 100 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BASE_H_ |
| OLD | NEW |