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" |
| 9 #include "base/files/file_path.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/public/browser/browser_thread.h" |
8 #include "content/public/browser/notification_source.h" | 13 #include "content/public/browser/notification_source.h" |
| 14 #include "sql/init_status.h" |
| 15 |
| 16 class WebDatabase; |
| 17 class WebDatabaseService; |
| 18 |
| 19 namespace base { |
| 20 class Thread; |
| 21 } |
9 | 22 |
10 // Base for WebDataService class hierarchy. | 23 // Base for WebDataService class hierarchy. |
11 class WebDataServiceBase { | 24 class WebDataServiceBase |
| 25 : public base::RefCountedThreadSafe<WebDataServiceBase, |
| 26 content::BrowserThread::DeleteOnUIThread> { |
12 public: | 27 public: |
13 // All requests return an opaque handle of the following type. | 28 // All requests return an opaque handle of the following type. |
14 typedef int Handle; | 29 typedef int Handle; |
15 | 30 |
16 virtual ~WebDataServiceBase() {} | 31 // Users of this class may provide a callback to handle errors |
| 32 // (e.g. by showing a UI). The callback is called only on error, and |
| 33 // takes a single parameter, the sql::InitStatus value from trying |
| 34 // to open the database. |
| 35 // TODO(joi): Should we combine this with WebDatabaseService::InitCallback? |
| 36 typedef base::Callback<void(sql::InitStatus)> ProfileErrorCallback; |
| 37 |
| 38 // |callback| will only be invoked on error, and only if |
| 39 // |callback.is_null()| evaluates to false. |
| 40 explicit WebDataServiceBase(const ProfileErrorCallback& callback); |
17 | 41 |
18 // Cancel any pending request. You need to call this method if your | 42 // Cancel any pending request. You need to call this method if your |
19 // WebDataServiceConsumer is about to be deleted. | 43 // WebDataServiceConsumer is about to be deleted. |
20 virtual void CancelRequest(Handle h) = 0; | 44 virtual void CancelRequest(Handle h); |
21 | 45 |
22 // Returns the notification source for this service. This may use a | 46 // Returns the notification source for this service. This may use a |
23 // pointer other than this object's |this| pointer. | 47 // pointer other than this object's |this| pointer. |
24 virtual content::NotificationSource GetNotificationSource() = 0; | 48 virtual content::NotificationSource GetNotificationSource(); |
| 49 |
| 50 // Shutdown the web data service. The service can no longer be used after this |
| 51 // call. |
| 52 virtual void ShutdownOnUIThread(); |
| 53 |
| 54 // Initializes the web data service. |
| 55 virtual void Init(const base::FilePath& path); |
| 56 |
| 57 // Unloads the database without actually shutting down the service. This can |
| 58 // be used to temporarily reduce the browser process' memory footprint. |
| 59 void UnloadDatabase(); |
| 60 |
| 61 // Unloads the database permanently and shuts down service. |
| 62 void ShutdownDatabase(); |
| 63 |
| 64 // Returns true if the database load has completetd successfully, and |
| 65 // ShutdownOnUIThread has not yet been called. |
| 66 virtual bool IsDatabaseLoaded(); |
| 67 |
| 68 // Returns a pointer to the DB (used by SyncableServices). May return NULL if |
| 69 // the database is not loaded or otherwise unavailable. Must be called on |
| 70 // DBThread. |
| 71 virtual WebDatabase* GetDatabase(); |
| 72 |
| 73 protected: |
| 74 virtual ~WebDataServiceBase(); |
| 75 |
| 76 // Our database service. |
| 77 scoped_ptr<WebDatabaseService> wdbs_; |
| 78 |
| 79 // True if we've received a notification that the WebDatabase has loaded. |
| 80 bool db_loaded_; |
| 81 |
| 82 private: |
| 83 friend struct content::BrowserThread::DeleteOnThread< |
| 84 content::BrowserThread::UI>; |
| 85 friend class base::DeleteHelper<WebDataServiceBase>; |
| 86 |
| 87 ProfileErrorCallback profile_error_callback_; |
| 88 |
| 89 void DBInitFailed(sql::InitStatus sql_status); |
| 90 void NotifyDatabaseLoadedOnUIThread(); |
| 91 void DatabaseInitOnDB(sql::InitStatus status); |
25 }; | 92 }; |
26 | 93 |
27 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ | 94 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ |
OLD | NEW |