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.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/ref_counted_delete_on_message_loop.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "components/webdata/common/webdata_export.h" | 13 #include "components/webdata/common/webdata_export.h" |
13 #include "content/public/browser/browser_thread.h" | |
14 #include "sql/init_status.h" | 14 #include "sql/init_status.h" |
15 | 15 |
16 class WebDatabase; | 16 class WebDatabase; |
17 class WebDatabaseService; | 17 class WebDatabaseService; |
18 class WebDatabaseTable; | 18 class WebDatabaseTable; |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 class Thread; | 21 class Thread; |
22 } | 22 } |
23 | 23 |
24 // Base for WebDataService class hierarchy. | 24 // Base for WebDataService class hierarchy. |
| 25 // WebDataServiceBase is destroyed on the UI thread. |
25 class WEBDATA_EXPORT WebDataServiceBase | 26 class WEBDATA_EXPORT WebDataServiceBase |
26 : public base::RefCountedThreadSafe<WebDataServiceBase, | 27 : public base::RefCountedDeleteOnMessageLoop<WebDataServiceBase> { |
27 content::BrowserThread::DeleteOnUIThread> { | |
28 public: | 28 public: |
29 // All requests return an opaque handle of the following type. | 29 // All requests return an opaque handle of the following type. |
30 typedef int Handle; | 30 typedef int Handle; |
31 | 31 |
32 // Users of this class may provide a callback to handle errors | 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 | 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 | 34 // takes a single parameter, the sql::InitStatus value from trying |
35 // to open the database. | 35 // to open the database. |
36 // TODO(joi): Should we combine this with WebDatabaseService::InitCallback? | 36 // TODO(joi): Should we combine this with WebDatabaseService::InitCallback? |
37 typedef base::Callback<void(sql::InitStatus)> ProfileErrorCallback; | 37 typedef base::Callback<void(sql::InitStatus)> ProfileErrorCallback; |
38 | 38 |
39 // |callback| will only be invoked on error, and only if | 39 // |callback| will only be invoked on error, and only if |
40 // |callback.is_null()| evaluates to false. | 40 // |callback.is_null()| evaluates to false. |
41 // | 41 // |
42 // The ownership of |wdbs| is shared, with the primary owner being the | 42 // The ownership of |wdbs| is shared, with the primary owner being the |
43 // WebDataServiceWrapper, and secondary owners being subclasses of | 43 // WebDataServiceWrapper, and secondary owners being subclasses of |
44 // WebDataServiceBase, which receive |wdbs| upon construction. The | 44 // WebDataServiceBase, which receive |wdbs| upon construction. The |
45 // WebDataServiceWrapper handles the initializing and shutting down and of | 45 // WebDataServiceWrapper handles the initializing and shutting down and of |
46 // the |wdbs| object. | 46 // the |wdbs| object. |
| 47 // WebDataServiceBase is destroyed on |ui_thread|. |
47 WebDataServiceBase(scoped_refptr<WebDatabaseService> wdbs, | 48 WebDataServiceBase(scoped_refptr<WebDatabaseService> wdbs, |
48 const ProfileErrorCallback& callback); | 49 const ProfileErrorCallback& callback, |
| 50 const scoped_refptr<base::MessageLoopProxy>& ui_thread); |
49 | 51 |
50 // Cancel any pending request. You need to call this method if your | 52 // Cancel any pending request. You need to call this method if your |
51 // WebDataServiceConsumer is about to be deleted. | 53 // WebDataServiceConsumer is about to be deleted. |
52 virtual void CancelRequest(Handle h); | 54 virtual void CancelRequest(Handle h); |
53 | 55 |
54 // Shutdown the web data service. The service can no longer be used after this | 56 // Shutdown the web data service. The service can no longer be used after this |
55 // call. | 57 // call. |
56 virtual void ShutdownOnUIThread(); | 58 virtual void ShutdownOnUIThread(); |
57 | 59 |
58 // Initializes the web data service. | 60 // Initializes the web data service. |
(...skipping 17 matching lines...) Expand all Loading... |
76 // Returns true if the database load has completetd successfully, and | 78 // Returns true if the database load has completetd successfully, and |
77 // ShutdownOnUIThread has not yet been called. | 79 // ShutdownOnUIThread has not yet been called. |
78 virtual bool IsDatabaseLoaded(); | 80 virtual bool IsDatabaseLoaded(); |
79 | 81 |
80 // Returns a pointer to the DB (used by SyncableServices). May return NULL if | 82 // Returns a pointer to the DB (used by SyncableServices). May return NULL if |
81 // the database is not loaded or otherwise unavailable. Must be called on | 83 // the database is not loaded or otherwise unavailable. Must be called on |
82 // DBThread. | 84 // DBThread. |
83 virtual WebDatabase* GetDatabase(); | 85 virtual WebDatabase* GetDatabase(); |
84 | 86 |
85 protected: | 87 protected: |
| 88 friend class base::RefCountedDeleteOnMessageLoop<WebDataServiceBase>; |
| 89 friend class base::DeleteHelper<WebDataServiceBase>; |
| 90 |
86 virtual ~WebDataServiceBase(); | 91 virtual ~WebDataServiceBase(); |
87 | 92 |
88 // Our database service. | 93 // Our database service. |
89 scoped_refptr<WebDatabaseService> wdbs_; | 94 scoped_refptr<WebDatabaseService> wdbs_; |
90 | 95 |
91 private: | 96 private: |
92 friend struct content::BrowserThread::DeleteOnThread< | |
93 content::BrowserThread::UI>; | |
94 friend class base::DeleteHelper<WebDataServiceBase>; | |
95 // We have to friend RCTS<> so WIN shared-lib build is happy (crbug/112250). | |
96 friend class base::RefCountedThreadSafe<WebDataServiceBase, | |
97 content::BrowserThread::DeleteOnUIThread>; | |
98 | |
99 ProfileErrorCallback profile_error_callback_; | 97 ProfileErrorCallback profile_error_callback_; |
100 }; | 98 }; |
101 | 99 |
102 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BASE_H_ | 100 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BASE_H_ |
OLD | NEW |