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 <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 160 |
161 DirOpenResult Directory::OpenImpl( | 161 DirOpenResult Directory::OpenImpl( |
162 const string& name, | 162 const string& name, |
163 DirectoryChangeDelegate* delegate, | 163 DirectoryChangeDelegate* delegate, |
164 const WeakHandle<TransactionObserver>& | 164 const WeakHandle<TransactionObserver>& |
165 transaction_observer) { | 165 transaction_observer) { |
166 KernelLoadInfo info; | 166 KernelLoadInfo info; |
167 // Temporary indices before kernel_ initialized in case Load fails. We 0(1) | 167 // Temporary indices before kernel_ initialized in case Load fails. We 0(1) |
168 // swap these later. | 168 // swap these later. |
169 Directory::MetahandlesMap tmp_handles_map; | 169 Directory::MetahandlesMap tmp_handles_map; |
| 170 |
| 171 // Avoids mem leaks on failure. Harmlessly deletes the empty hash map after |
| 172 // the swap in the success case. |
| 173 STLValueDeleter<Directory::MetahandlesMap> deleter(&tmp_handles_map); |
| 174 |
170 JournalIndex delete_journals; | 175 JournalIndex delete_journals; |
171 | 176 |
172 DirOpenResult result = | 177 DirOpenResult result = |
173 store_->Load(&tmp_handles_map, &delete_journals, &info); | 178 store_->Load(&tmp_handles_map, &delete_journals, &info); |
174 if (OPENED != result) | 179 if (OPENED != result) |
175 return result; | 180 return result; |
176 | 181 |
177 kernel_ = new Kernel(name, info, delegate, transaction_observer); | 182 kernel_ = new Kernel(name, info, delegate, transaction_observer); |
178 delete_journal_.reset(new DeleteJournal(&delete_journals)); | 183 delete_journal_.reset(new DeleteJournal(&delete_journals)); |
179 InitializeIndices(&tmp_handles_map); | 184 InitializeIndices(&tmp_handles_map); |
(...skipping 1242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1422 | 1427 |
1423 for (OrderedChildSet::const_iterator i = children->begin(); | 1428 for (OrderedChildSet::const_iterator i = children->begin(); |
1424 i != children->end(); ++i) { | 1429 i != children->end(); ++i) { |
1425 DCHECK_EQ(parent_id, (*i)->ref(PARENT_ID)); | 1430 DCHECK_EQ(parent_id, (*i)->ref(PARENT_ID)); |
1426 result->push_back((*i)->ref(META_HANDLE)); | 1431 result->push_back((*i)->ref(META_HANDLE)); |
1427 } | 1432 } |
1428 } | 1433 } |
1429 | 1434 |
1430 } // namespace syncable | 1435 } // namespace syncable |
1431 } // namespace syncer | 1436 } // namespace syncer |
OLD | NEW |