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/files/file_path.h" | 9 #include "base/files/file_path.h" |
9 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
12 #include "content/public/browser/notification_source.h" | 13 #include "content/public/browser/notification_source.h" |
13 #include "sql/init_status.h" | 14 #include "sql/init_status.h" |
14 | 15 |
15 class WebDatabase; | 16 class WebDatabase; |
16 class WebDatabaseService; | 17 class WebDatabaseService; |
17 | 18 |
18 namespace base { | 19 namespace base { |
19 class Thread; | 20 class Thread; |
20 } | 21 } |
21 | 22 |
22 // Base for WebDataService class hierarchy. | 23 // Base for WebDataService class hierarchy. |
23 class WebDataServiceBase | 24 class WebDataServiceBase |
24 : public base::RefCountedThreadSafe<WebDataServiceBase, | 25 : public base::RefCountedThreadSafe<WebDataServiceBase, |
25 content::BrowserThread::DeleteOnUIThread> { | 26 content::BrowserThread::DeleteOnUIThread> { |
26 public: | 27 public: |
27 // All requests return an opaque handle of the following type. | 28 // All requests return an opaque handle of the following type. |
28 typedef int Handle; | 29 typedef int Handle; |
29 | 30 |
30 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); |
31 | 41 |
32 // 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 |
33 // WebDataServiceConsumer is about to be deleted. | 43 // WebDataServiceConsumer is about to be deleted. |
34 virtual void CancelRequest(Handle h); | 44 virtual void CancelRequest(Handle h); |
35 | 45 |
36 // Returns the notification source for this service. This may use a | 46 // Returns the notification source for this service. This may use a |
37 // pointer other than this object's |this| pointer. | 47 // pointer other than this object's |this| pointer. |
38 virtual content::NotificationSource GetNotificationSource(); | 48 virtual content::NotificationSource GetNotificationSource(); |
39 | 49 |
40 // Shutdown the web data service. The service can no longer be used after this | 50 // Shutdown the web data service. The service can no longer be used after this |
(...skipping 26 matching lines...) Expand all Loading... |
67 scoped_ptr<WebDatabaseService> wdbs_; | 77 scoped_ptr<WebDatabaseService> wdbs_; |
68 | 78 |
69 // True if we've received a notification that the WebDatabase has loaded. | 79 // True if we've received a notification that the WebDatabase has loaded. |
70 bool db_loaded_; | 80 bool db_loaded_; |
71 | 81 |
72 private: | 82 private: |
73 friend struct content::BrowserThread::DeleteOnThread< | 83 friend struct content::BrowserThread::DeleteOnThread< |
74 content::BrowserThread::UI>; | 84 content::BrowserThread::UI>; |
75 friend class base::DeleteHelper<WebDataServiceBase>; | 85 friend class base::DeleteHelper<WebDataServiceBase>; |
76 | 86 |
| 87 ProfileErrorCallback profile_error_callback_; |
| 88 |
77 void DBInitFailed(sql::InitStatus sql_status); | 89 void DBInitFailed(sql::InitStatus sql_status); |
78 void NotifyDatabaseLoadedOnUIThread(); | 90 void NotifyDatabaseLoadedOnUIThread(); |
79 void DatabaseInitOnDB(sql::InitStatus status); | 91 void DatabaseInitOnDB(sql::InitStatus status); |
80 }; | 92 }; |
81 | 93 |
82 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ | 94 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ |
OLD | NEW |