| 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 #include "sql/connection.h" | 5 #include "sql/connection.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 #include "base/strings/string_split.h" | 26 #include "base/strings/string_split.h" |
| 27 #include "base/strings/string_util.h" | 27 #include "base/strings/string_util.h" |
| 28 #include "base/strings/stringprintf.h" | 28 #include "base/strings/stringprintf.h" |
| 29 #include "base/strings/utf_string_conversions.h" | 29 #include "base/strings/utf_string_conversions.h" |
| 30 #include "base/synchronization/lock.h" | 30 #include "base/synchronization/lock.h" |
| 31 #include "base/threading/thread_task_runner_handle.h" | 31 #include "base/threading/thread_task_runner_handle.h" |
| 32 #include "base/trace_event/memory_dump_manager.h" | 32 #include "base/trace_event/memory_dump_manager.h" |
| 33 #include "sql/connection_memory_dump_provider.h" | 33 #include "sql/connection_memory_dump_provider.h" |
| 34 #include "sql/meta_table.h" | 34 #include "sql/meta_table.h" |
| 35 #include "sql/statement.h" | 35 #include "sql/statement.h" |
| 36 #include "sql/vfs_wrapper.h" |
| 36 #include "third_party/sqlite/sqlite3.h" | 37 #include "third_party/sqlite/sqlite3.h" |
| 37 | 38 |
| 38 #if defined(OS_IOS) && defined(USE_SYSTEM_SQLITE) | 39 #if defined(OS_IOS) && defined(USE_SYSTEM_SQLITE) |
| 39 #include "base/ios/ios_util.h" | 40 #include "base/ios/ios_util.h" |
| 40 #include "third_party/sqlite/src/ext/icu/sqliteicu.h" | 41 #include "third_party/sqlite/src/ext/icu/sqliteicu.h" |
| 41 #endif | 42 #endif |
| 42 | 43 |
| 44 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 45 #include <CoreFoundation/CoreFoundation.h> |
| 46 #include <CoreServices/CoreServices.h> |
| 47 #endif |
| 48 |
| 43 namespace { | 49 namespace { |
| 44 | 50 |
| 51 #if defined(OS_MACOSX) && !defined(OS_IOS) |
| 52 void gross() { |
| 53 CFPreferencesSetAppValue(CFSTR("CSBackupDebugLogging"), |
| 54 kCFBooleanTrue, |
| 55 kCFPreferencesCurrentApplication); |
| 56 } |
| 57 #else |
| 58 void gross() { |
| 59 } |
| 60 #endif |
| 61 |
| 45 // Spin for up to a second waiting for the lock to clear when setting | 62 // Spin for up to a second waiting for the lock to clear when setting |
| 46 // up the database. | 63 // up the database. |
| 47 // TODO(shess): Better story on this. http://crbug.com/56559 | 64 // TODO(shess): Better story on this. http://crbug.com/56559 |
| 48 const int kBusyTimeoutSeconds = 1; | 65 const int kBusyTimeoutSeconds = 1; |
| 49 | 66 |
| 50 class ScopedBusyTimeout { | 67 class ScopedBusyTimeout { |
| 51 public: | 68 public: |
| 52 explicit ScopedBusyTimeout(sqlite3* db) | 69 explicit ScopedBusyTimeout(sqlite3* db) |
| 53 : db_(db) { | 70 : db_(db) { |
| 54 } | 71 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // | 169 // |
| 153 // TODO(shess): Another alternative would be to have | 170 // TODO(shess): Another alternative would be to have |
| 154 // sqlite3_initialize() called as part of process bring-up. If this | 171 // sqlite3_initialize() called as part of process bring-up. If this |
| 155 // is changed, remove the dynamic_annotations dependency in sql.gyp. | 172 // is changed, remove the dynamic_annotations dependency in sql.gyp. |
| 156 base::LazyInstance<base::Lock>::Leaky | 173 base::LazyInstance<base::Lock>::Leaky |
| 157 g_sqlite_init_lock = LAZY_INSTANCE_INITIALIZER; | 174 g_sqlite_init_lock = LAZY_INSTANCE_INITIALIZER; |
| 158 void InitializeSqlite() { | 175 void InitializeSqlite() { |
| 159 base::AutoLock lock(g_sqlite_init_lock.Get()); | 176 base::AutoLock lock(g_sqlite_init_lock.Get()); |
| 160 static bool first_call = true; | 177 static bool first_call = true; |
| 161 if (first_call) { | 178 if (first_call) { |
| 179 gross(); |
| 162 sqlite3_initialize(); | 180 sqlite3_initialize(); |
| 163 | 181 |
| 164 // Schedule callback to record memory footprint histograms at 10m, 1h, and | 182 // Schedule callback to record memory footprint histograms at 10m, 1h, and |
| 165 // 1d. There may not be a registered thread task runner in tests. | 183 // 1d. There may not be a registered thread task runner in tests. |
| 166 if (base::ThreadTaskRunnerHandle::IsSet()) { | 184 if (base::ThreadTaskRunnerHandle::IsSet()) { |
| 167 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 185 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 168 FROM_HERE, base::Bind(&RecordSqliteMemory10Min), | 186 FROM_HERE, base::Bind(&RecordSqliteMemory10Min), |
| 169 base::TimeDelta::FromMinutes(10)); | 187 base::TimeDelta::FromMinutes(10)); |
| 170 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 188 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 171 FROM_HERE, base::Bind(&RecordSqliteMemoryHour), | 189 FROM_HERE, base::Bind(&RecordSqliteMemoryHour), |
| (...skipping 1511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1683 | 1701 |
| 1684 // If |poisoned_| is set, it means an error handler called | 1702 // If |poisoned_| is set, it means an error handler called |
| 1685 // RazeAndClose(). Until regular Close() is called, the caller | 1703 // RazeAndClose(). Until regular Close() is called, the caller |
| 1686 // should be treating the database as open, but is_open() currently | 1704 // should be treating the database as open, but is_open() currently |
| 1687 // only considers the sqlite3 handle's state. | 1705 // only considers the sqlite3 handle's state. |
| 1688 // TODO(shess): Revise is_open() to consider poisoned_, and review | 1706 // TODO(shess): Revise is_open() to consider poisoned_, and review |
| 1689 // to see if any non-testing code even depends on it. | 1707 // to see if any non-testing code even depends on it. |
| 1690 DLOG_IF(FATAL, poisoned_) << "sql::Connection is already open."; | 1708 DLOG_IF(FATAL, poisoned_) << "sql::Connection is already open."; |
| 1691 poisoned_ = false; | 1709 poisoned_ = false; |
| 1692 | 1710 |
| 1693 int err = sqlite3_open(file_name.c_str(), &db_); | 1711 // Custom memory-mapping VFS which reads pages using regular I/O on first hit. |
| 1712 sqlite3_vfs* vfs = VFSWrapper(); |
| 1713 const char* vfs_name = (vfs ? vfs->zName : NULL); |
| 1714 int err = sqlite3_open_v2(file_name.c_str(), &db_, |
| 1715 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, |
| 1716 vfs_name); |
| 1694 if (err != SQLITE_OK) { | 1717 if (err != SQLITE_OK) { |
| 1695 // Extended error codes cannot be enabled until a handle is | 1718 // Extended error codes cannot be enabled until a handle is |
| 1696 // available, fetch manually. | 1719 // available, fetch manually. |
| 1697 err = sqlite3_extended_errcode(db_); | 1720 err = sqlite3_extended_errcode(db_); |
| 1698 | 1721 |
| 1699 // Histogram failures specific to initial open for debugging | 1722 // Histogram failures specific to initial open for debugging |
| 1700 // purposes. | 1723 // purposes. |
| 1701 UMA_HISTOGRAM_SPARSE_SLOWLY("Sqlite.OpenFailure", err); | 1724 UMA_HISTOGRAM_SPARSE_SLOWLY("Sqlite.OpenFailure", err); |
| 1702 | 1725 |
| 1703 OnSqliteError(err, NULL, "-- sqlite3_open()"); | 1726 OnSqliteError(err, NULL, "-- sqlite3_open()"); |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2048 const std::string& dump_name) { | 2071 const std::string& dump_name) { |
| 2049 return memory_dump_provider_ && | 2072 return memory_dump_provider_ && |
| 2050 memory_dump_provider_->ReportMemoryUsage(pmd, dump_name); | 2073 memory_dump_provider_->ReportMemoryUsage(pmd, dump_name); |
| 2051 } | 2074 } |
| 2052 | 2075 |
| 2053 base::TimeTicks TimeSource::Now() { | 2076 base::TimeTicks TimeSource::Now() { |
| 2054 return base::TimeTicks::Now(); | 2077 return base::TimeTicks::Now(); |
| 2055 } | 2078 } |
| 2056 | 2079 |
| 2057 } // namespace sql | 2080 } // namespace sql |
| OLD | NEW |