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

Side by Side Diff: chrome/browser/sync/syncable/syncable.cc

Issue 7904021: [Sync] Rework SharedValue<T> into Immutable<T> (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/sync/syncable/syncable.h" 5 #include "chrome/browser/sync/syncable/syncable.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <sys/stat.h> 9 #include <sys/stat.h>
10 #if defined(OS_POSIX) 10 #if defined(OS_POSIX)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 ENUM_CASE(VACUUM_AFTER_SAVE); 83 ENUM_CASE(VACUUM_AFTER_SAVE);
84 ENUM_CASE(PURGE_ENTRIES); 84 ENUM_CASE(PURGE_ENTRIES);
85 ENUM_CASE(SYNCAPI); 85 ENUM_CASE(SYNCAPI);
86 }; 86 };
87 NOTREACHED(); 87 NOTREACHED();
88 return ""; 88 return "";
89 } 89 }
90 90
91 #undef ENUM_CASE 91 #undef ENUM_CASE
92 92
93 SharedEntryKernelMutationMap::SharedEntryKernelMutationMap()
94 : mutations_(new SharedMutationMap()) {}
95
96 SharedEntryKernelMutationMap::SharedEntryKernelMutationMap(
97 EntryKernelMutationMap* mutations)
98 : mutations_(new SharedMutationMap(mutations)) {}
99
100 SharedEntryKernelMutationMap::~SharedEntryKernelMutationMap() {}
101
102 const EntryKernelMutationMap& SharedEntryKernelMutationMap::Get() const {
103 return mutations_->Get();
104 }
105
106 void SharedEntryKernelMutationMap::MutationMapTraits::Swap(
107 EntryKernelMutationMap* mutations1, EntryKernelMutationMap* mutations2) {
108 mutations1->swap(*mutations2);
109 }
110
111 namespace { 93 namespace {
112 94
113 DictionaryValue* EntryKernelMutationToValue( 95 DictionaryValue* EntryKernelMutationToValue(
114 const EntryKernelMutation& mutation) { 96 const EntryKernelMutation& mutation) {
115 DictionaryValue* dict = new DictionaryValue(); 97 DictionaryValue* dict = new DictionaryValue();
116 dict->Set("original", mutation.original.ToValue()); 98 dict->Set("original", mutation.original.ToValue());
117 dict->Set("mutated", mutation.mutated.ToValue()); 99 dict->Set("mutated", mutation.mutated.ToValue());
118 return dict; 100 return dict;
119 } 101 }
120 102
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 // Insert only if it's not already there. 1203 // Insert only if it's not already there.
1222 const int64 handle = entry->ref(META_HANDLE); 1204 const int64 handle = entry->ref(META_HANDLE);
1223 EntryKernelMutationMap::iterator it = mutations_.lower_bound(handle); 1205 EntryKernelMutationMap::iterator it = mutations_.lower_bound(handle);
1224 if (it == mutations_.end() || it->first != handle) { 1206 if (it == mutations_.end() || it->first != handle) {
1225 EntryKernelMutation mutation; 1207 EntryKernelMutation mutation;
1226 mutation.original = *entry; 1208 mutation.original = *entry;
1227 ignore_result(mutations_.insert(it, std::make_pair(handle, mutation))); 1209 ignore_result(mutations_.insert(it, std::make_pair(handle, mutation)));
1228 } 1210 }
1229 } 1211 }
1230 1212
1231 SharedEntryKernelMutationMap WriteTransaction::RecordMutations() { 1213 ImmutableEntryKernelMutationMap WriteTransaction::RecordMutations() {
1232 dirkernel_->transaction_mutex.AssertAcquired(); 1214 dirkernel_->transaction_mutex.AssertAcquired();
1233 for (syncable::EntryKernelMutationMap::iterator it = mutations_.begin(); 1215 for (syncable::EntryKernelMutationMap::iterator it = mutations_.begin();
1234 it != mutations_.end(); ++it) { 1216 it != mutations_.end(); ++it) {
1235 EntryKernel* kernel = directory()->GetEntryByHandle(it->first); 1217 EntryKernel* kernel = directory()->GetEntryByHandle(it->first);
1236 if (!kernel) { 1218 if (!kernel) {
1237 NOTREACHED(); 1219 NOTREACHED();
1238 continue; 1220 continue;
1239 } 1221 }
1240 it->second.mutated = *kernel; 1222 it->second.mutated = *kernel;
1241 } 1223 }
1242 return SharedEntryKernelMutationMap(&mutations_); 1224 return ImmutableEntryKernelMutationMap(&mutations_);
1243 } 1225 }
1244 1226
1245 void WriteTransaction::UnlockAndNotify( 1227 void WriteTransaction::UnlockAndNotify(
1246 const SharedEntryKernelMutationMap& mutations) { 1228 const ImmutableEntryKernelMutationMap& mutations) {
1247 // Work while transaction mutex is held. 1229 // Work while transaction mutex is held.
1248 ModelTypeBitSet models_with_changes; 1230 ModelTypeBitSet models_with_changes;
1249 bool has_mutations = !mutations.Get().empty(); 1231 bool has_mutations = !mutations.Get().empty();
1250 if (has_mutations) { 1232 if (has_mutations) {
1251 models_with_changes = NotifyTransactionChangingAndEnding(mutations); 1233 models_with_changes = NotifyTransactionChangingAndEnding(mutations);
1252 } 1234 }
1253 Unlock(); 1235 Unlock();
1254 1236
1255 // Work after mutex is relased. 1237 // Work after mutex is relased.
1256 if (has_mutations) { 1238 if (has_mutations) {
1257 NotifyTransactionComplete(models_with_changes); 1239 NotifyTransactionComplete(models_with_changes);
1258 } 1240 }
1259 } 1241 }
1260 1242
1261 ModelTypeBitSet WriteTransaction::NotifyTransactionChangingAndEnding( 1243 ModelTypeBitSet WriteTransaction::NotifyTransactionChangingAndEnding(
1262 const SharedEntryKernelMutationMap& mutations) { 1244 const ImmutableEntryKernelMutationMap& mutations) {
1263 dirkernel_->transaction_mutex.AssertAcquired(); 1245 dirkernel_->transaction_mutex.AssertAcquired();
1264 DCHECK(!mutations.Get().empty()); 1246 DCHECK(!mutations.Get().empty());
1265 1247
1266 DirectoryChangeDelegate* const delegate = dirkernel_->delegate; 1248 DirectoryChangeDelegate* const delegate = dirkernel_->delegate;
1267 if (writer_ == syncable::SYNCAPI) { 1249 if (writer_ == syncable::SYNCAPI) {
1268 delegate->HandleCalculateChangesChangeEventFromSyncApi( 1250 delegate->HandleCalculateChangesChangeEventFromSyncApi(
1269 mutations.Get(), this); 1251 mutations.Get(), this);
1270 } else { 1252 } else {
1271 delegate->HandleCalculateChangesChangeEventFromSyncer( 1253 delegate->HandleCalculateChangesChangeEventFromSyncer(
1272 mutations.Get(), this); 1254 mutations.Get(), this);
1273 } 1255 }
1274 1256
1275 ModelTypeBitSet models_with_changes = 1257 ModelTypeBitSet models_with_changes =
1276 delegate->HandleTransactionEndingChangeEvent(this); 1258 delegate->HandleTransactionEndingChangeEvent(this);
1277 1259
1278 dirkernel_->observers->Notify( 1260 dirkernel_->observers->Notify(
1279 &TransactionObserver::OnTransactionMutate, 1261 &TransactionObserver::OnTransactionMutate,
1280 from_here_, writer_, mutations, models_with_changes); 1262 from_here_, writer_, mutations, models_with_changes);
1281 1263
1282 return models_with_changes; 1264 return models_with_changes;
1283 } 1265 }
1284 1266
1285 void WriteTransaction::NotifyTransactionComplete( 1267 void WriteTransaction::NotifyTransactionComplete(
1286 ModelTypeBitSet models_with_changes) { 1268 ModelTypeBitSet models_with_changes) {
1287 dirkernel_->delegate->HandleTransactionCompleteChangeEvent( 1269 dirkernel_->delegate->HandleTransactionCompleteChangeEvent(
1288 models_with_changes); 1270 models_with_changes);
1289 } 1271 }
1290 1272
1291 WriteTransaction::~WriteTransaction() { 1273 WriteTransaction::~WriteTransaction() {
1292 const SharedEntryKernelMutationMap& mutations = RecordMutations(); 1274 const ImmutableEntryKernelMutationMap& mutations = RecordMutations();
1293 1275
1294 if (OFF != kInvariantCheckLevel) { 1276 if (OFF != kInvariantCheckLevel) {
1295 const bool full_scan = (FULL_DB_VERIFICATION == kInvariantCheckLevel); 1277 const bool full_scan = (FULL_DB_VERIFICATION == kInvariantCheckLevel);
1296 if (full_scan) 1278 if (full_scan)
1297 directory()->CheckTreeInvariants(this, full_scan); 1279 directory()->CheckTreeInvariants(this, full_scan);
1298 else 1280 else
1299 directory()->CheckTreeInvariants(this, mutations.Get()); 1281 directory()->CheckTreeInvariants(this, mutations.Get());
1300 } 1282 }
1301 1283
1302 UnlockAndNotify(mutations); 1284 UnlockAndNotify(mutations);
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
1959 CHECK(result); 1941 CHECK(result);
1960 for (iterator i = GetParentChildIndexLowerBound(lock, parent_id), 1942 for (iterator i = GetParentChildIndexLowerBound(lock, parent_id),
1961 end = GetParentChildIndexUpperBound(lock, parent_id); 1943 end = GetParentChildIndexUpperBound(lock, parent_id);
1962 i != end; ++i) { 1944 i != end; ++i) {
1963 DCHECK_EQ(parent_id, (*i)->ref(PARENT_ID)); 1945 DCHECK_EQ(parent_id, (*i)->ref(PARENT_ID));
1964 result->push_back((*i)->ref(META_HANDLE)); 1946 result->push_back((*i)->ref(META_HANDLE));
1965 } 1947 }
1966 } 1948 }
1967 1949
1968 } // namespace syncable 1950 } // namespace syncable
OLDNEW
« no previous file with comments | « chrome/browser/sync/syncable/syncable.h ('k') | chrome/browser/sync/syncable/transaction_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698