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

Side by Side Diff: chrome/browser/api/webdata/web_data_service_base.h

Issue 13392014: Move c/b/webdata/ code to components/webdata/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Pure merge Created 7 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_
6 #define CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_
7
8 #include "base/callback_forward.h"
9 #include "base/files/file_path.h"
10 #include "base/memory/ref_counted.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/supports_user_data.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/notification_source.h"
15 #include "sql/init_status.h"
16
17 class WebDatabase;
18 class WebDatabaseService;
19 class WebDatabaseTable;
20
21 namespace base {
22 class Thread;
23 }
24
25 // Base for WebDataService class hierarchy.
26 class WebDataServiceBase
27 : public base::RefCountedThreadSafe<WebDataServiceBase,
28 content::BrowserThread::DeleteOnUIThread> {
29 public:
30 // All requests return an opaque handle of the following type.
31 typedef int Handle;
32
33 // Users of this class may provide a callback to handle errors
34 // (e.g. by showing a UI). The callback is called only on error, and
35 // takes a single parameter, the sql::InitStatus value from trying
36 // to open the database.
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 false.
42 //
43 // The ownership of |wdbs| is shared, with the primary owner being the
44 // WebDataServiceWrapper, and secondary owners being subclasses of
45 // WebDataServiceBase, which receive |wdbs| upon construction. The
46 // WebDataServiceWrapper handles the initializing and shutting down and of
47 // the |wdbs| object.
48 WebDataServiceBase(scoped_refptr<WebDatabaseService> wdbs,
49 const ProfileErrorCallback& callback);
50
51 // Cancel any pending request. You need to call this method if your
52 // WebDataServiceConsumer is about to be deleted.
53 virtual void CancelRequest(Handle h);
54
55 // Returns the notification source for this service. This may use a
56 // pointer other than this object's |this| pointer.
57 virtual content::NotificationSource GetNotificationSource();
58
59 // Shutdown the web data service. The service can no longer be used after this
60 // call.
61 virtual void ShutdownOnUIThread();
62
63 // Initializes the web data service.
64 virtual void Init();
65
66 // Unloads the database without actually shutting down the service. This can
67 // be used to temporarily reduce the browser process' memory footprint.
68 void UnloadDatabase();
69
70 // Unloads the database permanently and shuts down service.
71 void ShutdownDatabase();
72
73 // Returns true if the database load has completetd successfully, and
74 // ShutdownOnUIThread has not yet been called.
75 virtual bool IsDatabaseLoaded();
76
77 // Returns a pointer to the DB (used by SyncableServices). May return NULL if
78 // the database is not loaded or otherwise unavailable. Must be called on
79 // DBThread.
80 virtual WebDatabase* GetDatabase();
81
82 // Returns a SupportsUserData objects that may be used to store data
83 // owned by the DB thread on this object. Should be called only from
84 // the DB thread, and will be destroyed on the DB thread soon after
85 // |ShutdownOnUIThread()| is called.
86 base::SupportsUserData* GetDBUserData();
87
88 protected:
89 virtual ~WebDataServiceBase();
90 virtual void ShutdownOnDBThread();
91
92 // Our database service.
93 scoped_refptr<WebDatabaseService> wdbs_;
94
95 // True if we've received a notification that the WebDatabase has loaded.
96 bool db_loaded_;
97
98 private:
99 friend struct content::BrowserThread::DeleteOnThread<
100 content::BrowserThread::UI>;
101 friend class base::DeleteHelper<WebDataServiceBase>;
102
103 ProfileErrorCallback profile_error_callback_;
104
105 // This makes the destructor public, and thus allows us to aggregate
106 // SupportsUserData. It is private by default to prevent incorrect
107 // usage in class hierarchies where it is inherited by
108 // reference-counted objects.
109 class SupportsUserDataAggregatable : public base::SupportsUserData {
110 public:
111 SupportsUserDataAggregatable() {}
112 virtual ~SupportsUserDataAggregatable() {}
113 private:
114 DISALLOW_COPY_AND_ASSIGN(SupportsUserDataAggregatable);
115 };
116
117 // Storage for user data to be accessed only on the DB thread. May
118 // be used e.g. for SyncableService subclasses that need to be owned
119 // by this object. Is created on first call to |GetDBUserData()|.
120 scoped_ptr<SupportsUserDataAggregatable> db_thread_user_data_;
121
122 // Called after database is successfully loaded. By default this function does
123 // nothing. Subclasses can override to support notification.
124 virtual void NotifyDatabaseLoadedOnUIThread();
125
126 void DBInitFailed(sql::InitStatus sql_status);
127 void DBInitSucceeded();
128 void DatabaseInitOnDB(sql::InitStatus status);
129 };
130
131 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698