Chromium Code Reviews| 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/web_database_observer.h" | |
| 13 #include "components/webdata/common/webdata_export.h" | 12 #include "components/webdata/common/webdata_export.h" |
| 14 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
| 16 #include "sql/init_status.h" | 15 #include "sql/init_status.h" |
| 17 | 16 |
| 18 class WebDatabase; | 17 class WebDatabase; |
| 19 class WebDatabaseService; | 18 class WebDatabaseService; |
| 20 class WebDatabaseTable; | 19 class WebDatabaseTable; |
| 21 | 20 |
| 22 namespace base { | 21 namespace base { |
| 23 class Thread; | 22 class Thread; |
| 24 } | 23 } |
| 25 | 24 |
| 26 // Base for WebDataService class hierarchy. | 25 // Base for WebDataService class hierarchy. |
| 27 class WEBDATA_EXPORT WebDataServiceBase | 26 class WEBDATA_EXPORT WebDataServiceBase |
| 28 : public WebDatabaseObserver, | 27 : public base::RefCountedThreadSafe<WebDataServiceBase, |
| 29 public base::RefCountedThreadSafe<WebDataServiceBase, | |
| 30 content::BrowserThread::DeleteOnUIThread> { | 28 content::BrowserThread::DeleteOnUIThread> { |
| 31 public: | 29 public: |
| 32 // All requests return an opaque handle of the following type. | 30 // All requests return an opaque handle of the following type. |
| 33 typedef int Handle; | 31 typedef int Handle; |
| 34 | 32 |
| 35 // Users of this class may provide a callback to handle errors | 33 // Users of this class may provide a callback to handle errors |
| 36 // (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 |
| 37 // takes a single parameter, the sql::InitStatus value from trying | 35 // takes a single parameter, the sql::InitStatus value from trying |
| 38 // to open the database. | 36 // to open the database. |
| 39 // TODO(joi): Should we combine this with WebDatabaseService::InitCallback? | 37 // TODO(joi): Should we combine this with WebDatabaseService::InitCallback? |
| 40 typedef base::Callback<void(sql::InitStatus)> ProfileErrorCallback; | 38 typedef base::Callback<void(sql::InitStatus)> ProfileErrorCallback; |
| 41 | 39 |
| 42 // |callback| will only be invoked on error, and only if | 40 // |callback| will only be invoked on error, and only if |
| 43 // |callback.is_null()| evaluates to false. | 41 // |callback.is_null()| evaluates to false. |
| 44 // | 42 // |
| 45 // The ownership of |wdbs| is shared, with the primary owner being the | 43 // The ownership of |wdbs| is shared, with the primary owner being the |
| 46 // WebDataServiceWrapper, and secondary owners being subclasses of | 44 // WebDataServiceWrapper, and secondary owners being subclasses of |
| 47 // WebDataServiceBase, which receive |wdbs| upon construction. The | 45 // WebDataServiceBase, which receive |wdbs| upon construction. The |
| 48 // WebDataServiceWrapper handles the initializing and shutting down and of | 46 // WebDataServiceWrapper handles the initializing and shutting down and of |
| 49 // the |wdbs| object. | 47 // the |wdbs| object. |
| 50 WebDataServiceBase(scoped_refptr<WebDatabaseService> wdbs, | 48 WebDataServiceBase(scoped_refptr<WebDatabaseService> wdbs, |
| 51 const ProfileErrorCallback& callback); | 49 const ProfileErrorCallback& callback); |
| 52 | 50 |
| 53 // WebDatabaseObserver implementation. | |
| 54 virtual void WebDatabaseLoaded() OVERRIDE; | |
| 55 virtual void WebDatabaseLoadFailed(sql::InitStatus status) OVERRIDE; | |
| 56 | |
| 57 // 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 |
| 58 // WebDataServiceConsumer is about to be deleted. | 52 // WebDataServiceConsumer is about to be deleted. |
| 59 virtual void CancelRequest(Handle h); | 53 virtual void CancelRequest(Handle h); |
| 60 | 54 |
| 61 // Returns the notification source for this service. This may use a | 55 // Returns the notification source for this service. This may use a |
| 62 // pointer other than this object's |this| pointer. | 56 // pointer other than this object's |this| pointer. |
| 63 virtual content::NotificationSource GetNotificationSource(); | 57 virtual content::NotificationSource GetNotificationSource(); |
| 64 | 58 |
| 65 // 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 |
| 66 // call. | 60 // call. |
| 67 virtual void ShutdownOnUIThread(); | 61 virtual void ShutdownOnUIThread(); |
| 68 | 62 |
| 69 // Initializes the web data service. | 63 // Initializes the web data service. |
| 70 virtual void Init(); | 64 virtual void Init(); |
| 71 | 65 |
| 72 // Unloads the database without actually shutting down the service. This can | 66 // Unloads the database without actually shutting down the service. This can |
| 73 // be used to temporarily reduce the browser process' memory footprint. | 67 // be used to temporarily reduce the browser process' memory footprint. |
| 74 void UnloadDatabase(); | 68 void UnloadDatabase(); |
| 75 | 69 |
| 76 // Unloads the database permanently and shuts down service. | 70 // Unloads the database permanently and shuts down service. |
| 77 void ShutdownDatabase(); | 71 void ShutdownDatabase(); |
| 78 | 72 |
| 79 virtual void AddDBObserver(WebDatabaseObserver* observer); | 73 // Register a callback to be notified that the database has loaded. Multiple |
| 80 virtual void RemoveDBObserver(WebDatabaseObserver* observer); | 74 // callbacks may be registered, and each will be called at most once |
| 75 // (following a successful database load), then cleared. | |
| 76 // Note: if the database load is already complete, then the callback will NOT | |
|
Jói
2013/06/06 11:37:17
"will NOT be stored or called." (right?)
Here and
Cait (Slow)
2013/06/06 15:57:34
Done.
| |
| 77 // be called. | |
| 78 virtual void RegisterDBLoadedCallback( | |
| 79 const base::Callback<void(void)>& callback); | |
| 81 | 80 |
| 82 // Returns true if the database load has completetd successfully, and | 81 // Returns true if the database load has completetd successfully, and |
| 83 // ShutdownOnUIThread has not yet been called. | 82 // ShutdownOnUIThread has not yet been called. |
| 84 virtual bool IsDatabaseLoaded(); | 83 virtual bool IsDatabaseLoaded(); |
| 85 | 84 |
| 86 // 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 |
| 87 // 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 |
| 88 // DBThread. | 87 // DBThread. |
| 89 virtual WebDatabase* GetDatabase(); | 88 virtual WebDatabase* GetDatabase(); |
| 90 | 89 |
| 91 protected: | 90 protected: |
| 92 virtual ~WebDataServiceBase(); | 91 virtual ~WebDataServiceBase(); |
| 93 | 92 |
| 94 // Our database service. | 93 // Our database service. |
| 95 scoped_refptr<WebDatabaseService> wdbs_; | 94 scoped_refptr<WebDatabaseService> wdbs_; |
| 96 | 95 |
| 97 // True if we've received a notification that the WebDatabase has loaded. | |
| 98 bool db_loaded_; | |
| 99 | |
| 100 private: | 96 private: |
| 101 friend struct content::BrowserThread::DeleteOnThread< | 97 friend struct content::BrowserThread::DeleteOnThread< |
| 102 content::BrowserThread::UI>; | 98 content::BrowserThread::UI>; |
| 103 friend class base::DeleteHelper<WebDataServiceBase>; | 99 friend class base::DeleteHelper<WebDataServiceBase>; |
| 104 // We have to friend RCTS<> so WIN shared-lib build is happy (crbug/112250). | 100 // We have to friend RCTS<> so WIN shared-lib build is happy (crbug/112250). |
| 105 friend class base::RefCountedThreadSafe<WebDataServiceBase, | 101 friend class base::RefCountedThreadSafe<WebDataServiceBase, |
| 106 content::BrowserThread::DeleteOnUIThread>; | 102 content::BrowserThread::DeleteOnUIThread>; |
| 107 | 103 |
| 108 ProfileErrorCallback profile_error_callback_; | 104 ProfileErrorCallback profile_error_callback_; |
| 109 }; | 105 }; |
| 110 | 106 |
| 111 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BASE_H_ | 107 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BASE_H_ |
| OLD | NEW |