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

Side by Side Diff: sql/connection.h

Issue 10806025: Revert 147309 - Annotate calls to SQLite functions - they have to be executed on a thread allowing … (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
« no previous file with comments | « chrome/browser/net/sqlite_server_bound_cert_store.cc ('k') | sql/connection.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/threading/thread_restrictions.h"
16 #include "base/time.h" 15 #include "base/time.h"
17 #include "sql/sql_export.h" 16 #include "sql/sql_export.h"
18 17
19 class FilePath; 18 class FilePath;
20 struct sqlite3; 19 struct sqlite3;
21 struct sqlite3_stmt; 20 struct sqlite3_stmt;
22 21
23 namespace sql { 22 namespace sql {
24 23
25 class Statement; 24 class Statement;
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 private: 313 private:
315 // Statement accesses StatementRef which we don't want to expose to everybody 314 // Statement accesses StatementRef which we don't want to expose to everybody
316 // (they should go through Statement). 315 // (they should go through Statement).
317 friend class Statement; 316 friend class Statement;
318 317
319 // Internal initialize function used by both Init and InitInMemory. The file 318 // Internal initialize function used by both Init and InitInMemory. The file
320 // name is always 8 bits since we want to use the 8-bit version of 319 // name is always 8 bits since we want to use the 8-bit version of
321 // sqlite3_open. The string can also be sqlite's special ":memory:" string. 320 // sqlite3_open. The string can also be sqlite's special ":memory:" string.
322 bool OpenInternal(const std::string& file_name); 321 bool OpenInternal(const std::string& file_name);
323 322
324 // Check whether the current thread is allowed to make IO calls, but only
325 // if database wasn't open in memory. Function is inlined to be a no-op in
326 // official build.
327 void AssertIOAllowed() {
328 if (!in_memory_)
329 base::ThreadRestrictions::AssertIOAllowed();
330 }
331
332 // Internal helper for DoesTableExist and DoesIndexExist. 323 // Internal helper for DoesTableExist and DoesIndexExist.
333 bool DoesTableOrIndexExist(const char* name, const char* type) const; 324 bool DoesTableOrIndexExist(const char* name, const char* type) const;
334 325
335 // A StatementRef is a refcounted wrapper around a sqlite statement pointer. 326 // A StatementRef is a refcounted wrapper around a sqlite statement pointer.
336 // Refcounting allows us to give these statements out to sql::Statement 327 // Refcounting allows us to give these statements out to sql::Statement
337 // objects while also optionally maintaining a cache of compiled statements 328 // objects while also optionally maintaining a cache of compiled statements
338 // by just keeping a refptr to these objects. 329 // by just keeping a refptr to these objects.
339 // 330 //
340 // A statement ref can be valid, in which case it can be used, or invalid to 331 // A statement ref can be valid, in which case it can be used, or invalid to
341 // indicate that the statement hasn't been created yet, has an error, or has 332 // indicate that the statement hasn't been created yet, has an error, or has
(...skipping 15 matching lines...) Expand all
357 Connection* connection() const { return connection_; } 348 Connection* connection() const { return connection_; }
358 349
359 // Returns the sqlite statement if any. If the statement is not active, 350 // Returns the sqlite statement if any. If the statement is not active,
360 // this will return NULL. 351 // this will return NULL.
361 sqlite3_stmt* stmt() const { return stmt_; } 352 sqlite3_stmt* stmt() const { return stmt_; }
362 353
363 // Destroys the compiled statement and marks it NULL. The statement will 354 // Destroys the compiled statement and marks it NULL. The statement will
364 // no longer be active. 355 // no longer be active.
365 void Close(); 356 void Close();
366 357
367 // Check whether the current thread is allowed to make IO calls, but only
368 // if database wasn't open in memory.
369 void AssertIOAllowed() { if (connection_) connection_->AssertIOAllowed(); }
370
371 private: 358 private:
372 friend class base::RefCounted<StatementRef>; 359 friend class base::RefCounted<StatementRef>;
373 360
374 ~StatementRef(); 361 ~StatementRef();
375 362
376 Connection* connection_; 363 Connection* connection_;
377 sqlite3_stmt* stmt_; 364 sqlite3_stmt* stmt_;
378 365
379 DISALLOW_COPY_AND_ASSIGN(StatementRef); 366 DISALLOW_COPY_AND_ASSIGN(StatementRef);
380 }; 367 };
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 StatementRefSet open_statements_; 410 StatementRefSet open_statements_;
424 411
425 // Number of currently-nested transactions. 412 // Number of currently-nested transactions.
426 int transaction_nesting_; 413 int transaction_nesting_;
427 414
428 // True if any of the currently nested transactions have been rolled back. 415 // True if any of the currently nested transactions have been rolled back.
429 // When we get to the outermost transaction, this will determine if we do 416 // When we get to the outermost transaction, this will determine if we do
430 // a rollback instead of a commit. 417 // a rollback instead of a commit.
431 bool needs_rollback_; 418 bool needs_rollback_;
432 419
433 // True if database is open with OpenInMemory(), False if database is open
434 // with Open().
435 bool in_memory_;
436
437 // This object handles errors resulting from all forms of executing sqlite 420 // This object handles errors resulting from all forms of executing sqlite
438 // commands or statements. It can be null which means default handling. 421 // commands or statements. It can be null which means default handling.
439 scoped_refptr<ErrorDelegate> error_delegate_; 422 scoped_refptr<ErrorDelegate> error_delegate_;
440 423
441 DISALLOW_COPY_AND_ASSIGN(Connection); 424 DISALLOW_COPY_AND_ASSIGN(Connection);
442 }; 425 };
443 426
444 } // namespace sql 427 } // namespace sql
445 428
446 #endif // SQL_CONNECTION_H_ 429 #endif // SQL_CONNECTION_H_
OLDNEW
« no previous file with comments | « chrome/browser/net/sqlite_server_bound_cert_store.cc ('k') | sql/connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698