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

Side by Side Diff: sql/connection.cc

Issue 1176653002: mandoline filesystem: add a sqlite3 vfs to proxy filesystem usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Another round. Created 5 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
OLDNEW
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 <string.h> 7 #include <string.h>
8 8
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // This should match UMA_HISTOGRAM_MEDIUM_TIMES(). 144 // This should match UMA_HISTOGRAM_MEDIUM_TIMES().
145 base::HistogramBase* GetMediumTimeHistogram(const std::string& name) { 145 base::HistogramBase* GetMediumTimeHistogram(const std::string& name) {
146 return base::Histogram::FactoryTimeGet( 146 return base::Histogram::FactoryTimeGet(
147 name, 147 name,
148 base::TimeDelta::FromMilliseconds(10), 148 base::TimeDelta::FromMilliseconds(10),
149 base::TimeDelta::FromMinutes(3), 149 base::TimeDelta::FromMinutes(3),
150 50, 150 50,
151 base::HistogramBase::kUmaTargetedHistogramFlag); 151 base::HistogramBase::kUmaTargetedHistogramFlag);
152 } 152 }
153 153
154 std::string AsUTF8ForSQL(const base::FilePath& path) {
155 #if defined(OS_WIN)
156 return base::WideToUTF8(path.value());
157 #elif defined(OS_POSIX)
158 return path.value();
159 #endif
160 }
161
154 } // namespace 162 } // namespace
155 163
156 namespace sql { 164 namespace sql {
157 165
158 // static 166 // static
159 Connection::ErrorIgnorerCallback* Connection::current_ignorer_cb_ = NULL; 167 Connection::ErrorIgnorerCallback* Connection::current_ignorer_cb_ = NULL;
160 168
161 // static 169 // static
162 bool Connection::ShouldIgnoreSqliteError(int error) { 170 bool Connection::ShouldIgnoreSqliteError(int error) {
163 if (!current_ignorer_cb_) 171 if (!current_ignorer_cb_)
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 std::string full_histogram_name = "Sqlite.SizeKB." + histogram_tag_; 313 std::string full_histogram_name = "Sqlite.SizeKB." + histogram_tag_;
306 base::HistogramBase* histogram = 314 base::HistogramBase* histogram =
307 base::Histogram::FactoryGet( 315 base::Histogram::FactoryGet(
308 full_histogram_name, 1, 1000000, 50, 316 full_histogram_name, 1, 1000000, 50,
309 base::HistogramBase::kUmaTargetedHistogramFlag); 317 base::HistogramBase::kUmaTargetedHistogramFlag);
310 if (histogram) 318 if (histogram)
311 histogram->Add(sample); 319 histogram->Add(sample);
312 } 320 }
313 } 321 }
314 322
315 #if defined(OS_WIN) 323 return OpenInternal(AsUTF8ForSQL(path), RETRY_ON_POISON);
Scott Hess - ex-Googler 2015/06/19 20:48:02 +1! The placement of this #if has annoyed me for
316 return OpenInternal(base::WideToUTF8(path.value()), RETRY_ON_POISON);
317 #elif defined(OS_POSIX)
318 return OpenInternal(path.value(), RETRY_ON_POISON);
319 #endif
320 } 324 }
321 325
322 bool Connection::OpenInMemory() { 326 bool Connection::OpenInMemory() {
323 in_memory_ = true; 327 in_memory_ = true;
324 return OpenInternal(":memory:", NO_RETRY); 328 return OpenInternal(":memory:", NO_RETRY);
325 } 329 }
326 330
327 bool Connection::OpenTemporary() { 331 bool Connection::OpenTemporary() {
328 return OpenInternal("", NO_RETRY); 332 return OpenInternal("", NO_RETRY);
329 } 333 }
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 // junk to prevent other processes from opening it successfully (like 621 // junk to prevent other processes from opening it successfully (like
618 // Gears "SQLite poison 3" trick). 622 // Gears "SQLite poison 3" trick).
619 // 623 //
620 // static 624 // static
621 bool Connection::Delete(const base::FilePath& path) { 625 bool Connection::Delete(const base::FilePath& path) {
622 base::ThreadRestrictions::AssertIOAllowed(); 626 base::ThreadRestrictions::AssertIOAllowed();
623 627
624 base::FilePath journal_path(path.value() + FILE_PATH_LITERAL("-journal")); 628 base::FilePath journal_path(path.value() + FILE_PATH_LITERAL("-journal"));
625 base::FilePath wal_path(path.value() + FILE_PATH_LITERAL("-wal")); 629 base::FilePath wal_path(path.value() + FILE_PATH_LITERAL("-wal"));
626 630
627 base::DeleteFile(journal_path, false); 631 std::string journal_str = AsUTF8ForSQL(journal_path);
628 base::DeleteFile(wal_path, false); 632 std::string wal_str = AsUTF8ForSQL(wal_path);
629 base::DeleteFile(path, false); 633 std::string path_str = AsUTF8ForSQL(path);
630 634
631 return !base::PathExists(journal_path) && 635 sqlite3_vfs* vfs = sqlite3_vfs_find(NULL);
632 !base::PathExists(wal_path) && 636 CHECK(vfs);
633 !base::PathExists(path); 637 CHECK(vfs->xDelete);
638 CHECK(vfs->xAccess);
639
640 // We only work with unix, win32 and mojo filesystems. If you're trying to
641 // use this code with any other VFS, you're not in a good place.
642 CHECK(strncmp(vfs->zName, "unix", 4) == 0 ||
643 strncmp(vfs->zName, "win32", 5) == 0 ||
644 strcmp(vfs->zName, "mojo") == 0);
645
646 vfs->xDelete(vfs, journal_str.c_str(), 0);
647 vfs->xDelete(vfs, wal_str.c_str(), 0);
648 vfs->xDelete(vfs, path_str.c_str(), 0);
649
650 int journal_exists = 0;
651 vfs->xAccess(vfs, journal_str.c_str(), SQLITE_ACCESS_EXISTS,
652 &journal_exists);
653
654 int wal_exists = 0;
655 vfs->xAccess(vfs, wal_str.c_str(), SQLITE_ACCESS_EXISTS,
656 &wal_exists);
657
658 int path_exists = 0;
659 vfs->xAccess(vfs, path_str.c_str(), SQLITE_ACCESS_EXISTS,
660 &path_exists);
661
662 return !journal_exists && !wal_exists && !path_exists;
634 } 663 }
635 664
636 bool Connection::BeginTransaction() { 665 bool Connection::BeginTransaction() {
637 if (needs_rollback_) { 666 if (needs_rollback_) {
638 DCHECK_GT(transaction_nesting_, 0); 667 DCHECK_GT(transaction_nesting_, 0);
639 668
640 // When we're going to rollback, fail on this begin and don't actually 669 // When we're going to rollback, fail on this begin and don't actually
641 // mark us as entering the nested transaction. 670 // mark us as entering the nested transaction.
642 return false; 671 return false;
643 } 672 }
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 ignore_result(Execute(kNoWritableSchema)); 1336 ignore_result(Execute(kNoWritableSchema));
1308 1337
1309 return ret; 1338 return ret;
1310 } 1339 }
1311 1340
1312 base::TimeTicks TimeSource::Now() { 1341 base::TimeTicks TimeSource::Now() {
1313 return base::TimeTicks::Now(); 1342 return base::TimeTicks::Now();
1314 } 1343 }
1315 1344
1316 } // namespace sql 1345 } // namespace sql
OLDNEW
« no previous file with comments | « sql/BUILD.gn ('k') | sql/connection_unittest.cc » ('j') | sql/mojo/enable_mojo_fs.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698