| OLD | NEW |
| 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 SQL_CONNECTION_H_ | 5 #ifndef SQL_CONNECTION_H_ |
| 6 #define SQL_CONNECTION_H_ | 6 #define SQL_CONNECTION_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 // Refcounting allows us to give these statements out to sql::Statement | 452 // Refcounting allows us to give these statements out to sql::Statement |
| 453 // objects while also optionally maintaining a cache of compiled statements | 453 // objects while also optionally maintaining a cache of compiled statements |
| 454 // by just keeping a refptr to these objects. | 454 // by just keeping a refptr to these objects. |
| 455 // | 455 // |
| 456 // A statement ref can be valid, in which case it can be used, or invalid to | 456 // A statement ref can be valid, in which case it can be used, or invalid to |
| 457 // indicate that the statement hasn't been created yet, has an error, or has | 457 // indicate that the statement hasn't been created yet, has an error, or has |
| 458 // been destroyed. | 458 // been destroyed. |
| 459 // | 459 // |
| 460 // The Connection may revoke a StatementRef in some error cases, so callers | 460 // The Connection may revoke a StatementRef in some error cases, so callers |
| 461 // should always check validity before using. | 461 // should always check validity before using. |
| 462 class SQL_EXPORT StatementRef : public base::RefCounted<StatementRef> { | 462 // TODO(mgiuca): Avoid using UnsafeRefCounted. http://crbug.com/469952. |
| 463 class SQL_EXPORT StatementRef : public base::UnsafeRefCounted<StatementRef> { |
| 463 public: | 464 public: |
| 464 // |connection| is the sql::Connection instance associated with | 465 // |connection| is the sql::Connection instance associated with |
| 465 // the statement, and is used for tracking outstanding statements | 466 // the statement, and is used for tracking outstanding statements |
| 466 // and for error handling. Set to NULL for invalid or untracked | 467 // and for error handling. Set to NULL for invalid or untracked |
| 467 // refs. |stmt| is the actual statement, and should only be NULL | 468 // refs. |stmt| is the actual statement, and should only be NULL |
| 468 // to create an invalid ref. |was_valid| indicates whether the | 469 // to create an invalid ref. |was_valid| indicates whether the |
| 469 // statement should be considered valid for diagnistic purposes. | 470 // statement should be considered valid for diagnistic purposes. |
| 470 // |was_valid| can be true for NULL |stmt| if the connection has | 471 // |was_valid| can be true for NULL |stmt| if the connection has |
| 471 // been forcibly closed by an error handler. | 472 // been forcibly closed by an error handler. |
| 472 StatementRef(Connection* connection, sqlite3_stmt* stmt, bool was_valid); | 473 StatementRef(Connection* connection, sqlite3_stmt* stmt, bool was_valid); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 491 // Destroys the compiled statement and marks it NULL. The statement will | 492 // Destroys the compiled statement and marks it NULL. The statement will |
| 492 // no longer be active. |forced| is used to indicate if orderly-shutdown | 493 // no longer be active. |forced| is used to indicate if orderly-shutdown |
| 493 // checks should apply (see Connection::RazeAndClose()). | 494 // checks should apply (see Connection::RazeAndClose()). |
| 494 void Close(bool forced); | 495 void Close(bool forced); |
| 495 | 496 |
| 496 // Check whether the current thread is allowed to make IO calls, but only | 497 // Check whether the current thread is allowed to make IO calls, but only |
| 497 // if database wasn't open in memory. | 498 // if database wasn't open in memory. |
| 498 void AssertIOAllowed() { if (connection_) connection_->AssertIOAllowed(); } | 499 void AssertIOAllowed() { if (connection_) connection_->AssertIOAllowed(); } |
| 499 | 500 |
| 500 private: | 501 private: |
| 501 friend class base::RefCounted<StatementRef>; | 502 friend class base::UnsafeRefCounted<StatementRef>; |
| 502 | 503 |
| 503 ~StatementRef(); | 504 ~StatementRef(); |
| 504 | 505 |
| 505 Connection* connection_; | 506 Connection* connection_; |
| 506 sqlite3_stmt* stmt_; | 507 sqlite3_stmt* stmt_; |
| 507 bool was_valid_; | 508 bool was_valid_; |
| 508 | 509 |
| 509 DISALLOW_COPY_AND_ASSIGN(StatementRef); | 510 DISALLOW_COPY_AND_ASSIGN(StatementRef); |
| 510 }; | 511 }; |
| 511 friend class StatementRef; | 512 friend class StatementRef; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 | 593 |
| 593 // Tag for auxiliary histograms. | 594 // Tag for auxiliary histograms. |
| 594 std::string histogram_tag_; | 595 std::string histogram_tag_; |
| 595 | 596 |
| 596 DISALLOW_COPY_AND_ASSIGN(Connection); | 597 DISALLOW_COPY_AND_ASSIGN(Connection); |
| 597 }; | 598 }; |
| 598 | 599 |
| 599 } // namespace sql | 600 } // namespace sql |
| 600 | 601 |
| 601 #endif // SQL_CONNECTION_H_ | 602 #endif // SQL_CONNECTION_H_ |
| OLD | NEW |