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