| 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 #ifndef COMPONENTS_SYNC_SYNCABLE_DIRECTORY_H_ | 5 #ifndef COMPONENTS_SYNC_SYNCABLE_DIRECTORY_H_ |
| 6 #define COMPONENTS_SYNC_SYNCABLE_DIRECTORY_H_ | 6 #define COMPONENTS_SYNC_SYNCABLE_DIRECTORY_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <deque> | 11 #include <deque> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <unordered_map> | 14 #include <unordered_map> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/callback.h" | 17 #include "base/callback.h" |
| 18 #include "base/containers/hash_tables.h" | 18 #include "base/containers/hash_tables.h" |
| 19 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
| 20 #include "base/gtest_prod_util.h" | 20 #include "base/gtest_prod_util.h" |
| 21 #include "base/macros.h" | 21 #include "base/macros.h" |
| 22 #include "base/values.h" | 22 #include "base/values.h" |
| 23 #include "components/sync/api/attachments/attachment_id.h" | 23 #include "components/sync/api/attachments/attachment_id.h" |
| 24 #include "components/sync/base/sync_export.h" | |
| 25 #include "components/sync/base/weak_handle.h" | 24 #include "components/sync/base/weak_handle.h" |
| 26 #include "components/sync/syncable/dir_open_result.h" | 25 #include "components/sync/syncable/dir_open_result.h" |
| 27 #include "components/sync/syncable/entry.h" | 26 #include "components/sync/syncable/entry.h" |
| 28 #include "components/sync/syncable/entry_kernel.h" | 27 #include "components/sync/syncable/entry_kernel.h" |
| 29 #include "components/sync/syncable/metahandle_set.h" | 28 #include "components/sync/syncable/metahandle_set.h" |
| 30 #include "components/sync/syncable/parent_child_index.h" | 29 #include "components/sync/syncable/parent_child_index.h" |
| 31 #include "components/sync/syncable/syncable_delete_journal.h" | 30 #include "components/sync/syncable/syncable_delete_journal.h" |
| 32 | 31 |
| 33 namespace syncer { | 32 namespace syncer { |
| 34 | 33 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 52 VERIFY_CHANGES = 1, // Checks only mutated entries. Does not check | 51 VERIFY_CHANGES = 1, // Checks only mutated entries. Does not check |
| 53 // hierarchy. | 52 // hierarchy. |
| 54 FULL_DB_VERIFICATION = 2 // Check every entry. This can be expensive. | 53 FULL_DB_VERIFICATION = 2 // Check every entry. This can be expensive. |
| 55 }; | 54 }; |
| 56 | 55 |
| 57 // Directory stores and manages EntryKernels. | 56 // Directory stores and manages EntryKernels. |
| 58 // | 57 // |
| 59 // This class is tightly coupled to several other classes via Directory::Kernel. | 58 // This class is tightly coupled to several other classes via Directory::Kernel. |
| 60 // Although Directory's kernel_ is exposed via public accessor it should be | 59 // Although Directory's kernel_ is exposed via public accessor it should be |
| 61 // treated as pseudo-private. | 60 // treated as pseudo-private. |
| 62 class SYNC_EXPORT Directory { | 61 class Directory { |
| 63 public: | 62 public: |
| 64 typedef std::vector<int64_t> Metahandles; | 63 typedef std::vector<int64_t> Metahandles; |
| 65 | 64 |
| 66 typedef std::unordered_map<int64_t, EntryKernel*> MetahandlesMap; | 65 typedef std::unordered_map<int64_t, EntryKernel*> MetahandlesMap; |
| 67 typedef std::unordered_map<std::string, EntryKernel*> IdsMap; | 66 typedef std::unordered_map<std::string, EntryKernel*> IdsMap; |
| 68 typedef std::unordered_map<std::string, EntryKernel*> TagsMap; | 67 typedef std::unordered_map<std::string, EntryKernel*> TagsMap; |
| 69 typedef std::string AttachmentIdUniqueId; | 68 typedef std::string AttachmentIdUniqueId; |
| 70 typedef std::unordered_map<AttachmentIdUniqueId, MetahandleSet> | 69 typedef std::unordered_map<AttachmentIdUniqueId, MetahandleSet> |
| 71 IndexByAttachmentId; | 70 IndexByAttachmentId; |
| 72 | 71 |
| 73 static const base::FilePath::CharType kSyncDatabaseFilename[]; | 72 static const base::FilePath::CharType kSyncDatabaseFilename[]; |
| 74 | 73 |
| 75 // The dirty/clean state of kernel fields backed by the share_info table. | 74 // The dirty/clean state of kernel fields backed by the share_info table. |
| 76 // This is public so it can be used in SaveChangesSnapshot for persistence. | 75 // This is public so it can be used in SaveChangesSnapshot for persistence. |
| 77 enum KernelShareInfoStatus { | 76 enum KernelShareInfoStatus { |
| 78 KERNEL_SHARE_INFO_INVALID, | 77 KERNEL_SHARE_INFO_INVALID, |
| 79 KERNEL_SHARE_INFO_VALID, | 78 KERNEL_SHARE_INFO_VALID, |
| 80 KERNEL_SHARE_INFO_DIRTY | 79 KERNEL_SHARE_INFO_DIRTY |
| 81 }; | 80 }; |
| 82 | 81 |
| 83 // Various data that the Directory::Kernel we are backing (persisting data | 82 // Various data that the Directory::Kernel we are backing (persisting data |
| 84 // for) needs saved across runs of the application. | 83 // for) needs saved across runs of the application. |
| 85 struct SYNC_EXPORT PersistedKernelInfo { | 84 struct PersistedKernelInfo { |
| 86 PersistedKernelInfo(); | 85 PersistedKernelInfo(); |
| 87 ~PersistedKernelInfo(); | 86 ~PersistedKernelInfo(); |
| 88 | 87 |
| 89 // Set the |download_progress| entry for the given model to a | 88 // Set the |download_progress| entry for the given model to a |
| 90 // "first sync" start point. When such a value is sent to the server, | 89 // "first sync" start point. When such a value is sent to the server, |
| 91 // a full download of all objects of the model will be initiated. | 90 // a full download of all objects of the model will be initiated. |
| 92 void ResetDownloadProgress(ModelType model_type); | 91 void ResetDownloadProgress(ModelType model_type); |
| 93 | 92 |
| 94 // Whether a valid progress marker exists for |model_type|. | 93 // Whether a valid progress marker exists for |model_type|. |
| 95 bool HasEmptyDownloadProgress(ModelType model_type); | 94 bool HasEmptyDownloadProgress(ModelType model_type); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 119 struct KernelLoadInfo { | 118 struct KernelLoadInfo { |
| 120 PersistedKernelInfo kernel_info; | 119 PersistedKernelInfo kernel_info; |
| 121 std::string cache_guid; // Created on first initialization, never changes. | 120 std::string cache_guid; // Created on first initialization, never changes. |
| 122 int64_t max_metahandle; // Computed (using sql MAX aggregate) on init. | 121 int64_t max_metahandle; // Computed (using sql MAX aggregate) on init. |
| 123 KernelLoadInfo() : max_metahandle(0) {} | 122 KernelLoadInfo() : max_metahandle(0) {} |
| 124 }; | 123 }; |
| 125 | 124 |
| 126 // When the Directory is told to SaveChanges, a SaveChangesSnapshot is | 125 // When the Directory is told to SaveChanges, a SaveChangesSnapshot is |
| 127 // constructed and forms a consistent snapshot of what needs to be sent to | 126 // constructed and forms a consistent snapshot of what needs to be sent to |
| 128 // the backing store. | 127 // the backing store. |
| 129 struct SYNC_EXPORT SaveChangesSnapshot { | 128 struct SaveChangesSnapshot { |
| 130 SaveChangesSnapshot(); | 129 SaveChangesSnapshot(); |
| 131 ~SaveChangesSnapshot(); | 130 ~SaveChangesSnapshot(); |
| 132 | 131 |
| 133 // Returns true if this snapshot has any unsaved metahandle changes. | 132 // Returns true if this snapshot has any unsaved metahandle changes. |
| 134 bool HasUnsavedMetahandleChanges() const; | 133 bool HasUnsavedMetahandleChanges() const; |
| 135 | 134 |
| 136 KernelShareInfoStatus kernel_info_status; | 135 KernelShareInfoStatus kernel_info_status; |
| 137 PersistedKernelInfo kernel_info; | 136 PersistedKernelInfo kernel_info; |
| 138 EntryKernelSet dirty_metas; | 137 EntryKernelSet dirty_metas; |
| 139 MetahandleSet metahandles_to_purge; | 138 MetahandleSet metahandles_to_purge; |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 | 650 |
| 652 base::WeakPtrFactory<Directory> weak_ptr_factory_; | 651 base::WeakPtrFactory<Directory> weak_ptr_factory_; |
| 653 | 652 |
| 654 DISALLOW_COPY_AND_ASSIGN(Directory); | 653 DISALLOW_COPY_AND_ASSIGN(Directory); |
| 655 }; | 654 }; |
| 656 | 655 |
| 657 } // namespace syncable | 656 } // namespace syncable |
| 658 } // namespace syncer | 657 } // namespace syncer |
| 659 | 658 |
| 660 #endif // COMPONENTS_SYNC_SYNCABLE_DIRECTORY_H_ | 659 #endif // COMPONENTS_SYNC_SYNCABLE_DIRECTORY_H_ |
| OLD | NEW |