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

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

Issue 1104423005: Revert of [Sync] Erase sync DB when corrupted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 | « sync/syncable/directory.h ('k') | sync/syncable/directory_backing_store_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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.h" 5 #include "sync/syncable/directory.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 104
105 Directory::Directory( 105 Directory::Directory(
106 DirectoryBackingStore* store, 106 DirectoryBackingStore* store,
107 UnrecoverableErrorHandler* unrecoverable_error_handler, 107 UnrecoverableErrorHandler* unrecoverable_error_handler,
108 ReportUnrecoverableErrorFunction report_unrecoverable_error_function, 108 ReportUnrecoverableErrorFunction report_unrecoverable_error_function,
109 NigoriHandler* nigori_handler, 109 NigoriHandler* nigori_handler,
110 Cryptographer* cryptographer) 110 Cryptographer* cryptographer)
111 : kernel_(NULL), 111 : kernel_(NULL),
112 store_(store), 112 store_(store),
113 unrecoverable_error_handler_(unrecoverable_error_handler), 113 unrecoverable_error_handler_(unrecoverable_error_handler),
114 report_unrecoverable_error_function_(report_unrecoverable_error_function), 114 report_unrecoverable_error_function_(
115 report_unrecoverable_error_function),
115 unrecoverable_error_set_(false), 116 unrecoverable_error_set_(false),
116 nigori_handler_(nigori_handler), 117 nigori_handler_(nigori_handler),
117 cryptographer_(cryptographer), 118 cryptographer_(cryptographer),
118 invariant_check_level_(VERIFY_CHANGES), 119 invariant_check_level_(VERIFY_CHANGES) {
119 weak_ptr_factory_(this) {
120 } 120 }
121 121
122 Directory::~Directory() { 122 Directory::~Directory() {
123 Close(); 123 Close();
124 } 124 }
125 125
126 DirOpenResult Directory::Open( 126 DirOpenResult Directory::Open(
127 const string& name, 127 const string& name,
128 DirectoryChangeDelegate* delegate, 128 DirectoryChangeDelegate* delegate,
129 const WeakHandle<TransactionObserver>& transaction_observer) { 129 const WeakHandle<TransactionObserver>& transaction_observer) {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 201
202 // Write back the share info to reserve some space in 'next_id'. This will 202 // Write back the share info to reserve some space in 'next_id'. This will
203 // prevent local ID reuse in the case of an early crash. See the comments in 203 // prevent local ID reuse in the case of an early crash. See the comments in
204 // TakeSnapshotForSaveChanges() or crbug.com/142987 for more information. 204 // TakeSnapshotForSaveChanges() or crbug.com/142987 for more information.
205 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; 205 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY;
206 206
207 kernel_->metahandles_to_purge.swap(metahandles_to_purge); 207 kernel_->metahandles_to_purge.swap(metahandles_to_purge);
208 if (!SaveChanges()) 208 if (!SaveChanges())
209 return FAILED_INITIAL_WRITE; 209 return FAILED_INITIAL_WRITE;
210 210
211 // Now that we've successfully opened the store, install an error handler to
212 // deal with catastrophic errors that may occur later on. Use a weak pointer
213 // because we cannot guarantee that this Directory will outlive the Closure.
214 store_->SetCatastrophicErrorHandler(base::Bind(
215 &Directory::OnCatastrophicError, weak_ptr_factory_.GetWeakPtr()));
216
217 return OPENED; 211 return OPENED;
218 } 212 }
219 213
220 DeleteJournal* Directory::delete_journal() { 214 DeleteJournal* Directory::delete_journal() {
221 DCHECK(delete_journal_.get()); 215 DCHECK(delete_journal_.get());
222 return delete_journal_.get(); 216 return delete_journal_.get();
223 } 217 }
224 218
225 void Directory::Close() { 219 void Directory::Close() {
226 store_.reset(); 220 store_.reset();
(...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after
1553 // server. To avoid re-uploading the same attachment mulitple times, we 1547 // server. To avoid re-uploading the same attachment mulitple times, we
1554 // remove any ids known to be on the server from the id_set we are about to 1548 // remove any ids known to be on the server from the id_set we are about to
1555 // return. 1549 // return.
1556 // 1550 //
1557 // TODO(maniscalco): Eliminate redundant metadata storage (bug 415203). 1551 // TODO(maniscalco): Eliminate redundant metadata storage (bug 415203).
1558 std::set_difference(not_on_server_id_set.begin(), not_on_server_id_set.end(), 1552 std::set_difference(not_on_server_id_set.begin(), not_on_server_id_set.end(),
1559 on_server_id_set.begin(), on_server_id_set.end(), 1553 on_server_id_set.begin(), on_server_id_set.end(),
1560 std::back_inserter(*ids)); 1554 std::back_inserter(*ids));
1561 } 1555 }
1562 1556
1563 void Directory::OnCatastrophicError() {
1564 ReadTransaction trans(FROM_HERE, this);
1565 OnUnrecoverableError(&trans, FROM_HERE,
1566 "Catastrophic error detected, Sync DB is unrecoverable");
1567 }
1568
1569 Directory::Kernel* Directory::kernel() { 1557 Directory::Kernel* Directory::kernel() {
1570 return kernel_; 1558 return kernel_;
1571 } 1559 }
1572 1560
1573 const Directory::Kernel* Directory::kernel() const { 1561 const Directory::Kernel* Directory::kernel() const {
1574 return kernel_; 1562 return kernel_;
1575 } 1563 }
1576 1564
1577 } // namespace syncable 1565 } // namespace syncable
1578 } // namespace syncer 1566 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/syncable/directory.h ('k') | sync/syncable/directory_backing_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698