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 <memory> |
12 #include <set> | 13 #include <set> |
13 #include <string> | 14 #include <string> |
14 #include <unordered_map> | 15 #include <unordered_map> |
15 #include <vector> | 16 #include <vector> |
16 | 17 |
17 #include "base/callback.h" | 18 #include "base/callback.h" |
18 #include "base/containers/hash_tables.h" | 19 #include "base/containers/hash_tables.h" |
19 #include "base/files/file_util.h" | 20 #include "base/files/file_util.h" |
20 #include "base/gtest_prod_util.h" | 21 #include "base/gtest_prod_util.h" |
21 #include "base/macros.h" | 22 #include "base/macros.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 56 |
56 // Directory stores and manages EntryKernels. | 57 // Directory stores and manages EntryKernels. |
57 // | 58 // |
58 // This class is tightly coupled to several other classes via Directory::Kernel. | 59 // This class is tightly coupled to several other classes via Directory::Kernel. |
59 // Although Directory's kernel_ is exposed via public accessor it should be | 60 // Although Directory's kernel_ is exposed via public accessor it should be |
60 // treated as pseudo-private. | 61 // treated as pseudo-private. |
61 class Directory { | 62 class Directory { |
62 public: | 63 public: |
63 typedef std::vector<int64_t> Metahandles; | 64 typedef std::vector<int64_t> Metahandles; |
64 | 65 |
65 typedef std::unordered_map<int64_t, EntryKernel*> MetahandlesMap; | 66 typedef std::unordered_map<int64_t, std::unique_ptr<EntryKernel>> |
| 67 MetahandlesMap; |
66 typedef std::unordered_map<std::string, EntryKernel*> IdsMap; | 68 typedef std::unordered_map<std::string, EntryKernel*> IdsMap; |
67 typedef std::unordered_map<std::string, EntryKernel*> TagsMap; | 69 typedef std::unordered_map<std::string, EntryKernel*> TagsMap; |
68 typedef std::string AttachmentIdUniqueId; | 70 typedef std::string AttachmentIdUniqueId; |
69 typedef std::unordered_map<AttachmentIdUniqueId, MetahandleSet> | 71 typedef std::unordered_map<AttachmentIdUniqueId, MetahandleSet> |
70 IndexByAttachmentId; | 72 IndexByAttachmentId; |
71 | 73 |
72 static const base::FilePath::CharType kSyncDatabaseFilename[]; | 74 static const base::FilePath::CharType kSyncDatabaseFilename[]; |
73 | 75 |
74 // The dirty/clean state of kernel fields backed by the share_info table. | 76 // The dirty/clean state of kernel fields backed by the share_info table. |
75 // This is public so it can be used in SaveChangesSnapshot for persistence. | 77 // This is public so it can be used in SaveChangesSnapshot for persistence. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // Protects all members below. | 164 // Protects all members below. |
163 // The mutex effectively protects all the indices, but not the | 165 // The mutex effectively protects all the indices, but not the |
164 // entries themselves. So once a pointer to an entry is pulled | 166 // entries themselves. So once a pointer to an entry is pulled |
165 // from the index, the mutex can be unlocked and entry read or written. | 167 // from the index, the mutex can be unlocked and entry read or written. |
166 // | 168 // |
167 // Never hold the mutex and do anything with the database or any | 169 // Never hold the mutex and do anything with the database or any |
168 // other buffered IO. Violating this rule will result in deadlock. | 170 // other buffered IO. Violating this rule will result in deadlock. |
169 mutable base::Lock mutex; | 171 mutable base::Lock mutex; |
170 | 172 |
171 // Entries indexed by metahandle. This container is considered to be the | 173 // Entries indexed by metahandle. This container is considered to be the |
172 // owner of all EntryKernels, which may be referened by the other | 174 // owner of all EntryKernels, which may be referenced by the other |
173 // containers. If you remove an EntryKernel from this map, you probably | 175 // containers. If you remove an EntryKernel from this map, you probably |
174 // want to remove it from all other containers and delete it, too. | 176 // want to remove it from all other containers. |
175 MetahandlesMap metahandles_map; | 177 MetahandlesMap metahandles_map; |
176 | 178 |
177 // Entries indexed by id | 179 // Entries indexed by id |
178 IdsMap ids_map; | 180 IdsMap ids_map; |
179 | 181 |
180 // Entries indexed by server tag. | 182 // Entries indexed by server tag. |
181 // This map does not include any entries with non-existent server tags. | 183 // This map does not include any entries with non-existent server tags. |
182 TagsMap server_tags_map; | 184 TagsMap server_tags_map; |
183 | 185 |
184 // Entries indexed by client tag. | 186 // Entries indexed by client tag. |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 | 652 |
651 base::WeakPtrFactory<Directory> weak_ptr_factory_; | 653 base::WeakPtrFactory<Directory> weak_ptr_factory_; |
652 | 654 |
653 DISALLOW_COPY_AND_ASSIGN(Directory); | 655 DISALLOW_COPY_AND_ASSIGN(Directory); |
654 }; | 656 }; |
655 | 657 |
656 } // namespace syncable | 658 } // namespace syncable |
657 } // namespace syncer | 659 } // namespace syncer |
658 | 660 |
659 #endif // COMPONENTS_SYNC_SYNCABLE_DIRECTORY_H_ | 661 #endif // COMPONENTS_SYNC_SYNCABLE_DIRECTORY_H_ |
OLD | NEW |