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

Side by Side Diff: sync/syncable/directory_backing_store.cc

Issue 1072093002: [Sync] Update DirectoryBackingStore to detect Sync DB corruption (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Apply CR feedback. Created 5 years, 8 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "sync/syncable/directory_backing_store.h" 5 #include "sync/syncable/directory_backing_store.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <limits> 9 #include <limits>
10 10
11 #include "base/base64.h" 11 #include "base/base64.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/metrics/field_trial.h" 13 #include "base/metrics/field_trial.h"
14 #include "base/rand_util.h" 14 #include "base/rand_util.h"
15 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
16 #include "base/thread_task_runner_handle.h"
16 #include "base/time/time.h" 17 #include "base/time/time.h"
17 #include "base/trace_event/trace_event.h" 18 #include "base/trace_event/trace_event.h"
18 #include "sql/connection.h" 19 #include "sql/connection.h"
20 #include "sql/error_delegate_util.h"
19 #include "sql/statement.h" 21 #include "sql/statement.h"
20 #include "sql/transaction.h" 22 #include "sql/transaction.h"
21 #include "sync/internal_api/public/base/node_ordinal.h" 23 #include "sync/internal_api/public/base/node_ordinal.h"
22 #include "sync/protocol/bookmark_specifics.pb.h" 24 #include "sync/protocol/bookmark_specifics.pb.h"
23 #include "sync/protocol/sync.pb.h" 25 #include "sync/protocol/sync.pb.h"
24 #include "sync/syncable/syncable-inl.h" 26 #include "sync/syncable/syncable-inl.h"
25 #include "sync/syncable/syncable_columns.h" 27 #include "sync/syncable/syncable_columns.h"
26 #include "sync/syncable/syncable_util.h" 28 #include "sync/syncable/syncable_util.h"
27 #include "sync/util/time.h" 29 #include "sync/util/time.h"
28 30
29 using std::string; 31 using std::string;
30 32
31 namespace { 33 namespace {
32 34
33 bool IsSyncBackingDatabase32KEnabled() { 35 bool IsSyncBackingDatabase32KEnabled() {
34 const std::string group_name = 36 const std::string group_name =
35 base::FieldTrialList::FindFullName("SyncBackingDatabase32K"); 37 base::FieldTrialList::FindFullName("SyncBackingDatabase32K");
36 return group_name == "Enabled"; 38 return group_name == "Enabled";
37 } 39 }
38 40
41 void OnSqliteError(const base::Closure& catastrophic_error_handler,
42 int err,
43 sql::Statement* statement) {
44 // An error has been detected. Ignore unless it is catastrophic.
45 if (sql::IsErrorCatastrophic(err)) {
46 // At this point sql::* and DirectoryBackingStore may be on the callstack so
47 // don't invoke the error handler directly. Instead, PostTask to this thread
48 // to avoid potential reentrancy issues.
49 base::MessageLoop::current()->PostTask(FROM_HERE,
50 catastrophic_error_handler);
51 }
52 }
53
39 } // namespace 54 } // namespace
40 55
41 namespace syncer { 56 namespace syncer {
42 namespace syncable { 57 namespace syncable {
43 58
44 // This just has to be big enough to hold an UPDATE or INSERT statement that 59 // This just has to be big enough to hold an UPDATE or INSERT statement that
45 // modifies all the columns in the entry table. 60 // modifies all the columns in the entry table.
46 static const string::size_type kUpdateStatementBufferSize = 2048; 61 static const string::size_type kUpdateStatementBufferSize = 2048;
47 62
48 // Increment this version whenever updating DB tables. 63 // Increment this version whenever updating DB tables.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 193
179 } // namespace 194 } // namespace
180 195
181 /////////////////////////////////////////////////////////////////////////////// 196 ///////////////////////////////////////////////////////////////////////////////
182 // DirectoryBackingStore implementation. 197 // DirectoryBackingStore implementation.
183 198
184 DirectoryBackingStore::DirectoryBackingStore(const string& dir_name) 199 DirectoryBackingStore::DirectoryBackingStore(const string& dir_name)
185 : dir_name_(dir_name), 200 : dir_name_(dir_name),
186 database_page_size_(IsSyncBackingDatabase32KEnabled() ? 32768 : 4096), 201 database_page_size_(IsSyncBackingDatabase32KEnabled() ? 32768 : 4096),
187 needs_column_refresh_(false) { 202 needs_column_refresh_(false) {
203 DCHECK(base::ThreadTaskRunnerHandle::IsSet());
188 ResetAndCreateConnection(); 204 ResetAndCreateConnection();
189 } 205 }
190 206
191 DirectoryBackingStore::DirectoryBackingStore(const string& dir_name, 207 DirectoryBackingStore::DirectoryBackingStore(const string& dir_name,
192 sql::Connection* db) 208 sql::Connection* db)
193 : db_(db), 209 : db_(db),
194 dir_name_(dir_name), 210 dir_name_(dir_name),
195 database_page_size_(IsSyncBackingDatabase32KEnabled() ? 32768 : 4096), 211 database_page_size_(IsSyncBackingDatabase32KEnabled() ? 32768 : 4096),
196 needs_column_refresh_(false) { 212 needs_column_refresh_(false) {
213 DCHECK(base::ThreadTaskRunnerHandle::IsSet());
197 } 214 }
198 215
199 DirectoryBackingStore::~DirectoryBackingStore() { 216 DirectoryBackingStore::~DirectoryBackingStore() {
200 } 217 }
201 218
202 bool DirectoryBackingStore::DeleteEntries(EntryTable from, 219 bool DirectoryBackingStore::DeleteEntries(EntryTable from,
203 const MetahandleSet& handles) { 220 const MetahandleSet& handles) {
204 if (handles.empty()) 221 if (handles.empty())
205 return true; 222 return true;
206 223
(...skipping 1427 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 bool DirectoryBackingStore::needs_column_refresh() const { 1651 bool DirectoryBackingStore::needs_column_refresh() const {
1635 return needs_column_refresh_; 1652 return needs_column_refresh_;
1636 } 1653 }
1637 1654
1638 void DirectoryBackingStore::ResetAndCreateConnection() { 1655 void DirectoryBackingStore::ResetAndCreateConnection() {
1639 db_.reset(new sql::Connection()); 1656 db_.reset(new sql::Connection());
1640 db_->set_histogram_tag("SyncDirectory"); 1657 db_->set_histogram_tag("SyncDirectory");
1641 db_->set_exclusive_locking(); 1658 db_->set_exclusive_locking();
1642 db_->set_cache_size(32); 1659 db_->set_cache_size(32);
1643 db_->set_page_size(database_page_size_); 1660 db_->set_page_size(database_page_size_);
1661 if (!catastrophic_error_handler_.is_null())
1662 SetCatastrophicErrorHandler(catastrophic_error_handler_);
1663 }
1664
1665 void DirectoryBackingStore::SetCatastrophicErrorHandler(
1666 const base::Closure& catastrophic_error_handler) {
1667 DCHECK(CalledOnValidThread());
1668 DCHECK(!catastrophic_error_handler.is_null());
1669 catastrophic_error_handler_ = catastrophic_error_handler;
1670 sql::Connection::ErrorCallback error_callback =
1671 base::Bind(&OnSqliteError, catastrophic_error_handler_);
1672 db_->set_error_callback(error_callback);
1644 } 1673 }
1645 1674
1646 } // namespace syncable 1675 } // namespace syncable
1647 } // namespace syncer 1676 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/syncable/directory_backing_store.h ('k') | sync/syncable/directory_backing_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698