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

Side by Side Diff: sql/connection.h

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

Powered by Google App Engine
This is Rietveld 408576698