| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/common/sqlite_utils.h" | 5 #include "chrome/common/sqlite_utils.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/lock.h" | 10 #include "base/lock.h" |
| 11 #include "base/lazy_instance.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/singleton.h" | |
| 13 #include "base/stl_util-inl.h" | 13 #include "base/stl_util-inl.h" |
| 14 #include "base/string16.h" | 14 #include "base/string16.h" |
| 15 | 15 |
| 16 // The vanilla error handler implements the common fucntionality for all the | 16 // The vanilla error handler implements the common fucntionality for all the |
| 17 // error handlers. Specialized error handlers are expected to only override | 17 // error handlers. Specialized error handlers are expected to only override |
| 18 // the Handler() function. | 18 // the Handler() function. |
| 19 class VanillaSQLErrorHandler : public SQLErrorHandler { | 19 class VanillaSQLErrorHandler : public SQLErrorHandler { |
| 20 public: | 20 public: |
| 21 VanillaSQLErrorHandler() : error_(SQLITE_OK) { | 21 VanillaSQLErrorHandler() : error_(SQLITE_OK) { |
| 22 } | 22 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 void AddHandler(SQLErrorHandler* handler) { | 69 void AddHandler(SQLErrorHandler* handler) { |
| 70 AutoLock lock(lock_); | 70 AutoLock lock(lock_); |
| 71 errors_.push_back(handler); | 71 errors_.push_back(handler); |
| 72 } | 72 } |
| 73 | 73 |
| 74 typedef std::list<SQLErrorHandler*> ErrorList; | 74 typedef std::list<SQLErrorHandler*> ErrorList; |
| 75 ErrorList errors_; | 75 ErrorList errors_; |
| 76 Lock lock_; | 76 Lock lock_; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 static base::LazyInstance<DefaultSQLErrorHandlerFactory> |
| 80 g_default_sql_error_handler_factory(base::LINKER_INITIALIZED); |
| 81 |
| 79 SQLErrorHandlerFactory* GetErrorHandlerFactory() { | 82 SQLErrorHandlerFactory* GetErrorHandlerFactory() { |
| 80 // TODO(cpu): Testing needs to override the error handler. | 83 // TODO(cpu): Testing needs to override the error handler. |
| 81 // Destruction of DefaultSQLErrorHandlerFactory handled by at_exit manager. | 84 // Destruction of DefaultSQLErrorHandlerFactory handled by at_exit manager. |
| 82 return Singleton<DefaultSQLErrorHandlerFactory>::get(); | 85 return g_default_sql_error_handler_factory.Pointer(); |
| 83 } | 86 } |
| 84 | 87 |
| 85 namespace sqlite_utils { | 88 namespace sqlite_utils { |
| 86 | 89 |
| 87 int OpenSqliteDb(const FilePath& filepath, sqlite3** database) { | 90 int OpenSqliteDb(const FilePath& filepath, sqlite3** database) { |
| 88 #if defined(OS_WIN) | 91 #if defined(OS_WIN) |
| 89 // We want the default encoding to always be UTF-8, so we use the | 92 // We want the default encoding to always be UTF-8, so we use the |
| 90 // 8-bit version of open(). | 93 // 8-bit version of open(). |
| 91 return sqlite3_open(WideToUTF8(filepath.value()).c_str(), database); | 94 return sqlite3_open(WideToUTF8(filepath.value()).c_str(), database); |
| 92 #elif defined(OS_POSIX) | 95 #elif defined(OS_POSIX) |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 const char* s = column_text(index); | 501 const char* s = column_text(index); |
| 499 str->assign(s ? UTF8ToWide(s) : std::wstring()); | 502 str->assign(s ? UTF8ToWide(s) : std::wstring()); |
| 500 return (s != NULL); | 503 return (s != NULL); |
| 501 } | 504 } |
| 502 | 505 |
| 503 std::wstring SQLStatement::column_wstring(int index) { | 506 std::wstring SQLStatement::column_wstring(int index) { |
| 504 std::wstring wstr; | 507 std::wstring wstr; |
| 505 column_wstring(index, &wstr); | 508 column_wstring(index, &wstr); |
| 506 return wstr; | 509 return wstr; |
| 507 } | 510 } |
| OLD | NEW |