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

Side by Side Diff: components/sync/syncable/directory.h

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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
« no previous file with comments | « components/sync/syncable/dir_open_result.h ('k') | components/sync/syncable/directory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 SYNC_SYNCABLE_DIRECTORY_H_ 5 #ifndef COMPONENTS_SYNC_SYNCABLE_DIRECTORY_H_
6 #define 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 "sync/api/attachments/attachment_id.h" 23 #include "components/sync/api/attachments/attachment_id.h"
24 #include "sync/base/sync_export.h" 24 #include "components/sync/base/sync_export.h"
25 #include "sync/internal_api/public/util/weak_handle.h" 25 #include "components/sync/base/weak_handle.h"
26 #include "sync/syncable/dir_open_result.h" 26 #include "components/sync/syncable/dir_open_result.h"
27 #include "sync/syncable/entry.h" 27 #include "components/sync/syncable/entry.h"
28 #include "sync/syncable/entry_kernel.h" 28 #include "components/sync/syncable/entry_kernel.h"
29 #include "sync/syncable/metahandle_set.h" 29 #include "components/sync/syncable/metahandle_set.h"
30 #include "sync/syncable/parent_child_index.h" 30 #include "components/sync/syncable/parent_child_index.h"
31 #include "sync/syncable/syncable_delete_journal.h" 31 #include "components/sync/syncable/syncable_delete_journal.h"
32 32
33 namespace syncer { 33 namespace syncer {
34 34
35 class Cryptographer; 35 class Cryptographer;
36 class TestUserShare; 36 class TestUserShare;
37 class UnrecoverableErrorHandler; 37 class UnrecoverableErrorHandler;
38 38
39 namespace syncable { 39 namespace syncable {
40 40
41 class BaseTransaction; 41 class BaseTransaction;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // The per-datatype context. 113 // The per-datatype context.
114 sync_pb::DataTypeContext datatype_context[MODEL_TYPE_COUNT]; 114 sync_pb::DataTypeContext datatype_context[MODEL_TYPE_COUNT];
115 }; 115 };
116 116
117 // What the Directory needs on initialization to create itself and its Kernel. 117 // What the Directory needs on initialization to create itself and its Kernel.
118 // Filled by DirectoryBackingStore::Load. 118 // Filled by DirectoryBackingStore::Load.
119 struct KernelLoadInfo { 119 struct KernelLoadInfo {
120 PersistedKernelInfo kernel_info; 120 PersistedKernelInfo kernel_info;
121 std::string cache_guid; // Created on first initialization, never changes. 121 std::string cache_guid; // Created on first initialization, never changes.
122 int64_t max_metahandle; // Computed (using sql MAX aggregate) on init. 122 int64_t max_metahandle; // Computed (using sql MAX aggregate) on init.
123 KernelLoadInfo() : max_metahandle(0) { 123 KernelLoadInfo() : max_metahandle(0) {}
124 }
125 }; 124 };
126 125
127 // When the Directory is told to SaveChanges, a SaveChangesSnapshot is 126 // When the Directory is told to SaveChanges, a SaveChangesSnapshot is
128 // constructed and forms a consistent snapshot of what needs to be sent to 127 // constructed and forms a consistent snapshot of what needs to be sent to
129 // the backing store. 128 // the backing store.
130 struct SYNC_EXPORT SaveChangesSnapshot { 129 struct SYNC_EXPORT SaveChangesSnapshot {
131 SaveChangesSnapshot(); 130 SaveChangesSnapshot();
132 ~SaveChangesSnapshot(); 131 ~SaveChangesSnapshot();
133 132
134 // Returns true if this snapshot has any unsaved metahandle changes. 133 // Returns true if this snapshot has any unsaved metahandle changes.
135 bool HasUnsavedMetahandleChanges() const; 134 bool HasUnsavedMetahandleChanges() const;
136 135
137 KernelShareInfoStatus kernel_info_status; 136 KernelShareInfoStatus kernel_info_status;
138 PersistedKernelInfo kernel_info; 137 PersistedKernelInfo kernel_info;
139 EntryKernelSet dirty_metas; 138 EntryKernelSet dirty_metas;
140 MetahandleSet metahandles_to_purge; 139 MetahandleSet metahandles_to_purge;
141 EntryKernelSet delete_journals; 140 EntryKernelSet delete_journals;
142 MetahandleSet delete_journals_to_purge; 141 MetahandleSet delete_journals_to_purge;
143 }; 142 };
144 143
145 struct Kernel { 144 struct Kernel {
146 // |delegate| must not be NULL. |transaction_observer| must be 145 // |delegate| must not be NULL. |transaction_observer| must be
147 // initialized. 146 // initialized.
148 Kernel(const std::string& name, const KernelLoadInfo& info, 147 Kernel(const std::string& name,
148 const KernelLoadInfo& info,
149 DirectoryChangeDelegate* delegate, 149 DirectoryChangeDelegate* delegate,
150 const WeakHandle<TransactionObserver>& transaction_observer); 150 const WeakHandle<TransactionObserver>& transaction_observer);
151 151
152 ~Kernel(); 152 ~Kernel();
153 153
154 // Implements ReadTransaction / WriteTransaction using a simple lock. 154 // Implements ReadTransaction / WriteTransaction using a simple lock.
155 base::Lock transaction_mutex; 155 base::Lock transaction_mutex;
156 156
157 // Protected by transaction_mutex. Used by WriteTransactions. 157 // Protected by transaction_mutex. Used by WriteTransactions.
158 int64_t next_write_transaction_id; 158 int64_t next_write_transaction_id;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, 249 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler,
250 const base::Closure& report_unrecoverable_error_function, 250 const base::Closure& report_unrecoverable_error_function,
251 NigoriHandler* nigori_handler, 251 NigoriHandler* nigori_handler,
252 Cryptographer* cryptographer); 252 Cryptographer* cryptographer);
253 virtual ~Directory(); 253 virtual ~Directory();
254 254
255 // Does not take ownership of |delegate|, which must not be NULL. 255 // Does not take ownership of |delegate|, which must not be NULL.
256 // Starts sending events to |delegate| if the returned result is 256 // Starts sending events to |delegate| if the returned result is
257 // OPENED. Note that events to |delegate| may be sent from *any* 257 // OPENED. Note that events to |delegate| may be sent from *any*
258 // thread. |transaction_observer| must be initialized. 258 // thread. |transaction_observer| must be initialized.
259 DirOpenResult Open(const std::string& name, 259 DirOpenResult Open(
260 DirectoryChangeDelegate* delegate, 260 const std::string& name,
261 const WeakHandle<TransactionObserver>& 261 DirectoryChangeDelegate* delegate,
262 transaction_observer); 262 const WeakHandle<TransactionObserver>& transaction_observer);
263 263
264 int64_t NextMetahandle(); 264 int64_t NextMetahandle();
265 // Generates next client ID based on a randomly generated GUID. 265 // Generates next client ID based on a randomly generated GUID.
266 syncable::Id NextId(); 266 syncable::Id NextId();
267 267
268 bool good() const { return NULL != kernel_; } 268 bool good() const { return NULL != kernel_; }
269 269
270 // The download progress is an opaque token provided by the sync server 270 // The download progress is an opaque token provided by the sync server
271 // to indicate the continuation state of the next GetUpdates operation. 271 // to indicate the continuation state of the next GetUpdates operation.
272 void GetDownloadProgress( 272 void GetDownloadProgress(ModelType type,
273 ModelType type, 273 sync_pb::DataTypeProgressMarker* value_out) const;
274 sync_pb::DataTypeProgressMarker* value_out) const; 274 void GetDownloadProgressAsString(ModelType type,
275 void GetDownloadProgressAsString( 275 std::string* value_out) const;
276 ModelType type, 276 void SetDownloadProgress(ModelType type,
277 std::string* value_out) const; 277 const sync_pb::DataTypeProgressMarker& value);
278 void SetDownloadProgress(
279 ModelType type,
280 const sync_pb::DataTypeProgressMarker& value);
281 bool HasEmptyDownloadProgress(ModelType type) const; 278 bool HasEmptyDownloadProgress(ModelType type) const;
282 279
283 // Gets the total number of entries in the directory. 280 // Gets the total number of entries in the directory.
284 size_t GetEntriesCount() const; 281 size_t GetEntriesCount() const;
285 282
286 // Gets/Increments transaction version of a model type. Must be called when 283 // Gets/Increments transaction version of a model type. Must be called when
287 // holding kernel mutex. 284 // holding kernel mutex.
288 int64_t GetTransactionVersion(ModelType type) const; 285 int64_t GetTransactionVersion(ModelType type) const;
289 void IncrementTransactionVersion(ModelType type); 286 void IncrementTransactionVersion(ModelType type);
290 287
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 Cryptographer* GetCryptographer(const BaseTransaction* trans); 326 Cryptographer* GetCryptographer(const BaseTransaction* trans);
330 327
331 // Called to immediately report an unrecoverable error (but don't 328 // Called to immediately report an unrecoverable error (but don't
332 // propagate it up). 329 // propagate it up).
333 void ReportUnrecoverableError(); 330 void ReportUnrecoverableError();
334 331
335 // Called to set the unrecoverable error on the directory and to propagate 332 // Called to set the unrecoverable error on the directory and to propagate
336 // the error to upper layers. 333 // the error to upper layers.
337 void OnUnrecoverableError(const BaseTransaction* trans, 334 void OnUnrecoverableError(const BaseTransaction* trans,
338 const tracked_objects::Location& location, 335 const tracked_objects::Location& location,
339 const std::string & message); 336 const std::string& message);
340 337
341 DeleteJournal* delete_journal(); 338 DeleteJournal* delete_journal();
342 339
343 // Returns the child meta handles (even those for deleted/unlinked 340 // Returns the child meta handles (even those for deleted/unlinked
344 // nodes) for given parent id. Clears |result| if there are no 341 // nodes) for given parent id. Clears |result| if there are no
345 // children. 342 // children.
346 bool GetChildHandlesById(BaseTransaction*, const Id& parent_id, 343 bool GetChildHandlesById(BaseTransaction*,
347 Metahandles* result); 344 const Id& parent_id,
345 Metahandles* result);
348 346
349 // Counts all items under the given node, including the node itself. 347 // Counts all items under the given node, including the node itself.
350 int GetTotalNodeCount(BaseTransaction*, EntryKernel* kernel_) const; 348 int GetTotalNodeCount(BaseTransaction*, EntryKernel* kernel_) const;
351 349
352 // Returns this item's position within its parent folder. 350 // Returns this item's position within its parent folder.
353 // The left-most item is 0, second left-most is 1, etc. 351 // The left-most item is 0, second left-most is 1, etc.
354 int GetPositionIndex(BaseTransaction*, EntryKernel* kernel_) const; 352 int GetPositionIndex(BaseTransaction*, EntryKernel* kernel_) const;
355 353
356 // Returns true iff |id| has children. 354 // Returns true iff |id| has children.
357 bool HasChildren(BaseTransaction* trans, const Id& id); 355 bool HasChildren(BaseTransaction* trans, const Id& id);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 // 389 //
392 // WARNING: THIS METHOD PERFORMS SYNCHRONOUS I/O VIA SQLITE. 390 // WARNING: THIS METHOD PERFORMS SYNCHRONOUS I/O VIA SQLITE.
393 bool SaveChanges(); 391 bool SaveChanges();
394 392
395 // Returns the number of entities with the unsynced bit set. 393 // Returns the number of entities with the unsynced bit set.
396 int64_t unsynced_entity_count() const; 394 int64_t unsynced_entity_count() const;
397 395
398 // Get GetUnsyncedMetaHandles should only be called after SaveChanges and 396 // Get GetUnsyncedMetaHandles should only be called after SaveChanges and
399 // before any new entries have been created. The intention is that the 397 // before any new entries have been created. The intention is that the
400 // syncer should call it from its PerformSyncQueries member. 398 // syncer should call it from its PerformSyncQueries member.
401 void GetUnsyncedMetaHandles(BaseTransaction* trans, 399 void GetUnsyncedMetaHandles(BaseTransaction* trans, Metahandles* result);
402 Metahandles* result);
403 400
404 // Returns whether or not this |type| has unapplied updates. 401 // Returns whether or not this |type| has unapplied updates.
405 bool TypeHasUnappliedUpdates(ModelType type); 402 bool TypeHasUnappliedUpdates(ModelType type);
406 403
407 // Get all the metahandles for unapplied updates for a given set of 404 // Get all the metahandles for unapplied updates for a given set of
408 // server types. 405 // server types.
409 void GetUnappliedUpdateMetaHandles(BaseTransaction* trans, 406 void GetUnappliedUpdateMetaHandles(BaseTransaction* trans,
410 FullModelTypeSet server_types, 407 FullModelTypeSet server_types,
411 std::vector<int64_t>* result); 408 std::vector<int64_t>* result);
412 409
(...skipping 12 matching lines...) Expand all
425 // Returns a ListValue serialization of all nodes for the given type. 422 // Returns a ListValue serialization of all nodes for the given type.
426 std::unique_ptr<base::ListValue> GetNodeDetailsForType(BaseTransaction* trans, 423 std::unique_ptr<base::ListValue> GetNodeDetailsForType(BaseTransaction* trans,
427 ModelType type); 424 ModelType type);
428 425
429 // Sets the level of invariant checking performed after transactions. 426 // Sets the level of invariant checking performed after transactions.
430 void SetInvariantCheckLevel(InvariantCheckLevel check_level); 427 void SetInvariantCheckLevel(InvariantCheckLevel check_level);
431 428
432 // Checks tree metadata consistency following a transaction. It is intended 429 // Checks tree metadata consistency following a transaction. It is intended
433 // to provide a reasonable tradeoff between performance and comprehensiveness 430 // to provide a reasonable tradeoff between performance and comprehensiveness
434 // and may be used in release code. 431 // and may be used in release code.
435 bool CheckInvariantsOnTransactionClose( 432 bool CheckInvariantsOnTransactionClose(syncable::BaseTransaction* trans,
436 syncable::BaseTransaction* trans, 433 const MetahandleSet& modified_handles);
437 const MetahandleSet& modified_handles);
438 434
439 // Forces a full check of the directory. This operation may be slow and 435 // Forces a full check of the directory. This operation may be slow and
440 // should not be invoked outside of tests. 436 // should not be invoked outside of tests.
441 bool FullyCheckTreeInvariants(BaseTransaction *trans); 437 bool FullyCheckTreeInvariants(BaseTransaction* trans);
442 438
443 // Purges data associated with any entries whose ModelType or ServerModelType 439 // Purges data associated with any entries whose ModelType or ServerModelType
444 // is found in |disabled_types|, from sync directory _both_ in memory and on 440 // is found in |disabled_types|, from sync directory _both_ in memory and on
445 // disk. Only valid, "real" model types are allowed in |disabled_types| (see 441 // disk. Only valid, "real" model types are allowed in |disabled_types| (see
446 // model_type.h for definitions). 442 // model_type.h for definitions).
447 // 1. Data associated with |types_to_journal| is saved in the delete journal 443 // 1. Data associated with |types_to_journal| is saved in the delete journal
448 // to help prevent back-from-dead problem due to offline delete in the next 444 // to help prevent back-from-dead problem due to offline delete in the next
449 // sync session. |types_to_journal| must be a subset of |disabled_types|. 445 // sync session. |types_to_journal| must be a subset of |disabled_types|.
450 // 2. Data associated with |types_to_unapply| is reset to an "unapplied" 446 // 2. Data associated with |types_to_unapply| is reset to an "unapplied"
451 // state, wherein all local data is deleted and IS_UNAPPLIED is set to true. 447 // state, wherein all local data is deleted and IS_UNAPPLIED is set to true.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 void UpdateAttachmentIndex(const int64_t metahandle, 497 void UpdateAttachmentIndex(const int64_t metahandle,
502 const sync_pb::AttachmentMetadata& old_metadata, 498 const sync_pb::AttachmentMetadata& old_metadata,
503 const sync_pb::AttachmentMetadata& new_metadata); 499 const sync_pb::AttachmentMetadata& new_metadata);
504 500
505 virtual EntryKernel* GetEntryById(const Id& id); 501 virtual EntryKernel* GetEntryById(const Id& id);
506 virtual EntryKernel* GetEntryByClientTag(const std::string& tag); 502 virtual EntryKernel* GetEntryByClientTag(const std::string& tag);
507 EntryKernel* GetEntryByServerTag(const std::string& tag); 503 EntryKernel* GetEntryByServerTag(const std::string& tag);
508 504
509 virtual EntryKernel* GetEntryByHandle(int64_t handle); 505 virtual EntryKernel* GetEntryByHandle(int64_t handle);
510 506
511 bool ReindexId(BaseWriteTransaction* trans, EntryKernel* const entry, 507 bool ReindexId(BaseWriteTransaction* trans,
508 EntryKernel* const entry,
512 const Id& new_id); 509 const Id& new_id);
513 510
514 bool ReindexParentId(BaseWriteTransaction* trans, EntryKernel* const entry, 511 bool ReindexParentId(BaseWriteTransaction* trans,
512 EntryKernel* const entry,
515 const Id& new_parent_id); 513 const Id& new_parent_id);
516 514
517 // Accessors for the underlying Kernel. Although these are public methods, the 515 // Accessors for the underlying Kernel. Although these are public methods, the
518 // number of classes that call these should be limited. 516 // number of classes that call these should be limited.
519 Kernel* kernel(); 517 Kernel* kernel();
520 const Kernel* kernel() const; 518 const Kernel* kernel() const;
521 519
522 private: 520 private:
523 friend class SyncableDirectoryTest; 521 friend class SyncableDirectoryTest;
524 friend class syncer::TestUserShare; 522 friend class syncer::TestUserShare;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 std::unique_ptr<DeleteJournal> delete_journal_; 650 std::unique_ptr<DeleteJournal> delete_journal_;
653 651
654 base::WeakPtrFactory<Directory> weak_ptr_factory_; 652 base::WeakPtrFactory<Directory> weak_ptr_factory_;
655 653
656 DISALLOW_COPY_AND_ASSIGN(Directory); 654 DISALLOW_COPY_AND_ASSIGN(Directory);
657 }; 655 };
658 656
659 } // namespace syncable 657 } // namespace syncable
660 } // namespace syncer 658 } // namespace syncer
661 659
662 #endif // SYNC_SYNCABLE_DIRECTORY_H_ 660 #endif // COMPONENTS_SYNC_SYNCABLE_DIRECTORY_H_
OLDNEW
« no previous file with comments | « components/sync/syncable/dir_open_result.h ('k') | components/sync/syncable/directory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698