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

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

Issue 15927029: Replace WebDatabaseObserver with callbacks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // Chromium settings and storage represent user-selected preferences and 5 // Chromium settings and storage represent user-selected preferences and
6 // information and MUST not be extracted, overwritten or modified except 6 // information and MUST not be extracted, overwritten or modified except
7 // through Chromium defined APIs. 7 // through Chromium defined APIs.
8 8
9 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ 9 #ifndef COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_
10 #define COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ 10 #define COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 virtual WebDataServiceBase::Handle ScheduleDBTaskWithResult( 86 virtual WebDataServiceBase::Handle ScheduleDBTaskWithResult(
87 const tracked_objects::Location& from_here, 87 const tracked_objects::Location& from_here,
88 const ReadTask& task, 88 const ReadTask& task,
89 WebDataServiceConsumer* consumer); 89 WebDataServiceConsumer* consumer);
90 90
91 // Cancel an existing request for a task on the DB thread. 91 // Cancel an existing request for a task on the DB thread.
92 // TODO(caitkp): Think about moving the definition of the Handle type to 92 // TODO(caitkp): Think about moving the definition of the Handle type to
93 // somewhere else. 93 // somewhere else.
94 virtual void CancelRequest(WebDataServiceBase::Handle h); 94 virtual void CancelRequest(WebDataServiceBase::Handle h);
95 95
96 void AddObserver(WebDatabaseObserver* observer); 96 // Register a callback to be notified that the database has loaded.
97 void RemoveObserver(WebDatabaseObserver* observer); 97 void RegisterDBLoadedCallback(const base::Callback<void(void)>& callback);
98
99 // Register a callback to be notified that the database has failed to load.
100 void RegisterDBErrorCallback(
101 const base::Callback<void(sql::InitStatus)>& callback);
102
103 bool db_loaded() { return db_loaded_; };
98 104
99 private: 105 private:
100 class BackendDelegate; 106 class BackendDelegate;
101 friend struct content::BrowserThread::DeleteOnThread< 107 friend struct content::BrowserThread::DeleteOnThread<
102 content::BrowserThread::UI>; 108 content::BrowserThread::UI>;
103 friend class base::DeleteHelper<WebDatabaseService>; 109 friend class base::DeleteHelper<WebDatabaseService>;
104 // We have to friend RCTS<> so WIN shared-lib build is happy (crbug/112250). 110 // We have to friend RCTS<> so WIN shared-lib build is happy (crbug/112250).
105 friend class base::RefCountedThreadSafe<WebDatabaseService, 111 friend class base::RefCountedThreadSafe<WebDatabaseService,
106 content::BrowserThread::DeleteOnUIThread>; 112 content::BrowserThread::DeleteOnUIThread>;
107 friend class BackendDelegate; 113 friend class BackendDelegate;
108 114
109 virtual ~WebDatabaseService(); 115 virtual ~WebDatabaseService();
110 116
111 void OnDatabaseLoadDone(sql::InitStatus status); 117 void OnDatabaseLoadDone(sql::InitStatus status);
112 118
113 base::FilePath path_; 119 base::FilePath path_;
114 120
115 // The primary owner is |WebDatabaseService| but is refcounted because 121 // The primary owner is |WebDatabaseService| but is refcounted because
116 // PostTask on DB thread may outlive us. 122 // PostTask on DB thread may outlive us.
117 scoped_refptr<WebDataServiceBackend> wds_backend_; 123 scoped_refptr<WebDataServiceBackend> wds_backend_;
118 124
119 ObserverList<WebDatabaseObserver> observer_list_;
120
121 // All vended weak pointers are invalidated in ShutdownDatabase(). 125 // All vended weak pointers are invalidated in ShutdownDatabase().
122 base::WeakPtrFactory<WebDatabaseService> weak_ptr_factory_; 126 base::WeakPtrFactory<WebDatabaseService> weak_ptr_factory_;
127
128 // Types for managing DB laoding callbacks.
Jói 2013/06/04 22:17:25 laoding -> loading
Cait (Slow) 2013/06/05 19:14:48 Done.
129 typedef base::Callback<void(void)> DBLoadedCallback;
130 typedef std::vector<DBLoadedCallback> PendingCallbacks;
Jói 2013/06/04 22:17:25 For consistency, suggest renaming to LoadedCallbac
Cait (Slow) 2013/06/05 19:14:48 Done.
131
132 typedef base::Callback<void(sql::InitStatus)> DBLoadErrorCallback;
133 typedef std::vector<DBLoadErrorCallback> ErrorCallbacks;
134
135 // Callbacks to be called once the DB has loaded.
136 PendingCallbacks pending_callbacks_;
Jói 2013/06/04 22:17:25 variable name too
Cait (Slow) 2013/06/05 19:14:48 Done.
137
138 // Callbacks to be called if the DB has failed to load.
139 ErrorCallbacks error_callbacks_;
140
141 // True if the WebDatabase has loaded.
142 bool db_loaded_;
123 }; 143 };
124 144
125 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_ 145 #endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698