OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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> |
11 #include <iosfwd> | 11 #include <iosfwd> |
12 #include <limits> | 12 #include <limits> |
13 #include <set> | 13 #include <set> |
14 #include <string> | 14 #include <string> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/atomicops.h" | 17 #include "base/atomicops.h" |
18 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
19 #include "base/file_path.h" | 19 #include "base/file_path.h" |
20 #include "base/gtest_prod_util.h" | 20 #include "base/gtest_prod_util.h" |
21 #include "base/lock.h" | 21 #include "base/synchronization/lock.h" |
22 #include "base/time.h" | 22 #include "base/time.h" |
23 #include "chrome/browser/sync/protocol/sync.pb.h" | 23 #include "chrome/browser/sync/protocol/sync.pb.h" |
24 #include "chrome/browser/sync/syncable/autofill_migration.h" | 24 #include "chrome/browser/sync/syncable/autofill_migration.h" |
25 #include "chrome/browser/sync/syncable/blob.h" | 25 #include "chrome/browser/sync/syncable/blob.h" |
26 #include "chrome/browser/sync/syncable/dir_open_result.h" | 26 #include "chrome/browser/sync/syncable/dir_open_result.h" |
27 #include "chrome/browser/sync/syncable/directory_event.h" | 27 #include "chrome/browser/sync/syncable/directory_event.h" |
28 #include "chrome/browser/sync/syncable/path_name_cmp.h" | 28 #include "chrome/browser/sync/syncable/path_name_cmp.h" |
29 #include "chrome/browser/sync/syncable/syncable_id.h" | 29 #include "chrome/browser/sync/syncable/syncable_id.h" |
30 #include "chrome/browser/sync/syncable/model_type.h" | 30 #include "chrome/browser/sync/syncable/model_type.h" |
31 #include "chrome/browser/sync/util/channel.h" | 31 #include "chrome/browser/sync/util/channel.h" |
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
820 | 820 |
821 template <class T> void TestAndSet(T* kernel_data, const T* data_to_set); | 821 template <class T> void TestAndSet(T* kernel_data, const T* data_to_set); |
822 | 822 |
823 struct DirectoryEventTraits { | 823 struct DirectoryEventTraits { |
824 typedef DirectoryEvent EventType; | 824 typedef DirectoryEvent EventType; |
825 static inline bool IsChannelShutdownEvent(const DirectoryEvent& event) { | 825 static inline bool IsChannelShutdownEvent(const DirectoryEvent& event) { |
826 return DIRECTORY_DESTROYED == event; | 826 return DIRECTORY_DESTROYED == event; |
827 } | 827 } |
828 }; | 828 }; |
829 public: | 829 public: |
830 typedef EventChannel<DirectoryEventTraits, Lock> Channel; | 830 typedef EventChannel<DirectoryEventTraits, base::Lock> Channel; |
831 typedef std::vector<int64> ChildHandles; | 831 typedef std::vector<int64> ChildHandles; |
832 | 832 |
833 // Returns the child meta handles for given parent id. | 833 // Returns the child meta handles for given parent id. |
834 void GetChildHandles(BaseTransaction*, const Id& parent_id, | 834 void GetChildHandles(BaseTransaction*, const Id& parent_id, |
835 const std::string& path_spec, ChildHandles* result); | 835 const std::string& path_spec, ChildHandles* result); |
836 void GetChildHandles(BaseTransaction*, const Id& parent_id, | 836 void GetChildHandles(BaseTransaction*, const Id& parent_id, |
837 ChildHandles* result); | 837 ChildHandles* result); |
838 void GetChildHandlesImpl(BaseTransaction* trans, const Id& parent_id, | 838 void GetChildHandlesImpl(BaseTransaction* trans, const Id& parent_id, |
839 PathMatcher* matcher, ChildHandles* result); | 839 PathMatcher* matcher, ChildHandles* result); |
840 | 840 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 ~Kernel(); | 974 ~Kernel(); |
975 | 975 |
976 void AddRef(); // For convenience. | 976 void AddRef(); // For convenience. |
977 void Release(); | 977 void Release(); |
978 | 978 |
979 FilePath const db_path; | 979 FilePath const db_path; |
980 // TODO(timsteele): audit use of the member and remove if possible | 980 // TODO(timsteele): audit use of the member and remove if possible |
981 volatile base::subtle::AtomicWord refcount; | 981 volatile base::subtle::AtomicWord refcount; |
982 | 982 |
983 // Implements ReadTransaction / WriteTransaction using a simple lock. | 983 // Implements ReadTransaction / WriteTransaction using a simple lock. |
984 Lock transaction_mutex; | 984 base::Lock transaction_mutex; |
985 | 985 |
986 // The name of this directory. | 986 // The name of this directory. |
987 std::string const name; | 987 std::string const name; |
988 | 988 |
989 // Protects all members below. | 989 // Protects all members below. |
990 // The mutex effectively protects all the indices, but not the | 990 // The mutex effectively protects all the indices, but not the |
991 // entries themselves. So once a pointer to an entry is pulled | 991 // entries themselves. So once a pointer to an entry is pulled |
992 // from the index, the mutex can be unlocked and entry read or written. | 992 // from the index, the mutex can be unlocked and entry read or written. |
993 // | 993 // |
994 // Never hold the mutex and do anything with the database or any | 994 // Never hold the mutex and do anything with the database or any |
995 // other buffered IO. Violating this rule will result in deadlock. | 995 // other buffered IO. Violating this rule will result in deadlock. |
996 Lock mutex; | 996 base::Lock mutex; |
997 MetahandlesIndex* metahandles_index; // Entries indexed by metahandle | 997 MetahandlesIndex* metahandles_index; // Entries indexed by metahandle |
998 IdsIndex* ids_index; // Entries indexed by id | 998 IdsIndex* ids_index; // Entries indexed by id |
999 ParentIdChildIndex* parent_id_child_index; | 999 ParentIdChildIndex* parent_id_child_index; |
1000 ClientTagIndex* client_tag_index; | 1000 ClientTagIndex* client_tag_index; |
1001 // So we don't have to create an EntryKernel every time we want to | 1001 // So we don't have to create an EntryKernel every time we want to |
1002 // look something up in an index. Needle in haystack metaphor. | 1002 // look something up in an index. Needle in haystack metaphor. |
1003 EntryKernel needle; | 1003 EntryKernel needle; |
1004 | 1004 |
1005 // 3 in-memory indices on bits used extremely frequently by the syncer. | 1005 // 3 in-memory indices on bits used extremely frequently by the syncer. |
1006 MetahandleSet* const unapplied_update_metahandles; | 1006 MetahandleSet* const unapplied_update_metahandles; |
1007 MetahandleSet* const unsynced_metahandles; | 1007 MetahandleSet* const unsynced_metahandles; |
1008 // Contains metahandles that are most likely dirty (though not | 1008 // Contains metahandles that are most likely dirty (though not |
1009 // necessarily). Dirtyness is confirmed in TakeSnapshotForSaveChanges(). | 1009 // necessarily). Dirtyness is confirmed in TakeSnapshotForSaveChanges(). |
1010 MetahandleSet* const dirty_metahandles; | 1010 MetahandleSet* const dirty_metahandles; |
1011 | 1011 |
1012 // When a purge takes place, we remove items from all our indices and stash | 1012 // When a purge takes place, we remove items from all our indices and stash |
1013 // them in here so that SaveChanges can persist their permanent deletion. | 1013 // them in here so that SaveChanges can persist their permanent deletion. |
1014 MetahandleSet* const metahandles_to_purge; | 1014 MetahandleSet* const metahandles_to_purge; |
1015 | 1015 |
1016 // TODO(ncarter): Figure out what the hell this is, and comment it. | 1016 // TODO(ncarter): Figure out what the hell this is, and comment it. |
1017 Channel* const channel; | 1017 Channel* const channel; |
1018 | 1018 |
1019 // The changes channel mutex is explicit because it must be locked | 1019 // The changes channel mutex is explicit because it must be locked |
1020 // while holding the transaction mutex and released after | 1020 // while holding the transaction mutex and released after |
1021 // releasing the transaction mutex. | 1021 // releasing the transaction mutex. |
1022 browser_sync::Channel<DirectoryChangeEvent> changes_channel; | 1022 browser_sync::Channel<DirectoryChangeEvent> changes_channel; |
1023 | 1023 |
1024 Lock changes_channel_mutex; | 1024 base::Lock changes_channel_mutex; |
1025 KernelShareInfoStatus info_status; | 1025 KernelShareInfoStatus info_status; |
1026 | 1026 |
1027 // These 3 members are backed in the share_info table, and | 1027 // These 3 members are backed in the share_info table, and |
1028 // their state is marked by the flag above. | 1028 // their state is marked by the flag above. |
1029 | 1029 |
1030 // A structure containing the Directory state that is written back into the | 1030 // A structure containing the Directory state that is written back into the |
1031 // database on SaveChanges. | 1031 // database on SaveChanges. |
1032 PersistedKernelInfo persisted_info; | 1032 PersistedKernelInfo persisted_info; |
1033 | 1033 |
1034 // A unique identifier for this account's cache db, used to generate | 1034 // A unique identifier for this account's cache db, used to generate |
1035 // unique server IDs. No need to lock, only written at init time. | 1035 // unique server IDs. No need to lock, only written at init time. |
1036 std::string cache_guid; | 1036 std::string cache_guid; |
1037 | 1037 |
1038 // It doesn't make sense for two threads to run SaveChanges at the same | 1038 // It doesn't make sense for two threads to run SaveChanges at the same |
1039 // time; this mutex protects that activity. | 1039 // time; this mutex protects that activity. |
1040 Lock save_changes_mutex; | 1040 base::Lock save_changes_mutex; |
1041 | 1041 |
1042 // The next metahandle is protected by kernel mutex. | 1042 // The next metahandle is protected by kernel mutex. |
1043 int64 next_metahandle; | 1043 int64 next_metahandle; |
1044 | 1044 |
1045 // Keep a history of recently flushed metahandles for debugging | 1045 // Keep a history of recently flushed metahandles for debugging |
1046 // purposes. Protected by the save_changes_mutex. | 1046 // purposes. Protected by the save_changes_mutex. |
1047 DebugQueue<int64, 1000> flushed_metahandles; | 1047 DebugQueue<int64, 1000> flushed_metahandles; |
1048 }; | 1048 }; |
1049 | 1049 |
1050 Kernel* kernel_; | 1050 Kernel* kernel_; |
1051 | 1051 |
1052 DirectoryBackingStore* store_; | 1052 DirectoryBackingStore* store_; |
1053 }; | 1053 }; |
1054 | 1054 |
1055 class ScopedKernelLock { | 1055 class ScopedKernelLock { |
1056 public: | 1056 public: |
1057 explicit ScopedKernelLock(const Directory*); | 1057 explicit ScopedKernelLock(const Directory*); |
1058 ~ScopedKernelLock() {} | 1058 ~ScopedKernelLock() {} |
1059 | 1059 |
1060 AutoLock scoped_lock_; | 1060 base::AutoLock scoped_lock_; |
1061 Directory* const dir_; | 1061 Directory* const dir_; |
1062 DISALLOW_COPY_AND_ASSIGN(ScopedKernelLock); | 1062 DISALLOW_COPY_AND_ASSIGN(ScopedKernelLock); |
1063 }; | 1063 }; |
1064 | 1064 |
1065 // Transactions are now processed FIFO with a straight lock | 1065 // Transactions are now processed FIFO with a straight lock |
1066 class BaseTransaction { | 1066 class BaseTransaction { |
1067 friend class Entry; | 1067 friend class Entry; |
1068 public: | 1068 public: |
1069 inline Directory* directory() const { return directory_; } | 1069 inline Directory* directory() const { return directory_; } |
1070 inline Id root_id() const { return Id(); } | 1070 inline Id root_id() const { return Id(); } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1154 void ZeroFields(EntryKernel* entry, int first_field); | 1154 void ZeroFields(EntryKernel* entry, int first_field); |
1155 | 1155 |
1156 } // namespace syncable | 1156 } // namespace syncable |
1157 | 1157 |
1158 std::ostream& operator <<(std::ostream&, const syncable::Blob&); | 1158 std::ostream& operator <<(std::ostream&, const syncable::Blob&); |
1159 | 1159 |
1160 browser_sync::FastDump& operator << | 1160 browser_sync::FastDump& operator << |
1161 (browser_sync::FastDump&, const syncable::Blob&); | 1161 (browser_sync::FastDump&, const syncable::Blob&); |
1162 | 1162 |
1163 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ | 1163 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ |
OLD | NEW |