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. |
blundell
2013/06/17 10:50:33
Add a comment saying that this class should be des
droger
2013/06/17 11:10:51
Done.
| |
25 class WEBDATA_EXPORT WebDataServiceBase | 25 class WEBDATA_EXPORT WebDataServiceBase |
26 : public base::RefCountedThreadSafe<WebDataServiceBase, | 26 : public base::RefCountedDeleteOnMessageLoop<WebDataServiceBase> { |
27 content::BrowserThread::DeleteOnUIThread> { | |
28 public: | 27 public: |
29 // All requests return an opaque handle of the following type. | 28 // All requests return an opaque handle of the following type. |
30 typedef int Handle; | 29 typedef int Handle; |
31 | 30 |
32 // Users of this class may provide a callback to handle errors | 31 // 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 | 32 // (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 | 33 // takes a single parameter, the sql::InitStatus value from trying |
35 // to open the database. | 34 // to open the database. |
36 // TODO(joi): Should we combine this with WebDatabaseService::InitCallback? | 35 // TODO(joi): Should we combine this with WebDatabaseService::InitCallback? |
37 typedef base::Callback<void(sql::InitStatus)> ProfileErrorCallback; | 36 typedef base::Callback<void(sql::InitStatus)> ProfileErrorCallback; |
38 | 37 |
39 // |callback| will only be invoked on error, and only if | 38 // |callback| will only be invoked on error, and only if |
40 // |callback.is_null()| evaluates to false. | 39 // |callback.is_null()| evaluates to false. |
41 // | 40 // |
42 // The ownership of |wdbs| is shared, with the primary owner being the | 41 // The ownership of |wdbs| is shared, with the primary owner being the |
43 // WebDataServiceWrapper, and secondary owners being subclasses of | 42 // WebDataServiceWrapper, and secondary owners being subclasses of |
44 // WebDataServiceBase, which receive |wdbs| upon construction. The | 43 // WebDataServiceBase, which receive |wdbs| upon construction. The |
45 // WebDataServiceWrapper handles the initializing and shutting down and of | 44 // WebDataServiceWrapper handles the initializing and shutting down and of |
46 // the |wdbs| object. | 45 // the |wdbs| object. |
47 WebDataServiceBase(scoped_refptr<WebDatabaseService> wdbs, | 46 WebDataServiceBase(scoped_refptr<WebDatabaseService> wdbs, |
48 const ProfileErrorCallback& callback); | 47 const ProfileErrorCallback& callback, |
48 const scoped_refptr<base::MessageLoopProxy>& ui_thread); | |
49 | 49 |
50 // Cancel any pending request. You need to call this method if your | 50 // Cancel any pending request. You need to call this method if your |
51 // WebDataServiceConsumer is about to be deleted. | 51 // WebDataServiceConsumer is about to be deleted. |
52 virtual void CancelRequest(Handle h); | 52 virtual void CancelRequest(Handle h); |
53 | 53 |
54 // Shutdown the web data service. The service can no longer be used after this | 54 // Shutdown the web data service. The service can no longer be used after this |
55 // call. | 55 // call. |
56 virtual void ShutdownOnUIThread(); | 56 virtual void ShutdownOnUIThread(); |
57 | 57 |
58 // Initializes the web data service. | 58 // Initializes the web data service. |
(...skipping 17 matching lines...) Expand all Loading... | |
76 // Returns true if the database load has completetd successfully, and | 76 // Returns true if the database load has completetd successfully, and |
77 // ShutdownOnUIThread has not yet been called. | 77 // ShutdownOnUIThread has not yet been called. |
78 virtual bool IsDatabaseLoaded(); | 78 virtual bool IsDatabaseLoaded(); |
79 | 79 |
80 // Returns a pointer to the DB (used by SyncableServices). May return NULL if | 80 // 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 | 81 // the database is not loaded or otherwise unavailable. Must be called on |
82 // DBThread. | 82 // DBThread. |
83 virtual WebDatabase* GetDatabase(); | 83 virtual WebDatabase* GetDatabase(); |
84 | 84 |
85 protected: | 85 protected: |
86 friend class base::RefCountedDeleteOnMessageLoop<WebDataServiceBase>; | |
87 friend class base::DeleteHelper<WebDataServiceBase>; | |
88 | |
86 virtual ~WebDataServiceBase(); | 89 virtual ~WebDataServiceBase(); |
87 | 90 |
88 // Our database service. | 91 // Our database service. |
89 scoped_refptr<WebDatabaseService> wdbs_; | 92 scoped_refptr<WebDatabaseService> wdbs_; |
90 | 93 |
91 private: | 94 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_; | 95 ProfileErrorCallback profile_error_callback_; |
100 }; | 96 }; |
101 | 97 |
102 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BASE_H_ | 98 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BASE_H_ |
OLD | NEW |