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

Unified Diff: sql/connection.h

Issue 11111021: Remove ref counting on sql::ErrorDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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: sql/connection.h
diff --git a/sql/connection.h b/sql/connection.h
index 65020a04ebb86e0842f1048d119e2d88185b4fbf..fc0606898a167a653bf76384cebbf36f1e04b799 100644
--- a/sql/connection.h
+++ b/sql/connection.h
@@ -12,6 +12,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
#include "base/threading/thread_restrictions.h"
#include "base/time.h"
#include "sql/sql_export.h"
@@ -78,10 +79,12 @@ class Connection;
// the OnError() callback.
// The tipical usage is to centralize the code designed to handle database
// corruption, low-level IO errors or locking violations.
-class SQL_EXPORT ErrorDelegate : public base::RefCounted<ErrorDelegate> {
+class SQL_EXPORT ErrorDelegate {
public:
ErrorDelegate();
+ virtual ~ErrorDelegate();
+
// |error| is an sqlite result code as seen in sqlite\preprocessed\sqlite3.h
// |connection| is db connection where the error happened and |stmt| is
// our best guess at the statement that triggered the error. Do not store
@@ -95,10 +98,8 @@ class SQL_EXPORT ErrorDelegate : public base::RefCounted<ErrorDelegate> {
// that you return the original |error| or the appropiae error code.
virtual int OnError(int error, Connection* connection, Statement* stmt) = 0;
- protected:
- friend class base::RefCounted<ErrorDelegate>;
-
- virtual ~ErrorDelegate();
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ErrorDelegate);
};
class SQL_EXPORT Connection {
@@ -142,8 +143,9 @@ class SQL_EXPORT Connection {
// Sets the object that will handle errors. Recomended that it should be set
// before calling Open(). If not set, the default is to ignore errors on
// release and assert on debug builds.
+ // Takes ownership of |delegate|.
void set_error_delegate(ErrorDelegate* delegate) {
- error_delegate_ = delegate;
+ error_delegate_.reset(delegate);
}
// Initialization ------------------------------------------------------------
@@ -445,7 +447,7 @@ class SQL_EXPORT Connection {
// This object handles errors resulting from all forms of executing sqlite
// commands or statements. It can be null which means default handling.
- scoped_refptr<ErrorDelegate> error_delegate_;
+ scoped_ptr<ErrorDelegate> error_delegate_;
DISALLOW_COPY_AND_ASSIGN(Connection);
};

Powered by Google App Engine
This is Rietveld 408576698