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" |
12 #include "base/supports_user_data.h" | |
11 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
12 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
13 #include "sql/init_status.h" | 15 #include "sql/init_status.h" |
14 | 16 |
15 class WebDatabase; | 17 class WebDatabase; |
16 class WebDatabaseService; | 18 class WebDatabaseService; |
17 | 19 |
18 namespace base { | 20 namespace base { |
19 class Thread; | 21 class Thread; |
20 } | 22 } |
21 | 23 |
22 // Base for WebDataService class hierarchy. | 24 // Base for WebDataService class hierarchy. |
23 class WebDataServiceBase | 25 class WebDataServiceBase |
24 : public base::RefCountedThreadSafe<WebDataServiceBase, | 26 : public base::RefCountedThreadSafe<WebDataServiceBase, |
25 content::BrowserThread::DeleteOnUIThread> { | 27 content::BrowserThread::DeleteOnUIThread> { |
26 public: | 28 public: |
27 // All requests return an opaque handle of the following type. | 29 // All requests return an opaque handle of the following type. |
28 typedef int Handle; | 30 typedef int Handle; |
29 | 31 |
30 WebDataServiceBase(); | 32 // Users of this class may provide a callback to handle errors |
33 // (e.g. by showing a UI). The callback is called only on error, and | |
34 // takes a single parameter, the sql::InitStatus value from trying | |
35 // to open the database. | |
36 | |
37 // TODO(joi): Should we combine this with WebDatabaseService::InitCallback? | |
38 typedef base::Callback<void(sql::InitStatus)> ProfileErrorCallback; | |
39 | |
40 // |callback| will only be invoked on error, and only if | |
41 // ||callback.is_null()| evaluates to true. | |
Jói
2013/03/19 20:53:58
||callback.is_null()| evaluates to true
-->
|cal
Cait (Slow)
2013/03/20 22:21:10
I updated this CL so its now based off of https://
| |
42 WebDataServiceBase(scoped_refptr<WebDatabaseService> wdbs, | |
43 const ProfileErrorCallback& callback); | |
31 | 44 |
32 // Cancel any pending request. You need to call this method if your | 45 // Cancel any pending request. You need to call this method if your |
33 // WebDataServiceConsumer is about to be deleted. | 46 // WebDataServiceConsumer is about to be deleted. |
34 virtual void CancelRequest(Handle h); | 47 virtual void CancelRequest(Handle h); |
35 | 48 |
36 // Returns the notification source for this service. This may use a | 49 // Returns the notification source for this service. This may use a |
37 // pointer other than this object's |this| pointer. | 50 // pointer other than this object's |this| pointer. |
38 virtual content::NotificationSource GetNotificationSource(); | 51 virtual content::NotificationSource GetNotificationSource(); |
39 | 52 |
40 // Shutdown the web data service. The service can no longer be used after this | 53 // Shutdown the web data service. The service can no longer be used after this |
(...skipping 12 matching lines...) Expand all Loading... | |
53 | 66 |
54 // Returns true if the database load has completetd successfully, and | 67 // Returns true if the database load has completetd successfully, and |
55 // ShutdownOnUIThread has not yet been called. | 68 // ShutdownOnUIThread has not yet been called. |
56 virtual bool IsDatabaseLoaded(); | 69 virtual bool IsDatabaseLoaded(); |
57 | 70 |
58 // Returns a pointer to the DB (used by SyncableServices). May return NULL if | 71 // 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 | 72 // the database is not loaded or otherwise unavailable. Must be called on |
60 // DBThread. | 73 // DBThread. |
61 virtual WebDatabase* GetDatabase(); | 74 virtual WebDatabase* GetDatabase(); |
62 | 75 |
76 // Returns a SupportsUserData objects that may be used to store data | |
77 // owned by the DB thread on this object. Should be called only from | |
78 // the DB thread, and will be destroyed on the DB thread soon after | |
79 // |ShutdownOnUIThread()| is called. | |
80 base::SupportsUserData* GetDBUserData(); | |
81 | |
63 protected: | 82 protected: |
64 virtual ~WebDataServiceBase(); | 83 virtual ~WebDataServiceBase(); |
84 virtual void ShutdownOnDBThread(); | |
65 | 85 |
66 // Our database service. | 86 // Our database service. |
67 scoped_ptr<WebDatabaseService> wdbs_; | 87 scoped_refptr<WebDatabaseService> wdbs_; |
68 | 88 |
69 // True if we've received a notification that the WebDatabase has loaded. | 89 // True if we've received a notification that the WebDatabase has loaded. |
70 bool db_loaded_; | 90 bool db_loaded_; |
71 | 91 |
72 private: | 92 private: |
73 friend struct content::BrowserThread::DeleteOnThread< | 93 friend struct content::BrowserThread::DeleteOnThread< |
74 content::BrowserThread::UI>; | 94 content::BrowserThread::UI>; |
75 friend class base::DeleteHelper<WebDataServiceBase>; | 95 friend class base::DeleteHelper<WebDataServiceBase>; |
76 | 96 |
97 ProfileErrorCallback profile_error_callback_; | |
98 | |
99 // This makes the destructor public, and thus allows us to aggregate | |
100 // SupportsUserData. It is private by default to prevent incorrect | |
101 // usage in class hierarchies where it is inherited by | |
102 // reference-counted objects. | |
103 class SupportsUserDataAggregatable : public base::SupportsUserData { | |
104 public: | |
105 SupportsUserDataAggregatable() {} | |
106 virtual ~SupportsUserDataAggregatable() {} | |
107 private: | |
108 DISALLOW_COPY_AND_ASSIGN(SupportsUserDataAggregatable); | |
109 }; | |
110 | |
111 // Storage for user data to be accessed only on the DB thread. May | |
112 // be used e.g. for SyncableService subclasses that need to be owned | |
113 // by this object. Is created on first call to |GetDBUserData()|. | |
114 scoped_ptr<SupportsUserDataAggregatable> db_thread_user_data_; | |
115 | |
77 void DBInitFailed(sql::InitStatus sql_status); | 116 void DBInitFailed(sql::InitStatus sql_status); |
78 void NotifyDatabaseLoadedOnUIThread(); | 117 void NotifyDatabaseLoadedOnUIThread(); |
79 void DatabaseInitOnDB(sql::InitStatus status); | 118 void DatabaseInitOnDB(sql::InitStatus status); |
80 }; | 119 }; |
81 | 120 |
82 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ | 121 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ |
OLD | NEW |