Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: components/webdata/common/web_data_service_base.h

Issue 14103021: Use Observer to notify of WebDB load instead of callbacks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix WIN builds Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_forward.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/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/supports_user_data.h" 12 #include "base/supports_user_data.h"
13 #include "components/webdata/common/web_database_observer.h"
13 #include "components/webdata/common/webdata_export.h" 14 #include "components/webdata/common/webdata_export.h"
14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/notification_source.h" 16 #include "content/public/browser/notification_source.h"
16 #include "sql/init_status.h" 17 #include "sql/init_status.h"
17 18
18 class WebDatabase; 19 class WebDatabase;
19 class WebDatabaseService; 20 class WebDatabaseService;
20 class WebDatabaseTable; 21 class WebDatabaseTable;
21 22
22 namespace base { 23 namespace base {
23 class Thread; 24 class Thread;
24 } 25 }
25 26
26 // Base for WebDataService class hierarchy. 27 // Base for WebDataService class hierarchy.
27 class WEBDATA_EXPORT WebDataServiceBase 28 class WEBDATA_EXPORT WebDataServiceBase
28 : public base::RefCountedThreadSafe<WebDataServiceBase, 29 : public WebDatabaseObserver,
30 public base::RefCountedThreadSafe<WebDataServiceBase,
29 content::BrowserThread::DeleteOnUIThread> { 31 content::BrowserThread::DeleteOnUIThread> {
30 public: 32 public:
31 // All requests return an opaque handle of the following type. 33 // All requests return an opaque handle of the following type.
32 typedef int Handle; 34 typedef int Handle;
33 35
34 // Users of this class may provide a callback to handle errors 36 // Users of this class may provide a callback to handle errors
35 // (e.g. by showing a UI). The callback is called only on error, and 37 // (e.g. by showing a UI). The callback is called only on error, and
36 // takes a single parameter, the sql::InitStatus value from trying 38 // takes a single parameter, the sql::InitStatus value from trying
37 // to open the database. 39 // to open the database.
38 // TODO(joi): Should we combine this with WebDatabaseService::InitCallback? 40 // TODO(joi): Should we combine this with WebDatabaseService::InitCallback?
39 typedef base::Callback<void(sql::InitStatus)> ProfileErrorCallback; 41 typedef base::Callback<void(sql::InitStatus)> ProfileErrorCallback;
40 42
41 // |callback| will only be invoked on error, and only if 43 // |callback| will only be invoked on error, and only if
42 // |callback.is_null()| evaluates to false. 44 // |callback.is_null()| evaluates to false.
43 // 45 //
44 // The ownership of |wdbs| is shared, with the primary owner being the 46 // The ownership of |wdbs| is shared, with the primary owner being the
45 // WebDataServiceWrapper, and secondary owners being subclasses of 47 // WebDataServiceWrapper, and secondary owners being subclasses of
46 // WebDataServiceBase, which receive |wdbs| upon construction. The 48 // WebDataServiceBase, which receive |wdbs| upon construction. The
47 // WebDataServiceWrapper handles the initializing and shutting down and of 49 // WebDataServiceWrapper handles the initializing and shutting down and of
48 // the |wdbs| object. 50 // the |wdbs| object.
49 WebDataServiceBase(scoped_refptr<WebDatabaseService> wdbs, 51 WebDataServiceBase(scoped_refptr<WebDatabaseService> wdbs,
50 const ProfileErrorCallback& callback); 52 const ProfileErrorCallback& callback);
51 53
54 // WebDatabaseObserver implementation.
55 virtual void WebDatabaseLoaded() OVERRIDE;
56 virtual void WebDatabaseLoadFailed(sql::InitStatus status) OVERRIDE;
57
52 // Cancel any pending request. You need to call this method if your 58 // Cancel any pending request. You need to call this method if your
53 // WebDataServiceConsumer is about to be deleted. 59 // WebDataServiceConsumer is about to be deleted.
54 virtual void CancelRequest(Handle h); 60 virtual void CancelRequest(Handle h);
55 61
56 // Returns the notification source for this service. This may use a 62 // Returns the notification source for this service. This may use a
57 // pointer other than this object's |this| pointer. 63 // pointer other than this object's |this| pointer.
58 virtual content::NotificationSource GetNotificationSource(); 64 virtual content::NotificationSource GetNotificationSource();
59 65
60 // Shutdown the web data service. The service can no longer be used after this 66 // Shutdown the web data service. The service can no longer be used after this
61 // call. 67 // call.
62 virtual void ShutdownOnUIThread(); 68 virtual void ShutdownOnUIThread();
63 69
64 // Initializes the web data service. 70 // Initializes the web data service.
65 virtual void Init(); 71 virtual void Init();
66 72
67 // Unloads the database without actually shutting down the service. This can 73 // Unloads the database without actually shutting down the service. This can
68 // be used to temporarily reduce the browser process' memory footprint. 74 // be used to temporarily reduce the browser process' memory footprint.
69 void UnloadDatabase(); 75 void UnloadDatabase();
70 76
71 // Unloads the database permanently and shuts down service. 77 // Unloads the database permanently and shuts down service.
72 void ShutdownDatabase(); 78 void ShutdownDatabase();
73 79
80 virtual void AddDBObserver(WebDatabaseObserver* observer);
81 virtual void RemoveDBObserver(WebDatabaseObserver* observer);
82
74 // Returns true if the database load has completetd successfully, and 83 // Returns true if the database load has completetd successfully, and
75 // ShutdownOnUIThread has not yet been called. 84 // ShutdownOnUIThread has not yet been called.
76 virtual bool IsDatabaseLoaded(); 85 virtual bool IsDatabaseLoaded();
77 86
78 // Returns a pointer to the DB (used by SyncableServices). May return NULL if 87 // Returns a pointer to the DB (used by SyncableServices). May return NULL if
79 // the database is not loaded or otherwise unavailable. Must be called on 88 // the database is not loaded or otherwise unavailable. Must be called on
80 // DBThread. 89 // DBThread.
81 virtual WebDatabase* GetDatabase(); 90 virtual WebDatabase* GetDatabase();
82 91
83 // Returns a SupportsUserData objects that may be used to store data 92 // Returns a SupportsUserData objects that may be used to store data
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 SupportsUserDataAggregatable() {} 124 SupportsUserDataAggregatable() {}
116 virtual ~SupportsUserDataAggregatable() {} 125 virtual ~SupportsUserDataAggregatable() {}
117 private: 126 private:
118 DISALLOW_COPY_AND_ASSIGN(SupportsUserDataAggregatable); 127 DISALLOW_COPY_AND_ASSIGN(SupportsUserDataAggregatable);
119 }; 128 };
120 129
121 // Storage for user data to be accessed only on the DB thread. May 130 // Storage for user data to be accessed only on the DB thread. May
122 // be used e.g. for SyncableService subclasses that need to be owned 131 // be used e.g. for SyncableService subclasses that need to be owned
123 // by this object. Is created on first call to |GetDBUserData()|. 132 // by this object. Is created on first call to |GetDBUserData()|.
124 scoped_ptr<SupportsUserDataAggregatable> db_thread_user_data_; 133 scoped_ptr<SupportsUserDataAggregatable> db_thread_user_data_;
125
126 // Called after database is successfully loaded. By default this function does
127 // nothing. Subclasses can override to support notification.
128 virtual void NotifyDatabaseLoadedOnUIThread();
129
130 void DBInitFailed(sql::InitStatus sql_status);
131 void DBInitSucceeded();
132 void DatabaseInitOnDB(sql::InitStatus status);
133 }; 134 };
134 135
135 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BASE_H_ 136 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATA_SERVICE_BASE_H_
OLDNEW
« no previous file with comments | « components/webdata/common/web_data_service_backend.cc ('k') | components/webdata/common/web_data_service_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698