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 "sync/syncable/directory.h" | 5 #include "sync/syncable/directory.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/perftimer.h" | 8 #include "base/perftimer.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 // Temporary indices before kernel_ initialized in case Load fails. We 0(1) | 197 // Temporary indices before kernel_ initialized in case Load fails. We 0(1) |
198 // swap these later. | 198 // swap these later. |
199 MetahandlesIndex metas_bucket; | 199 MetahandlesIndex metas_bucket; |
200 DirOpenResult result = store_->Load(&metas_bucket, &info); | 200 DirOpenResult result = store_->Load(&metas_bucket, &info); |
201 if (OPENED != result) | 201 if (OPENED != result) |
202 return result; | 202 return result; |
203 | 203 |
204 kernel_ = new Kernel(name, info, delegate, transaction_observer); | 204 kernel_ = new Kernel(name, info, delegate, transaction_observer); |
205 kernel_->metahandles_index->swap(metas_bucket); | 205 kernel_->metahandles_index->swap(metas_bucket); |
206 InitializeIndices(); | 206 InitializeIndices(); |
| 207 |
| 208 // Write back the share info to reserve some space in 'next_id'. This will |
| 209 // prevent local ID reuse in the case of an early crash. See the comments in |
| 210 // TakeSnapshotForSaveChanges() or crbug.com/142987 for more information. |
| 211 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; |
| 212 if (!SaveChanges()) |
| 213 return FAILED_INITIAL_WRITE; |
| 214 |
207 return OPENED; | 215 return OPENED; |
208 } | 216 } |
209 | 217 |
210 void Directory::Close() { | 218 void Directory::Close() { |
211 store_.reset(); | 219 store_.reset(); |
212 if (kernel_) { | 220 if (kernel_) { |
213 delete kernel_; | 221 delete kernel_; |
214 kernel_ = NULL; | 222 kernel_ = NULL; |
215 } | 223 } |
216 } | 224 } |
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 // There were no children in the linked list. | 1215 // There were no children in the linked list. |
1208 return NULL; | 1216 return NULL; |
1209 } | 1217 } |
1210 | 1218 |
1211 ScopedKernelLock::ScopedKernelLock(const Directory* dir) | 1219 ScopedKernelLock::ScopedKernelLock(const Directory* dir) |
1212 : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) { | 1220 : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) { |
1213 } | 1221 } |
1214 | 1222 |
1215 } // namespace syncable | 1223 } // namespace syncable |
1216 } // namespace syncer | 1224 } // namespace syncer |
OLD | NEW |