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

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

Issue 12853004: Move creation of WebDatabaseTable subclasses to WebDatabaseServiceFactory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix path snafu. Created 7 years, 9 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 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/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 "content/public/browser/browser_thread.h" 13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/notification_source.h" 14 #include "content/public/browser/notification_source.h"
15 #include "sql/init_status.h" 15 #include "sql/init_status.h"
16 16
17 class WebDatabase; 17 class WebDatabase;
18 class WebDatabaseService; 18 class WebDatabaseService;
19 class WebDatabaseTable;
19 20
20 namespace base { 21 namespace base {
21 class Thread; 22 class Thread;
22 } 23 }
23 24
24 // Base for WebDataService class hierarchy. 25 // Base for WebDataService class hierarchy.
25 class WebDataServiceBase 26 class WebDataServiceBase
26 : public base::RefCountedThreadSafe<WebDataServiceBase, 27 : public base::RefCountedThreadSafe<WebDataServiceBase,
27 content::BrowserThread::DeleteOnUIThread> { 28 content::BrowserThread::DeleteOnUIThread> {
28 public: 29 public:
29 // All requests return an opaque handle of the following type. 30 // All requests return an opaque handle of the following type.
30 typedef int Handle; 31 typedef int Handle;
31 32
32 // Users of this class may provide a callback to handle errors 33 // 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 // (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 // takes a single parameter, the sql::InitStatus value from trying
35 // to open the database. 36 // to open the database.
36 // TODO(joi): Should we combine this with WebDatabaseService::InitCallback? 37 // TODO(joi): Should we combine this with WebDatabaseService::InitCallback?
37 typedef base::Callback<void(sql::InitStatus)> ProfileErrorCallback; 38 typedef base::Callback<void(sql::InitStatus)> ProfileErrorCallback;
38 39
39 // |callback| will only be invoked on error, and only if 40 // |callback| will only be invoked on error, and only if
40 // |callback.is_null()| evaluates to false. 41 // |callback.is_null()| evaluates to false.
41 explicit WebDataServiceBase(const ProfileErrorCallback& callback); 42 explicit WebDataServiceBase(const base::FilePath& path,
Cait (Slow) 2013/03/21 00:37:49 explicit not needed anymore.
kaiwang 2013/03/21 06:30:56 Done.
43 const ProfileErrorCallback& callback);
42 44
43 // 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
44 // WebDataServiceConsumer is about to be deleted. 46 // WebDataServiceConsumer is about to be deleted.
45 virtual void CancelRequest(Handle h); 47 virtual void CancelRequest(Handle h);
46 48
47 // Returns the notification source for this service. This may use a 49 // Returns the notification source for this service. This may use a
48 // pointer other than this object's |this| pointer. 50 // pointer other than this object's |this| pointer.
49 virtual content::NotificationSource GetNotificationSource(); 51 virtual content::NotificationSource GetNotificationSource();
50 52
51 // 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
52 // call. 54 // call.
53 virtual void ShutdownOnUIThread(); 55 virtual void ShutdownOnUIThread();
54 56
57 // Adds the given table to the database. Passes ownership. Must be
58 // called for all tables before Init.
59 //
60 // TODO(joi): This method is duplicated a couple of layers deep;
61 // once we have a single object creating the WebDatabaseService as
62 // well as all the XyzWebDataService objects, we should be able to
63 // simplify.
64 void AddTable(scoped_ptr<WebDatabaseTable> table);
65
55 // Initializes the web data service. 66 // Initializes the web data service.
56 virtual void Init(const base::FilePath& path); 67 virtual void Init();
57 68
58 // Unloads the database without actually shutting down the service. This can 69 // Unloads the database without actually shutting down the service. This can
59 // be used to temporarily reduce the browser process' memory footprint. 70 // be used to temporarily reduce the browser process' memory footprint.
60 void UnloadDatabase(); 71 void UnloadDatabase();
61 72
62 // Unloads the database permanently and shuts down service. 73 // Unloads the database permanently and shuts down service.
63 void ShutdownDatabase(); 74 void ShutdownDatabase();
64 75
65 // Returns true if the database load has completetd successfully, and 76 // Returns true if the database load has completetd successfully, and
66 // ShutdownOnUIThread has not yet been called. 77 // ShutdownOnUIThread has not yet been called.
(...skipping 18 matching lines...) Expand all
85 scoped_ptr<WebDatabaseService> wdbs_; 96 scoped_ptr<WebDatabaseService> wdbs_;
86 97
87 // True if we've received a notification that the WebDatabase has loaded. 98 // True if we've received a notification that the WebDatabase has loaded.
88 bool db_loaded_; 99 bool db_loaded_;
89 100
90 private: 101 private:
91 friend struct content::BrowserThread::DeleteOnThread< 102 friend struct content::BrowserThread::DeleteOnThread<
92 content::BrowserThread::UI>; 103 content::BrowserThread::UI>;
93 friend class base::DeleteHelper<WebDataServiceBase>; 104 friend class base::DeleteHelper<WebDataServiceBase>;
94 105
106 // TODO(caitkp): Get rid of this once we fully split
107 // AutofillWebDataService and WebDatabaseService away from
108 // WebDataService.
109 base::FilePath path_;
110
95 ProfileErrorCallback profile_error_callback_; 111 ProfileErrorCallback profile_error_callback_;
96 112
97 // This makes the destructor public, and thus allows us to aggregate 113 // This makes the destructor public, and thus allows us to aggregate
98 // SupportsUserData. It is private by default to prevent incorrect 114 // SupportsUserData. It is private by default to prevent incorrect
99 // usage in class hierarchies where it is inherited by 115 // usage in class hierarchies where it is inherited by
100 // reference-counted objects. 116 // reference-counted objects.
101 class SupportsUserDataAggregatable : public base::SupportsUserData { 117 class SupportsUserDataAggregatable : public base::SupportsUserData {
102 public: 118 public:
103 SupportsUserDataAggregatable() {} 119 SupportsUserDataAggregatable() {}
104 virtual ~SupportsUserDataAggregatable() {} 120 virtual ~SupportsUserDataAggregatable() {}
105 private: 121 private:
106 DISALLOW_COPY_AND_ASSIGN(SupportsUserDataAggregatable); 122 DISALLOW_COPY_AND_ASSIGN(SupportsUserDataAggregatable);
107 }; 123 };
108 124
109 // Storage for user data to be accessed only on the DB thread. May 125 // Storage for user data to be accessed only on the DB thread. May
110 // be used e.g. for SyncableService subclasses that need to be owned 126 // be used e.g. for SyncableService subclasses that need to be owned
111 // by this object. Is created on first call to |GetDBUserData()|. 127 // by this object. Is created on first call to |GetDBUserData()|.
112 scoped_ptr<SupportsUserDataAggregatable> db_thread_user_data_; 128 scoped_ptr<SupportsUserDataAggregatable> db_thread_user_data_;
113 129
114 void DBInitFailed(sql::InitStatus sql_status); 130 void DBInitFailed(sql::InitStatus sql_status);
115 void NotifyDatabaseLoadedOnUIThread(); 131 void NotifyDatabaseLoadedOnUIThread();
116 void DatabaseInitOnDB(sql::InitStatus status); 132 void DatabaseInitOnDB(sql::InitStatus status);
117 }; 133 };
118 134
119 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_ 135 #endif // CHROME_BROWSER_API_WEBDATA_WEB_DATA_SERVICE_BASE_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/webdata/autofill_web_data_service_impl.cc » ('j') | chrome/browser/webdata/web_data_service.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698