| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <bitset> | 9 #include <bitset> |
| 10 #include <iosfwd> | 10 #include <iosfwd> |
| 11 #include <limits> | 11 #include <limits> |
| 12 #include <map> | 12 #include <map> |
| 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/lock.h" | 20 #include "base/lock.h" |
| 21 #include "base/time.h" | 21 #include "base/time.h" |
| 22 #include "chrome/browser/sync/protocol/sync.pb.h" | 22 #include "chrome/browser/sync/protocol/sync.pb.h" |
| 23 #include "chrome/browser/sync/syncable/blob.h" | 23 #include "chrome/browser/sync/syncable/blob.h" |
| 24 #include "chrome/browser/sync/syncable/dir_open_result.h" | 24 #include "chrome/browser/sync/syncable/dir_open_result.h" |
| 25 #include "chrome/browser/sync/syncable/directory_event.h" | 25 #include "chrome/browser/sync/syncable/directory_event.h" |
| 26 #include "chrome/browser/sync/syncable/path_name_cmp.h" | 26 #include "chrome/browser/sync/syncable/path_name_cmp.h" |
| 27 #include "chrome/browser/sync/syncable/syncable_id.h" | 27 #include "chrome/browser/sync/syncable/syncable_id.h" |
| 28 #include "chrome/browser/sync/syncable/model_type.h" | 28 #include "chrome/browser/sync/syncable/model_type.h" |
| 29 #include "chrome/browser/sync/util/channel.h" |
| 29 #include "chrome/browser/sync/util/dbgq.h" | 30 #include "chrome/browser/sync/util/dbgq.h" |
| 30 #include "chrome/browser/sync/util/row_iterator.h" | 31 #include "chrome/browser/sync/util/row_iterator.h" |
| 31 #include "chrome/browser/sync/util/sync_types.h" | 32 #include "chrome/browser/sync/util/sync_types.h" |
| 32 #include "chrome/common/deprecated/event_sys.h" | 33 #include "chrome/common/deprecated/event_sys.h" |
| 33 #include "testing/gtest/include/gtest/gtest_prod.h" // For FRIEND_TEST | 34 #include "testing/gtest/include/gtest/gtest_prod.h" // For FRIEND_TEST |
| 34 | 35 |
| 35 struct PurgeInfo; | 36 struct PurgeInfo; |
| 36 | 37 |
| 37 namespace sync_api { | 38 namespace sync_api { |
| 38 class ReadTransaction; | 39 class ReadTransaction; |
| (...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 friend class ReadTransaction; | 666 friend class ReadTransaction; |
| 666 friend class ReadTransactionWithoutDB; | 667 friend class ReadTransactionWithoutDB; |
| 667 friend class ScopedKernelLock; | 668 friend class ScopedKernelLock; |
| 668 friend class ScopedKernelUnlock; | 669 friend class ScopedKernelUnlock; |
| 669 friend class WriteTransaction; | 670 friend class WriteTransaction; |
| 670 friend class SyncableDirectoryTest; | 671 friend class SyncableDirectoryTest; |
| 671 FRIEND_TEST(SyncableDirectoryTest, TakeSnapshotGetsAllDirtyHandlesTest); | 672 FRIEND_TEST(SyncableDirectoryTest, TakeSnapshotGetsAllDirtyHandlesTest); |
| 672 FRIEND_TEST(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest); | 673 FRIEND_TEST(SyncableDirectoryTest, TakeSnapshotGetsOnlyDirtyHandlesTest); |
| 673 | 674 |
| 674 public: | 675 public: |
| 676 class EventListenerHookup; |
| 677 |
| 675 // Various data that the Directory::Kernel we are backing (persisting data | 678 // Various data that the Directory::Kernel we are backing (persisting data |
| 676 // for) needs saved across runs of the application. | 679 // for) needs saved across runs of the application. |
| 677 struct PersistedKernelInfo { | 680 struct PersistedKernelInfo { |
| 678 // Last sync timestamp fetched from the server. | 681 // Last sync timestamp fetched from the server. |
| 679 int64 last_download_timestamp[MODEL_TYPE_COUNT]; | 682 int64 last_download_timestamp[MODEL_TYPE_COUNT]; |
| 680 // true iff we ever reached the end of the changelog. | 683 // true iff we ever reached the end of the changelog. |
| 681 ModelTypeBitSet initial_sync_ended; | 684 ModelTypeBitSet initial_sync_ended; |
| 682 // The store birthday we were given by the server. Contents are opaque to | 685 // The store birthday we were given by the server. Contents are opaque to |
| 683 // the client. | 686 // the client. |
| 684 std::string store_birthday; | 687 std::string store_birthday; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 | 776 |
| 774 // (Account) Store birthday is opaque to the client, | 777 // (Account) Store birthday is opaque to the client, |
| 775 // so we keep it in the format it is in the proto buffer | 778 // so we keep it in the format it is in the proto buffer |
| 776 // in case we switch to a binary birthday later. | 779 // in case we switch to a binary birthday later. |
| 777 std::string store_birthday() const; | 780 std::string store_birthday() const; |
| 778 void set_store_birthday(std::string store_birthday); | 781 void set_store_birthday(std::string store_birthday); |
| 779 | 782 |
| 780 // Unique to each account / client pair. | 783 // Unique to each account / client pair. |
| 781 std::string cache_guid() const; | 784 std::string cache_guid() const; |
| 782 | 785 |
| 786 browser_sync::ChannelHookup<DirectoryChangeEvent>* AddChangeObserver( |
| 787 browser_sync::ChannelEventHandler<DirectoryChangeEvent>* observer); |
| 788 |
| 783 protected: // for friends, mainly used by Entry constructors | 789 protected: // for friends, mainly used by Entry constructors |
| 784 EntryKernel* GetEntryByHandle(const int64 handle); | 790 EntryKernel* GetEntryByHandle(const int64 handle); |
| 785 EntryKernel* GetEntryByHandle(const int64 metahandle, ScopedKernelLock* lock); | 791 EntryKernel* GetEntryByHandle(const int64 metahandle, ScopedKernelLock* lock); |
| 786 EntryKernel* GetEntryById(const Id& id); | 792 EntryKernel* GetEntryById(const Id& id); |
| 787 EntryKernel* GetEntryByServerTag(const std::string& tag); | 793 EntryKernel* GetEntryByServerTag(const std::string& tag); |
| 788 EntryKernel* GetEntryByClientTag(const std::string& tag); | 794 EntryKernel* GetEntryByClientTag(const std::string& tag); |
| 789 EntryKernel* GetRootEntry(); | 795 EntryKernel* GetRootEntry(); |
| 790 bool ReindexId(EntryKernel* const entry, const Id& new_id); | 796 bool ReindexId(EntryKernel* const entry, const Id& new_id); |
| 791 void ReindexParentId(EntryKernel* const entry, const Id& new_parent_id); | 797 void ReindexParentId(EntryKernel* const entry, const Id& new_parent_id); |
| 792 void ClearDirtyMetahandles(); | 798 void ClearDirtyMetahandles(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 809 DirOpenResult OpenImpl(const FilePath& file_path, const std::string& name); | 815 DirOpenResult OpenImpl(const FilePath& file_path, const std::string& name); |
| 810 | 816 |
| 811 struct DirectoryEventTraits { | 817 struct DirectoryEventTraits { |
| 812 typedef DirectoryEvent EventType; | 818 typedef DirectoryEvent EventType; |
| 813 static inline bool IsChannelShutdownEvent(const DirectoryEvent& event) { | 819 static inline bool IsChannelShutdownEvent(const DirectoryEvent& event) { |
| 814 return DIRECTORY_DESTROYED == event; | 820 return DIRECTORY_DESTROYED == event; |
| 815 } | 821 } |
| 816 }; | 822 }; |
| 817 public: | 823 public: |
| 818 typedef EventChannel<DirectoryEventTraits, Lock> Channel; | 824 typedef EventChannel<DirectoryEventTraits, Lock> Channel; |
| 819 typedef EventChannel<DirectoryChangeEvent, Lock> ChangesChannel; | |
| 820 typedef std::vector<int64> ChildHandles; | 825 typedef std::vector<int64> ChildHandles; |
| 821 | 826 |
| 822 // Returns the child meta handles for given parent id. | 827 // Returns the child meta handles for given parent id. |
| 823 void GetChildHandles(BaseTransaction*, const Id& parent_id, | 828 void GetChildHandles(BaseTransaction*, const Id& parent_id, |
| 824 const std::string& path_spec, ChildHandles* result); | 829 const std::string& path_spec, ChildHandles* result); |
| 825 void GetChildHandles(BaseTransaction*, const Id& parent_id, | 830 void GetChildHandles(BaseTransaction*, const Id& parent_id, |
| 826 ChildHandles* result); | 831 ChildHandles* result); |
| 827 void GetChildHandlesImpl(BaseTransaction* trans, const Id& parent_id, | 832 void GetChildHandlesImpl(BaseTransaction* trans, const Id& parent_id, |
| 828 PathMatcher* matcher, ChildHandles* result); | 833 PathMatcher* matcher, ChildHandles* result); |
| 829 | 834 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 // Get all extended attribute keys associated with a metahandle | 867 // Get all extended attribute keys associated with a metahandle |
| 863 void GetExtendedAttributesList(BaseTransaction* trans, int64 metahandle, | 868 void GetExtendedAttributesList(BaseTransaction* trans, int64 metahandle, |
| 864 AttributeKeySet* result); | 869 AttributeKeySet* result); |
| 865 // Flags all extended attributes for deletion on the next SaveChanges. | 870 // Flags all extended attributes for deletion on the next SaveChanges. |
| 866 void DeleteAllExtendedAttributes(WriteTransaction* trans, int64 metahandle); | 871 void DeleteAllExtendedAttributes(WriteTransaction* trans, int64 metahandle); |
| 867 | 872 |
| 868 // Get the channel for post save notification, used by the syncer. | 873 // Get the channel for post save notification, used by the syncer. |
| 869 inline Channel* channel() const { | 874 inline Channel* channel() const { |
| 870 return kernel_->channel; | 875 return kernel_->channel; |
| 871 } | 876 } |
| 872 inline ChangesChannel* changes_channel() const { | |
| 873 return kernel_->changes_channel; | |
| 874 } | |
| 875 | 877 |
| 876 // Checks tree metadata consistency. | 878 // Checks tree metadata consistency. |
| 877 // If full_scan is false, the function will avoid pulling any entries from the | 879 // If full_scan is false, the function will avoid pulling any entries from the |
| 878 // db and scan entries currently in ram. | 880 // db and scan entries currently in ram. |
| 879 // If full_scan is true, all entries will be pulled from the database. | 881 // If full_scan is true, all entries will be pulled from the database. |
| 880 // No return value, CHECKs will be triggered if we're given bad | 882 // No return value, CHECKs will be triggered if we're given bad |
| 881 // information. | 883 // information. |
| 882 void CheckTreeInvariants(syncable::BaseTransaction* trans, | 884 void CheckTreeInvariants(syncable::BaseTransaction* trans, |
| 883 bool full_scan); | 885 bool full_scan); |
| 884 | 886 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 991 // Contains metahandles that are most likely dirty (though not | 993 // Contains metahandles that are most likely dirty (though not |
| 992 // necessarily). Dirtyness is confirmed in TakeSnapshotForSaveChanges(). | 994 // necessarily). Dirtyness is confirmed in TakeSnapshotForSaveChanges(). |
| 993 MetahandleSet* const dirty_metahandles; | 995 MetahandleSet* const dirty_metahandles; |
| 994 | 996 |
| 995 // TODO(ncarter): Figure out what the hell this is, and comment it. | 997 // TODO(ncarter): Figure out what the hell this is, and comment it. |
| 996 Channel* const channel; | 998 Channel* const channel; |
| 997 | 999 |
| 998 // The changes channel mutex is explicit because it must be locked | 1000 // The changes channel mutex is explicit because it must be locked |
| 999 // while holding the transaction mutex and released after | 1001 // while holding the transaction mutex and released after |
| 1000 // releasing the transaction mutex. | 1002 // releasing the transaction mutex. |
| 1001 ChangesChannel* const changes_channel; | 1003 browser_sync::Channel<DirectoryChangeEvent> changes_channel; |
| 1004 |
| 1002 Lock changes_channel_mutex; | 1005 Lock changes_channel_mutex; |
| 1003 KernelShareInfoStatus info_status; | 1006 KernelShareInfoStatus info_status; |
| 1004 | 1007 |
| 1005 // These 3 members are backed in the share_info table, and | 1008 // These 3 members are backed in the share_info table, and |
| 1006 // their state is marked by the flag above. | 1009 // their state is marked by the flag above. |
| 1007 | 1010 |
| 1008 // A structure containing the Directory state that is written back into the | 1011 // A structure containing the Directory state that is written back into the |
| 1009 // database on SaveChanges. | 1012 // database on SaveChanges. |
| 1010 PersistedKernelInfo persisted_info; | 1013 PersistedKernelInfo persisted_info; |
| 1011 | 1014 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 void ZeroFields(EntryKernel* entry, int first_field); | 1174 void ZeroFields(EntryKernel* entry, int first_field); |
| 1172 | 1175 |
| 1173 } // namespace syncable | 1176 } // namespace syncable |
| 1174 | 1177 |
| 1175 std::ostream& operator <<(std::ostream&, const syncable::Blob&); | 1178 std::ostream& operator <<(std::ostream&, const syncable::Blob&); |
| 1176 | 1179 |
| 1177 browser_sync::FastDump& operator << | 1180 browser_sync::FastDump& operator << |
| 1178 (browser_sync::FastDump&, const syncable::Blob&); | 1181 (browser_sync::FastDump&, const syncable::Blob&); |
| 1179 | 1182 |
| 1180 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ | 1183 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ |
| OLD | NEW |