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

Side by Side Diff: sql/connection.h

Issue 10540155: 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, 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 unified diff | Download patch
« no previous file with comments | « no previous file | sql/connection.cc » ('j') | sql/connection.cc » ('J')
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 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/threading/thread_restrictions.h"
16 #include "base/time.h" 17 #include "base/time.h"
17 #include "sql/sql_export.h" 18 #include "sql/sql_export.h"
18 19
19 class FilePath; 20 class FilePath;
20 struct sqlite3; 21 struct sqlite3;
21 struct sqlite3_stmt; 22 struct sqlite3_stmt;
22 23
23 namespace sql { 24 namespace sql {
24 25
25 class Statement; 26 class Statement;
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 private: 315 private:
315 // Statement accesses StatementRef which we don't want to expose to everybody 316 // Statement accesses StatementRef which we don't want to expose to everybody
316 // (they should go through Statement). 317 // (they should go through Statement).
317 friend class Statement; 318 friend class Statement;
318 319
319 // Internal initialize function used by both Init and InitInMemory. The file 320 // 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 321 // 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. 322 // sqlite3_open. The string can also be sqlite's special ":memory:" string.
322 bool OpenInternal(const std::string& file_name); 323 bool OpenInternal(const std::string& file_name);
323 324
325 // Check whether the current thread is allowed to make IO calls, but only
326 // if database wasn't open in memory.
327 void AssertIOAllowed() {
328 if (!in_memory_)
329 base::ThreadRestrictions::AssertIOAllowed();
330 }
331
324 // Internal helper for DoesTableExist and DoesIndexExist. 332 // Internal helper for DoesTableExist and DoesIndexExist.
325 bool DoesTableOrIndexExist(const char* name, const char* type) const; 333 bool DoesTableOrIndexExist(const char* name, const char* type) const;
326 334
327 // A StatementRef is a refcounted wrapper around a sqlite statement pointer. 335 // A StatementRef is a refcounted wrapper around a sqlite statement pointer.
328 // Refcounting allows us to give these statements out to sql::Statement 336 // Refcounting allows us to give these statements out to sql::Statement
329 // objects while also optionally maintaining a cache of compiled statements 337 // objects while also optionally maintaining a cache of compiled statements
330 // by just keeping a refptr to these objects. 338 // by just keeping a refptr to these objects.
331 // 339 //
332 // 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
333 // 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
349 Connection* connection() const { return connection_; } 357 Connection* connection() const { return connection_; }
350 358
351 // 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,
352 // this will return NULL. 360 // this will return NULL.
353 sqlite3_stmt* stmt() const { return stmt_; } 361 sqlite3_stmt* stmt() const { return stmt_; }
354 362
355 // Destroys the compiled statement and marks it NULL. The statement will 363 // Destroys the compiled statement and marks it NULL. The statement will
356 // no longer be active. 364 // no longer be active.
357 void Close(); 365 void Close();
358 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() { return connection_->AssertIOAllowed(); }
370
359 private: 371 private:
360 friend class base::RefCounted<StatementRef>; 372 friend class base::RefCounted<StatementRef>;
361 373
362 ~StatementRef(); 374 ~StatementRef();
363 375
364 Connection* connection_; 376 Connection* connection_;
365 sqlite3_stmt* stmt_; 377 sqlite3_stmt* stmt_;
366 378
367 DISALLOW_COPY_AND_ASSIGN(StatementRef); 379 DISALLOW_COPY_AND_ASSIGN(StatementRef);
368 }; 380 };
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 StatementRefSet open_statements_; 423 StatementRefSet open_statements_;
412 424
413 // Number of currently-nested transactions. 425 // Number of currently-nested transactions.
414 int transaction_nesting_; 426 int transaction_nesting_;
415 427
416 // 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.
417 // 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
418 // a rollback instead of a commit. 430 // a rollback instead of a commit.
419 bool needs_rollback_; 431 bool needs_rollback_;
420 432
433 // True if database is open with OpenInMemory(), False if database is open
434 // with Open().
435 bool in_memory_;
436
421 // This object handles errors resulting from all forms of executing sqlite 437 // This object handles errors resulting from all forms of executing sqlite
422 // commands or statements. It can be null which means default handling. 438 // commands or statements. It can be null which means default handling.
423 scoped_refptr<ErrorDelegate> error_delegate_; 439 scoped_refptr<ErrorDelegate> error_delegate_;
424 440
425 DISALLOW_COPY_AND_ASSIGN(Connection); 441 DISALLOW_COPY_AND_ASSIGN(Connection);
426 }; 442 };
427 443
428 } // namespace sql 444 } // namespace sql
429 445
430 #endif // SQL_CONNECTION_H_ 446 #endif // SQL_CONNECTION_H_
OLDNEW
« no previous file with comments | « no previous file | sql/connection.cc » ('j') | sql/connection.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698