| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 SYNC_SYNCABLE_DIRECTORY_H_ |
| 6 #define SYNC_SYNCABLE_DIRECTORY_H_ | 6 #define SYNC_SYNCABLE_DIRECTORY_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 KernelShareInfoStatus kernel_info_status; | 200 KernelShareInfoStatus kernel_info_status; |
| 201 PersistedKernelInfo kernel_info; | 201 PersistedKernelInfo kernel_info; |
| 202 EntryKernelSet dirty_metas; | 202 EntryKernelSet dirty_metas; |
| 203 MetahandleSet metahandles_to_purge; | 203 MetahandleSet metahandles_to_purge; |
| 204 }; | 204 }; |
| 205 | 205 |
| 206 // Does not take ownership of |encryptor|. | 206 // Does not take ownership of |encryptor|. |
| 207 // |report_unrecoverable_error_function| may be NULL. | 207 // |report_unrecoverable_error_function| may be NULL. |
| 208 // Takes ownership of |store|. | 208 // Takes ownership of |store|. |
| 209 Directory( | 209 Directory( |
| 210 syncer::Encryptor* encryptor, | 210 Encryptor* encryptor, |
| 211 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, | 211 UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 212 syncer::ReportUnrecoverableErrorFunction | 212 ReportUnrecoverableErrorFunction |
| 213 report_unrecoverable_error_function, | 213 report_unrecoverable_error_function, |
| 214 DirectoryBackingStore* store); | 214 DirectoryBackingStore* store); |
| 215 virtual ~Directory(); | 215 virtual ~Directory(); |
| 216 | 216 |
| 217 // Does not take ownership of |delegate|, which must not be NULL. | 217 // Does not take ownership of |delegate|, which must not be NULL. |
| 218 // Starts sending events to |delegate| if the returned result is | 218 // Starts sending events to |delegate| if the returned result is |
| 219 // OPENED. Note that events to |delegate| may be sent from *any* | 219 // OPENED. Note that events to |delegate| may be sent from *any* |
| 220 // thread. |transaction_observer| must be initialized. | 220 // thread. |transaction_observer| must be initialized. |
| 221 DirOpenResult Open(const std::string& name, | 221 DirOpenResult Open(const std::string& name, |
| 222 DirectoryChangeDelegate* delegate, | 222 DirectoryChangeDelegate* delegate, |
| 223 const syncer::WeakHandle<TransactionObserver>& | 223 const WeakHandle<TransactionObserver>& |
| 224 transaction_observer); | 224 transaction_observer); |
| 225 | 225 |
| 226 // Stops sending events to the delegate and the transaction | 226 // Stops sending events to the delegate and the transaction |
| 227 // observer. | 227 // observer. |
| 228 void Close(); | 228 void Close(); |
| 229 | 229 |
| 230 int64 NextMetahandle(); | 230 int64 NextMetahandle(); |
| 231 // Always returns a negative id. Positive client ids are generated | 231 // Always returns a negative id. Positive client ids are generated |
| 232 // by the server only. | 232 // by the server only. |
| 233 Id NextId(); | 233 Id NextId(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 261 | 261 |
| 262 std::string GetNotificationState() const; | 262 std::string GetNotificationState() const; |
| 263 void SetNotificationState(const std::string& notification_state); | 263 void SetNotificationState(const std::string& notification_state); |
| 264 | 264 |
| 265 // Unique to each account / client pair. | 265 // Unique to each account / client pair. |
| 266 std::string cache_guid() const; | 266 std::string cache_guid() const; |
| 267 | 267 |
| 268 // Returns a pointer to our cryptographer. Does not transfer ownership. The | 268 // Returns a pointer to our cryptographer. Does not transfer ownership. The |
| 269 // cryptographer is not thread safe; it should not be accessed after the | 269 // cryptographer is not thread safe; it should not be accessed after the |
| 270 // transaction has been released. | 270 // transaction has been released. |
| 271 syncer::Cryptographer* GetCryptographer(const BaseTransaction* trans); | 271 Cryptographer* GetCryptographer(const BaseTransaction* trans); |
| 272 | 272 |
| 273 // Returns true if the directory had encountered an unrecoverable error. | 273 // Returns true if the directory had encountered an unrecoverable error. |
| 274 // Note: Any function in |Directory| that can be called without holding a | 274 // Note: Any function in |Directory| that can be called without holding a |
| 275 // transaction need to check if the Directory already has an unrecoverable | 275 // transaction need to check if the Directory already has an unrecoverable |
| 276 // error on it. | 276 // error on it. |
| 277 bool unrecoverable_error_set(const BaseTransaction* trans) const; | 277 bool unrecoverable_error_set(const BaseTransaction* trans) const; |
| 278 | 278 |
| 279 // Called to immediately report an unrecoverable error (but don't | 279 // Called to immediately report an unrecoverable error (but don't |
| 280 // propagate it up). | 280 // propagate it up). |
| 281 void ReportUnrecoverableError() { | 281 void ReportUnrecoverableError() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 307 // These don't do semantic checking. | 307 // These don't do semantic checking. |
| 308 // The semantic checking is implemented higher up. | 308 // The semantic checking is implemented higher up. |
| 309 bool UnlinkEntryFromOrder(EntryKernel* entry, | 309 bool UnlinkEntryFromOrder(EntryKernel* entry, |
| 310 WriteTransaction* trans, | 310 WriteTransaction* trans, |
| 311 ScopedKernelLock* lock, | 311 ScopedKernelLock* lock, |
| 312 UnlinkReason unlink_reason); | 312 UnlinkReason unlink_reason); |
| 313 | 313 |
| 314 DirOpenResult OpenImpl( | 314 DirOpenResult OpenImpl( |
| 315 const std::string& name, | 315 const std::string& name, |
| 316 DirectoryChangeDelegate* delegate, | 316 DirectoryChangeDelegate* delegate, |
| 317 const syncer::WeakHandle<TransactionObserver>& | 317 const WeakHandle<TransactionObserver>& transaction_observer); |
| 318 transaction_observer); | |
| 319 | 318 |
| 320 private: | 319 private: |
| 321 // These private versions expect the kernel lock to already be held | 320 // These private versions expect the kernel lock to already be held |
| 322 // before calling. | 321 // before calling. |
| 323 EntryKernel* GetEntryById(const Id& id, ScopedKernelLock* const lock); | 322 EntryKernel* GetEntryById(const Id& id, ScopedKernelLock* const lock); |
| 324 | 323 |
| 325 template <class T> void TestAndSet(T* kernel_data, const T* data_to_set); | 324 template <class T> void TestAndSet(T* kernel_data, const T* data_to_set); |
| 326 | 325 |
| 327 public: | 326 public: |
| 328 typedef std::vector<int64> ChildHandles; | 327 typedef std::vector<int64> ChildHandles; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 // items that had a duplicated ID in the end, resulting in a DB key | 477 // items that had a duplicated ID in the end, resulting in a DB key |
| 479 // violation. ID reassociation would fail after an attempted commit. | 478 // violation. ID reassociation would fail after an attempted commit. |
| 480 typedef Index<ClientTagIndexer>::Set ClientTagIndex; | 479 typedef Index<ClientTagIndexer>::Set ClientTagIndex; |
| 481 | 480 |
| 482 protected: | 481 protected: |
| 483 // Used by tests. |delegate| must not be NULL. | 482 // Used by tests. |delegate| must not be NULL. |
| 484 // |transaction_observer| must be initialized. | 483 // |transaction_observer| must be initialized. |
| 485 void InitKernelForTest( | 484 void InitKernelForTest( |
| 486 const std::string& name, | 485 const std::string& name, |
| 487 DirectoryChangeDelegate* delegate, | 486 DirectoryChangeDelegate* delegate, |
| 488 const syncer::WeakHandle<TransactionObserver>& | 487 const WeakHandle<TransactionObserver>& transaction_observer); |
| 489 transaction_observer); | |
| 490 | 488 |
| 491 private: | 489 private: |
| 492 struct Kernel { | 490 struct Kernel { |
| 493 // |delegate| must not be NULL. |transaction_observer| must be | 491 // |delegate| must not be NULL. |transaction_observer| must be |
| 494 // initialized. | 492 // initialized. |
| 495 Kernel(const std::string& name, const KernelLoadInfo& info, | 493 Kernel(const std::string& name, const KernelLoadInfo& info, |
| 496 DirectoryChangeDelegate* delegate, | 494 DirectoryChangeDelegate* delegate, |
| 497 const syncer::WeakHandle<TransactionObserver>& | 495 const WeakHandle<TransactionObserver>& transaction_observer); |
| 498 transaction_observer); | |
| 499 | 496 |
| 500 ~Kernel(); | 497 ~Kernel(); |
| 501 | 498 |
| 502 // Implements ReadTransaction / WriteTransaction using a simple lock. | 499 // Implements ReadTransaction / WriteTransaction using a simple lock. |
| 503 base::Lock transaction_mutex; | 500 base::Lock transaction_mutex; |
| 504 | 501 |
| 505 // Protected by transaction_mutex. Used by WriteTransactions. | 502 // Protected by transaction_mutex. Used by WriteTransactions. |
| 506 int64 next_write_transaction_id; | 503 int64 next_write_transaction_id; |
| 507 | 504 |
| 508 // The name of this directory. | 505 // The name of this directory. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 // time; this mutex protects that activity. | 552 // time; this mutex protects that activity. |
| 556 base::Lock save_changes_mutex; | 553 base::Lock save_changes_mutex; |
| 557 | 554 |
| 558 // The next metahandle is protected by kernel mutex. | 555 // The next metahandle is protected by kernel mutex. |
| 559 int64 next_metahandle; | 556 int64 next_metahandle; |
| 560 | 557 |
| 561 // The delegate for directory change events. Must not be NULL. | 558 // The delegate for directory change events. Must not be NULL. |
| 562 DirectoryChangeDelegate* const delegate; | 559 DirectoryChangeDelegate* const delegate; |
| 563 | 560 |
| 564 // The transaction observer. | 561 // The transaction observer. |
| 565 const syncer::WeakHandle<TransactionObserver> transaction_observer; | 562 const WeakHandle<TransactionObserver> transaction_observer; |
| 566 }; | 563 }; |
| 567 | 564 |
| 568 // Helper method used to do searches on |parent_id_child_index|. | 565 // Helper method used to do searches on |parent_id_child_index|. |
| 569 ParentIdChildIndex::iterator LocateInParentChildIndex( | 566 ParentIdChildIndex::iterator LocateInParentChildIndex( |
| 570 const ScopedKernelLock& lock, | 567 const ScopedKernelLock& lock, |
| 571 const Id& parent_id, | 568 const Id& parent_id, |
| 572 int64 position_in_parent, | 569 int64 position_in_parent, |
| 573 const Id& item_id_for_tiebreaking); | 570 const Id& item_id_for_tiebreaking); |
| 574 | 571 |
| 575 // Return an iterator to the beginning of the range of the children of | 572 // Return an iterator to the beginning of the range of the children of |
| (...skipping 12 matching lines...) Expand all Loading... |
| 588 void AppendChildHandles( | 585 void AppendChildHandles( |
| 589 const ScopedKernelLock& lock, | 586 const ScopedKernelLock& lock, |
| 590 const Id& parent_id, Directory::ChildHandles* result); | 587 const Id& parent_id, Directory::ChildHandles* result); |
| 591 | 588 |
| 592 // Return a pointer to what is probably (but not certainly) the | 589 // Return a pointer to what is probably (but not certainly) the |
| 593 // first child of |parent_id|, or NULL if |parent_id| definitely has | 590 // first child of |parent_id|, or NULL if |parent_id| definitely has |
| 594 // no children. | 591 // no children. |
| 595 EntryKernel* GetPossibleFirstChild( | 592 EntryKernel* GetPossibleFirstChild( |
| 596 const ScopedKernelLock& lock, const Id& parent_id); | 593 const ScopedKernelLock& lock, const Id& parent_id); |
| 597 | 594 |
| 598 syncer::Cryptographer cryptographer_; | 595 Cryptographer cryptographer_; |
| 599 | 596 |
| 600 Kernel* kernel_; | 597 Kernel* kernel_; |
| 601 | 598 |
| 602 scoped_ptr<DirectoryBackingStore> store_; | 599 scoped_ptr<DirectoryBackingStore> store_; |
| 603 | 600 |
| 604 syncer::UnrecoverableErrorHandler* const unrecoverable_error_handler_; | 601 UnrecoverableErrorHandler* const unrecoverable_error_handler_; |
| 605 const syncer::ReportUnrecoverableErrorFunction | 602 const ReportUnrecoverableErrorFunction report_unrecoverable_error_function_; |
| 606 report_unrecoverable_error_function_; | |
| 607 bool unrecoverable_error_set_; | 603 bool unrecoverable_error_set_; |
| 608 | 604 |
| 609 InvariantCheckLevel invariant_check_level_; | 605 InvariantCheckLevel invariant_check_level_; |
| 610 }; | 606 }; |
| 611 | 607 |
| 612 } // namespace syncable | 608 } // namespace syncable |
| 613 } // namespace syncer | 609 } // namespace syncer |
| 614 | 610 |
| 615 #endif // SYNC_SYNCABLE_DIRECTORY_H_ | 611 #endif // SYNC_SYNCABLE_DIRECTORY_H_ |
| OLD | NEW |