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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 : kernel_info_status(KERNEL_SHARE_INFO_INVALID) { | 140 : kernel_info_status(KERNEL_SHARE_INFO_INVALID) { |
141 } | 141 } |
142 | 142 |
143 Directory::SaveChangesSnapshot::~SaveChangesSnapshot() {} | 143 Directory::SaveChangesSnapshot::~SaveChangesSnapshot() {} |
144 | 144 |
145 Directory::Kernel::Kernel( | 145 Directory::Kernel::Kernel( |
146 const std::string& name, | 146 const std::string& name, |
147 const KernelLoadInfo& info, DirectoryChangeDelegate* delegate, | 147 const KernelLoadInfo& info, DirectoryChangeDelegate* delegate, |
148 const browser_sync::WeakHandle<TransactionObserver>& | 148 const browser_sync::WeakHandle<TransactionObserver>& |
149 transaction_observer) | 149 transaction_observer) |
150 : refcount(1), | 150 : next_write_transaction_id(0), |
151 next_write_transaction_id(0), | |
152 name(name), | 151 name(name), |
153 metahandles_index(new Directory::MetahandlesIndex), | 152 metahandles_index(new Directory::MetahandlesIndex), |
154 ids_index(new Directory::IdsIndex), | 153 ids_index(new Directory::IdsIndex), |
155 parent_id_child_index(new Directory::ParentIdChildIndex), | 154 parent_id_child_index(new Directory::ParentIdChildIndex), |
156 client_tag_index(new Directory::ClientTagIndex), | 155 client_tag_index(new Directory::ClientTagIndex), |
157 unsynced_metahandles(new MetahandleSet), | 156 unsynced_metahandles(new MetahandleSet), |
158 dirty_metahandles(new MetahandleSet), | 157 dirty_metahandles(new MetahandleSet), |
159 metahandles_to_purge(new MetahandleSet), | 158 metahandles_to_purge(new MetahandleSet), |
160 info_status(Directory::KERNEL_SHARE_INFO_VALID), | 159 info_status(Directory::KERNEL_SHARE_INFO_VALID), |
161 persisted_info(info.kernel_info), | 160 persisted_info(info.kernel_info), |
162 cache_guid(info.cache_guid), | 161 cache_guid(info.cache_guid), |
163 next_metahandle(info.max_metahandle + 1), | 162 next_metahandle(info.max_metahandle + 1), |
164 delegate(delegate), | 163 delegate(delegate), |
165 transaction_observer(transaction_observer) { | 164 transaction_observer(transaction_observer) { |
166 DCHECK(delegate); | 165 DCHECK(delegate); |
167 DCHECK(transaction_observer.IsInitialized()); | 166 DCHECK(transaction_observer.IsInitialized()); |
168 } | 167 } |
169 | 168 |
170 void Directory::Kernel::AddRef() { | |
171 base::subtle::NoBarrier_AtomicIncrement(&refcount, 1); | |
172 } | |
173 | |
174 void Directory::Kernel::Release() { | |
175 if (!base::subtle::NoBarrier_AtomicIncrement(&refcount, -1)) | |
176 delete this; | |
177 } | |
178 | |
179 Directory::Kernel::~Kernel() { | 169 Directory::Kernel::~Kernel() { |
180 CHECK_EQ(0, refcount); | |
181 delete unsynced_metahandles; | 170 delete unsynced_metahandles; |
182 delete dirty_metahandles; | 171 delete dirty_metahandles; |
183 delete metahandles_to_purge; | 172 delete metahandles_to_purge; |
184 delete parent_id_child_index; | 173 delete parent_id_child_index; |
185 delete client_tag_index; | 174 delete client_tag_index; |
186 delete ids_index; | 175 delete ids_index; |
187 STLDeleteElements(metahandles_index); | 176 STLDeleteElements(metahandles_index); |
188 delete metahandles_index; | 177 delete metahandles_index; |
189 } | 178 } |
190 | 179 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 kernel_->metahandles_index->swap(metas_bucket); | 270 kernel_->metahandles_index->swap(metas_bucket); |
282 InitializeIndices(); | 271 InitializeIndices(); |
283 return OPENED; | 272 return OPENED; |
284 } | 273 } |
285 | 274 |
286 void Directory::Close() { | 275 void Directory::Close() { |
287 if (store_) | 276 if (store_) |
288 delete store_; | 277 delete store_; |
289 store_ = NULL; | 278 store_ = NULL; |
290 if (kernel_) { | 279 if (kernel_) { |
291 bool del = !base::subtle::NoBarrier_AtomicIncrement(&kernel_->refcount, -1); | 280 delete kernel_; |
292 DCHECK(del) << "Kernel should only have a single ref"; | |
293 if (del) | |
294 delete kernel_; | |
295 kernel_ = NULL; | 281 kernel_ = NULL; |
296 } | 282 } |
297 } | 283 } |
298 | 284 |
299 void Directory::OnUnrecoverableError(const BaseTransaction* trans, | 285 void Directory::OnUnrecoverableError(const BaseTransaction* trans, |
300 const tracked_objects::Location& location, | 286 const tracked_objects::Location& location, |
301 const std::string & message) { | 287 const std::string & message) { |
302 DCHECK(trans != NULL); | 288 DCHECK(trans != NULL); |
303 unrecoverable_error_set_ = true; | 289 unrecoverable_error_set_ = true; |
304 unrecoverable_error_handler_->OnUnrecoverableError(location, | 290 unrecoverable_error_handler_->OnUnrecoverableError(location, |
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1349 } | 1335 } |
1350 // There were no children in the linked list. | 1336 // There were no children in the linked list. |
1351 return NULL; | 1337 return NULL; |
1352 } | 1338 } |
1353 | 1339 |
1354 ScopedKernelLock::ScopedKernelLock(const Directory* dir) | 1340 ScopedKernelLock::ScopedKernelLock(const Directory* dir) |
1355 : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) { | 1341 : scoped_lock_(dir->kernel_->mutex), dir_(const_cast<Directory*>(dir)) { |
1356 } | 1342 } |
1357 | 1343 |
1358 } | 1344 } |
OLD | NEW |