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

Unified 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: comments 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 side-by-side diff with in-line comments
Download patch
Index: components/webdata/common/web_database_service.h
diff --git a/components/webdata/common/web_database_service.h b/components/webdata/common/web_database_service.h
index cd3ceae5394095e56d8f4ded5d2072393bfd68b3..28e89b09decc663c0af2d8b67660fa08ff186697 100644
--- a/components/webdata/common/web_database_service.h
+++ b/components/webdata/common/web_database_service.h
@@ -93,8 +93,22 @@ class WEBDATA_EXPORT WebDatabaseService
// somewhere else.
virtual void CancelRequest(WebDataServiceBase::Handle h);
- void AddObserver(WebDatabaseObserver* observer);
- void RemoveObserver(WebDatabaseObserver* observer);
+ // Register a callback to be notified that the database has loaded. Multiple
+ // callbacks may be registered, and each will be called at most once
+ // (following a successful database load), then cleared.
+ // Note: if the database load is already complete, then the callback will NOT
+ // be called.
+ void RegisterDBLoadedCallback(const base::Callback<void(void)>& callback);
+
+ // Register a callback to be notified that the database has failed to load.
+ // Multiple callbacks may be registered, and each will be called at most once
+ // (following a database load failure), then cleared.
+ // Note: if the database load is already complete, then the callback will NOT
+ // be called.
+ void RegisterDBErrorCallback(
+ const base::Callback<void(sql::InitStatus)>& callback);
+
+ bool db_loaded() { return db_loaded_; };
private:
class BackendDelegate;
@@ -116,10 +130,24 @@ class WEBDATA_EXPORT WebDatabaseService
// PostTask on DB thread may outlive us.
scoped_refptr<WebDataServiceBackend> wds_backend_;
- ObserverList<WebDatabaseObserver> observer_list_;
-
// All vended weak pointers are invalidated in ShutdownDatabase().
base::WeakPtrFactory<WebDatabaseService> weak_ptr_factory_;
+
+ // Types for managing DB loading callbacks.
+ typedef base::Callback<void(void)> DBLoadedCallback;
+ typedef std::vector<DBLoadedCallback> LoadedCallbacks;
+
+ typedef base::Callback<void(sql::InitStatus)> DBLoadErrorCallback;
+ typedef std::vector<DBLoadErrorCallback> ErrorCallbacks;
+
+ // Callbacks to be called once the DB has loaded.
+ LoadedCallbacks loaded_callbacks_;
+
+ // Callbacks to be called if the DB has failed to load.
+ ErrorCallbacks error_callbacks_;
+
+ // True if the WebDatabase has loaded.
+ bool db_loaded_;
};
#endif // COMPONENTS_WEBDATA_COMMON_WEB_DATABASE_SERVICE_H_

Powered by Google App Engine
This is Rietveld 408576698