OLD | NEW |
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 Loading... |
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_( | 114 report_unrecoverable_error_function_(report_unrecoverable_error_function), |
115 report_unrecoverable_error_function), | |
116 unrecoverable_error_set_(false), | 115 unrecoverable_error_set_(false), |
117 nigori_handler_(nigori_handler), | 116 nigori_handler_(nigori_handler), |
118 cryptographer_(cryptographer), | 117 cryptographer_(cryptographer), |
119 invariant_check_level_(VERIFY_CHANGES) { | 118 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 Loading... |
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 |
211 return OPENED; | 217 return OPENED; |
212 } | 218 } |
213 | 219 |
214 DeleteJournal* Directory::delete_journal() { | 220 DeleteJournal* Directory::delete_journal() { |
215 DCHECK(delete_journal_.get()); | 221 DCHECK(delete_journal_.get()); |
216 return delete_journal_.get(); | 222 return delete_journal_.get(); |
217 } | 223 } |
218 | 224 |
219 void Directory::Close() { | 225 void Directory::Close() { |
220 store_.reset(); | 226 store_.reset(); |
(...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1547 // server. To avoid re-uploading the same attachment mulitple times, we | 1553 // server. To avoid re-uploading the same attachment mulitple times, we |
1548 // remove any ids known to be on the server from the id_set we are about to | 1554 // remove any ids known to be on the server from the id_set we are about to |
1549 // return. | 1555 // return. |
1550 // | 1556 // |
1551 // TODO(maniscalco): Eliminate redundant metadata storage (bug 415203). | 1557 // TODO(maniscalco): Eliminate redundant metadata storage (bug 415203). |
1552 std::set_difference(not_on_server_id_set.begin(), not_on_server_id_set.end(), | 1558 std::set_difference(not_on_server_id_set.begin(), not_on_server_id_set.end(), |
1553 on_server_id_set.begin(), on_server_id_set.end(), | 1559 on_server_id_set.begin(), on_server_id_set.end(), |
1554 std::back_inserter(*ids)); | 1560 std::back_inserter(*ids)); |
1555 } | 1561 } |
1556 | 1562 |
| 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 |
1557 Directory::Kernel* Directory::kernel() { | 1569 Directory::Kernel* Directory::kernel() { |
1558 return kernel_; | 1570 return kernel_; |
1559 } | 1571 } |
1560 | 1572 |
1561 const Directory::Kernel* Directory::kernel() const { | 1573 const Directory::Kernel* Directory::kernel() const { |
1562 return kernel_; | 1574 return kernel_; |
1563 } | 1575 } |
1564 | 1576 |
1565 } // namespace syncable | 1577 } // namespace syncable |
1566 } // namespace syncer | 1578 } // namespace syncer |
OLD | NEW |