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

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

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 #ifndef CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ 5 #ifndef CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_
6 #define CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ 6 #define CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_
7 #pragma once 7 #pragma once
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <bitset> 10 #include <bitset>
(...skipping 14 matching lines...) Expand all
25 #include "base/synchronization/lock.h" 25 #include "base/synchronization/lock.h"
26 #include "base/time.h" 26 #include "base/time.h"
27 #include "base/tracked.h" 27 #include "base/tracked.h"
28 #include "chrome/browser/sync/protocol/sync.pb.h" 28 #include "chrome/browser/sync/protocol/sync.pb.h"
29 #include "chrome/browser/sync/syncable/blob.h" 29 #include "chrome/browser/sync/syncable/blob.h"
30 #include "chrome/browser/sync/syncable/dir_open_result.h" 30 #include "chrome/browser/sync/syncable/dir_open_result.h"
31 #include "chrome/browser/sync/syncable/directory_event.h" 31 #include "chrome/browser/sync/syncable/directory_event.h"
32 #include "chrome/browser/sync/syncable/syncable_id.h" 32 #include "chrome/browser/sync/syncable/syncable_id.h"
33 #include "chrome/browser/sync/syncable/model_type.h" 33 #include "chrome/browser/sync/syncable/model_type.h"
34 #include "chrome/browser/sync/util/dbgq.h" 34 #include "chrome/browser/sync/util/dbgq.h"
35 #include "chrome/browser/sync/util/shared_value.h" 35 #include "chrome/browser/sync/util/immutable.h"
36 36
37 struct PurgeInfo; 37 struct PurgeInfo;
38 38
39 namespace base { 39 namespace base {
40 class DictionaryValue; 40 class DictionaryValue;
41 class ListValue; 41 class ListValue;
42 } 42 }
43 43
44 namespace sync_api { 44 namespace sync_api {
45 class ReadTransaction; 45 class ReadTransaction;
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 return a.ref(META_HANDLE) < b.ref(META_HANDLE); 556 return a.ref(META_HANDLE) < b.ref(META_HANDLE);
557 } 557 }
558 }; 558 };
559 typedef std::set<EntryKernel, EntryKernelLessByMetaHandle> EntryKernelSet; 559 typedef std::set<EntryKernel, EntryKernelLessByMetaHandle> EntryKernelSet;
560 560
561 struct EntryKernelMutation { 561 struct EntryKernelMutation {
562 EntryKernel original, mutated; 562 EntryKernel original, mutated;
563 }; 563 };
564 typedef std::map<int64, EntryKernelMutation> EntryKernelMutationMap; 564 typedef std::map<int64, EntryKernelMutation> EntryKernelMutationMap;
565 565
566 // A thread-safe wrapper around an immutable mutation map. Used for 566 typedef browser_sync::Immutable<EntryKernelMutationMap>
567 // passing around mutation maps without incurring lots of copies. 567 ImmutableEntryKernelMutationMap;
568 class SharedEntryKernelMutationMap {
569 public:
570 SharedEntryKernelMutationMap();
571 // Takes over the data in |mutations|, leaving |mutations| empty.
572 explicit SharedEntryKernelMutationMap(EntryKernelMutationMap* mutations);
573
574 ~SharedEntryKernelMutationMap();
575
576 const EntryKernelMutationMap& Get() const;
577
578 private:
579 struct MutationMapTraits {
580 static void Swap(EntryKernelMutationMap* mutations1,
581 EntryKernelMutationMap* mutations2);
582 };
583
584 typedef browser_sync::SharedValue<EntryKernelMutationMap, MutationMapTraits>
585 SharedMutationMap;
586
587 scoped_refptr<const SharedMutationMap> mutations_;
588 };
589 568
590 // Caller owns the return value. 569 // Caller owns the return value.
591 base::ListValue* EntryKernelMutationMapToValue( 570 base::ListValue* EntryKernelMutationMapToValue(
592 const EntryKernelMutationMap& mutations); 571 const EntryKernelMutationMap& mutations);
593 572
594 // How syncable indices & Indexers work. 573 // How syncable indices & Indexers work.
595 // 574 //
596 // The syncable Directory maintains several indices on the Entries it tracks. 575 // The syncable Directory maintains several indices on the Entries it tracks.
597 // The indices follow a common pattern: 576 // The indices follow a common pattern:
598 // (a) The index allows efficient lookup of an Entry* with particular 577 // (a) The index allows efficient lookup of an Entry* with particular
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 1160
1182 void SaveOriginal(const EntryKernel* entry); 1161 void SaveOriginal(const EntryKernel* entry);
1183 1162
1184 protected: 1163 protected:
1185 // Overridden by tests. 1164 // Overridden by tests.
1186 virtual void NotifyTransactionComplete( 1165 virtual void NotifyTransactionComplete(
1187 ModelTypeBitSet models_with_changes); 1166 ModelTypeBitSet models_with_changes);
1188 1167
1189 private: 1168 private:
1190 // Clears |mutations_|. 1169 // Clears |mutations_|.
1191 SharedEntryKernelMutationMap RecordMutations(); 1170 ImmutableEntryKernelMutationMap RecordMutations();
1192 1171
1193 void UnlockAndNotify(const SharedEntryKernelMutationMap& mutations); 1172 void UnlockAndNotify(const ImmutableEntryKernelMutationMap& mutations);
1194 1173
1195 ModelTypeBitSet NotifyTransactionChangingAndEnding( 1174 ModelTypeBitSet NotifyTransactionChangingAndEnding(
1196 const SharedEntryKernelMutationMap& mutations); 1175 const ImmutableEntryKernelMutationMap& mutations);
1197 1176
1198 // Only the original fields are filled in until |RecordMutations()|. 1177 // Only the original fields are filled in until |RecordMutations()|.
1199 // We use a mutation map instead of a kernel set to avoid copying. 1178 // We use a mutation map instead of a kernel set to avoid copying.
1200 EntryKernelMutationMap mutations_; 1179 EntryKernelMutationMap mutations_;
1201 1180
1202 DISALLOW_COPY_AND_ASSIGN(WriteTransaction); 1181 DISALLOW_COPY_AND_ASSIGN(WriteTransaction);
1203 }; 1182 };
1204 1183
1205 bool IsLegalNewParent(BaseTransaction* trans, const Id& id, const Id& parentid); 1184 bool IsLegalNewParent(BaseTransaction* trans, const Id& id, const Id& parentid);
1206 1185
1207 int64 Now(); 1186 int64 Now();
1208 1187
1209 // This function sets only the flags needed to get this entry to sync. 1188 // This function sets only the flags needed to get this entry to sync.
1210 void MarkForSyncing(syncable::MutableEntry* e); 1189 void MarkForSyncing(syncable::MutableEntry* e);
1211 1190
1212 // This is not a reset. It just sets the numeric fields which are not 1191 // This is not a reset. It just sets the numeric fields which are not
1213 // initialized by the constructor to zero. 1192 // initialized by the constructor to zero.
1214 void ZeroFields(EntryKernel* entry, int first_field); 1193 void ZeroFields(EntryKernel* entry, int first_field);
1215 1194
1216 } // namespace syncable 1195 } // namespace syncable
1217 1196
1218 std::ostream& operator <<(std::ostream&, const syncable::Blob&); 1197 std::ostream& operator <<(std::ostream&, const syncable::Blob&);
1219 1198
1220 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ 1199 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/js/js_transaction_observer.cc ('k') | chrome/browser/sync/syncable/syncable.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698