| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" | 15 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" |
| 16 #include "sync/internal_api/public/util/weak_handle.h" | 16 #include "sync/internal_api/public/util/weak_handle.h" |
| 17 #include "sync/syncable/dir_open_result.h" | 17 #include "sync/syncable/dir_open_result.h" |
| 18 #include "sync/syncable/entry_kernel.h" | 18 #include "sync/syncable/entry_kernel.h" |
| 19 #include "sync/syncable/metahandle_set.h" | 19 #include "sync/syncable/metahandle_set.h" |
| 20 #include "sync/syncable/scoped_kernel_lock.h" | 20 #include "sync/syncable/scoped_kernel_lock.h" |
| 21 #include "sync/util/cryptographer.h" | 21 #include "sync/util/cryptographer.h" |
| 22 | 22 |
| 23 namespace csync { | 23 namespace syncer { |
| 24 class Encryptor; | 24 class Encryptor; |
| 25 class UnrecoverableErrorHandler; | 25 class UnrecoverableErrorHandler; |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace syncable { | 28 namespace syncable { |
| 29 | 29 |
| 30 class DirectoryChangeDelegate; | 30 class DirectoryChangeDelegate; |
| 31 class TransactionObserver; | 31 class TransactionObserver; |
| 32 class BaseTransaction; | 32 class BaseTransaction; |
| 33 class WriteTransaction; | 33 class WriteTransaction; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 KernelShareInfoStatus kernel_info_status; | 195 KernelShareInfoStatus kernel_info_status; |
| 196 PersistedKernelInfo kernel_info; | 196 PersistedKernelInfo kernel_info; |
| 197 EntryKernelSet dirty_metas; | 197 EntryKernelSet dirty_metas; |
| 198 MetahandleSet metahandles_to_purge; | 198 MetahandleSet metahandles_to_purge; |
| 199 }; | 199 }; |
| 200 | 200 |
| 201 // Does not take ownership of |encryptor|. | 201 // Does not take ownership of |encryptor|. |
| 202 // |report_unrecoverable_error_function| may be NULL. | 202 // |report_unrecoverable_error_function| may be NULL. |
| 203 // Takes ownership of |store|. | 203 // Takes ownership of |store|. |
| 204 Directory( | 204 Directory( |
| 205 csync::Encryptor* encryptor, | 205 syncer::Encryptor* encryptor, |
| 206 csync::UnrecoverableErrorHandler* unrecoverable_error_handler, | 206 syncer::UnrecoverableErrorHandler* unrecoverable_error_handler, |
| 207 csync::ReportUnrecoverableErrorFunction | 207 syncer::ReportUnrecoverableErrorFunction |
| 208 report_unrecoverable_error_function, | 208 report_unrecoverable_error_function, |
| 209 DirectoryBackingStore* store); | 209 DirectoryBackingStore* store); |
| 210 virtual ~Directory(); | 210 virtual ~Directory(); |
| 211 | 211 |
| 212 // Does not take ownership of |delegate|, which must not be NULL. | 212 // Does not take ownership of |delegate|, which must not be NULL. |
| 213 // Starts sending events to |delegate| if the returned result is | 213 // Starts sending events to |delegate| if the returned result is |
| 214 // OPENED. Note that events to |delegate| may be sent from *any* | 214 // OPENED. Note that events to |delegate| may be sent from *any* |
| 215 // thread. |transaction_observer| must be initialized. | 215 // thread. |transaction_observer| must be initialized. |
| 216 DirOpenResult Open(const std::string& name, | 216 DirOpenResult Open(const std::string& name, |
| 217 DirectoryChangeDelegate* delegate, | 217 DirectoryChangeDelegate* delegate, |
| 218 const csync::WeakHandle<TransactionObserver>& | 218 const syncer::WeakHandle<TransactionObserver>& |
| 219 transaction_observer); | 219 transaction_observer); |
| 220 | 220 |
| 221 // Stops sending events to the delegate and the transaction | 221 // Stops sending events to the delegate and the transaction |
| 222 // observer. | 222 // observer. |
| 223 void Close(); | 223 void Close(); |
| 224 | 224 |
| 225 int64 NextMetahandle(); | 225 int64 NextMetahandle(); |
| 226 // Always returns a negative id. Positive client ids are generated | 226 // Always returns a negative id. Positive client ids are generated |
| 227 // by the server only. | 227 // by the server only. |
| 228 Id NextId(); | 228 Id NextId(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 256 | 256 |
| 257 std::string GetNotificationState() const; | 257 std::string GetNotificationState() const; |
| 258 void SetNotificationState(const std::string& notification_state); | 258 void SetNotificationState(const std::string& notification_state); |
| 259 | 259 |
| 260 // Unique to each account / client pair. | 260 // Unique to each account / client pair. |
| 261 std::string cache_guid() const; | 261 std::string cache_guid() const; |
| 262 | 262 |
| 263 // Returns a pointer to our cryptographer. Does not transfer ownership. The | 263 // Returns a pointer to our cryptographer. Does not transfer ownership. The |
| 264 // cryptographer is not thread safe; it should not be accessed after the | 264 // cryptographer is not thread safe; it should not be accessed after the |
| 265 // transaction has been released. | 265 // transaction has been released. |
| 266 csync::Cryptographer* GetCryptographer(const BaseTransaction* trans); | 266 syncer::Cryptographer* GetCryptographer(const BaseTransaction* trans); |
| 267 | 267 |
| 268 // Returns true if the directory had encountered an unrecoverable error. | 268 // Returns true if the directory had encountered an unrecoverable error. |
| 269 // Note: Any function in |Directory| that can be called without holding a | 269 // Note: Any function in |Directory| that can be called without holding a |
| 270 // transaction need to check if the Directory already has an unrecoverable | 270 // transaction need to check if the Directory already has an unrecoverable |
| 271 // error on it. | 271 // error on it. |
| 272 bool unrecoverable_error_set(const BaseTransaction* trans) const; | 272 bool unrecoverable_error_set(const BaseTransaction* trans) const; |
| 273 | 273 |
| 274 // Called to immediately report an unrecoverable error (but don't | 274 // Called to immediately report an unrecoverable error (but don't |
| 275 // propagate it up). | 275 // propagate it up). |
| 276 void ReportUnrecoverableError() { | 276 void ReportUnrecoverableError() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 302 // These don't do semantic checking. | 302 // These don't do semantic checking. |
| 303 // The semantic checking is implemented higher up. | 303 // The semantic checking is implemented higher up. |
| 304 bool UnlinkEntryFromOrder(EntryKernel* entry, | 304 bool UnlinkEntryFromOrder(EntryKernel* entry, |
| 305 WriteTransaction* trans, | 305 WriteTransaction* trans, |
| 306 ScopedKernelLock* lock, | 306 ScopedKernelLock* lock, |
| 307 UnlinkReason unlink_reason); | 307 UnlinkReason unlink_reason); |
| 308 | 308 |
| 309 DirOpenResult OpenImpl( | 309 DirOpenResult OpenImpl( |
| 310 const std::string& name, | 310 const std::string& name, |
| 311 DirectoryChangeDelegate* delegate, | 311 DirectoryChangeDelegate* delegate, |
| 312 const csync::WeakHandle<TransactionObserver>& | 312 const syncer::WeakHandle<TransactionObserver>& |
| 313 transaction_observer); | 313 transaction_observer); |
| 314 | 314 |
| 315 private: | 315 private: |
| 316 // These private versions expect the kernel lock to already be held | 316 // These private versions expect the kernel lock to already be held |
| 317 // before calling. | 317 // before calling. |
| 318 EntryKernel* GetEntryById(const Id& id, ScopedKernelLock* const lock); | 318 EntryKernel* GetEntryById(const Id& id, ScopedKernelLock* const lock); |
| 319 | 319 |
| 320 template <class T> void TestAndSet(T* kernel_data, const T* data_to_set); | 320 template <class T> void TestAndSet(T* kernel_data, const T* data_to_set); |
| 321 | 321 |
| 322 public: | 322 public: |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 // items that had a duplicated ID in the end, resulting in a DB key | 470 // items that had a duplicated ID in the end, resulting in a DB key |
| 471 // violation. ID reassociation would fail after an attempted commit. | 471 // violation. ID reassociation would fail after an attempted commit. |
| 472 typedef Index<ClientTagIndexer>::Set ClientTagIndex; | 472 typedef Index<ClientTagIndexer>::Set ClientTagIndex; |
| 473 | 473 |
| 474 protected: | 474 protected: |
| 475 // Used by tests. |delegate| must not be NULL. | 475 // Used by tests. |delegate| must not be NULL. |
| 476 // |transaction_observer| must be initialized. | 476 // |transaction_observer| must be initialized. |
| 477 void InitKernelForTest( | 477 void InitKernelForTest( |
| 478 const std::string& name, | 478 const std::string& name, |
| 479 DirectoryChangeDelegate* delegate, | 479 DirectoryChangeDelegate* delegate, |
| 480 const csync::WeakHandle<TransactionObserver>& | 480 const syncer::WeakHandle<TransactionObserver>& |
| 481 transaction_observer); | 481 transaction_observer); |
| 482 | 482 |
| 483 private: | 483 private: |
| 484 struct Kernel { | 484 struct Kernel { |
| 485 // |delegate| must not be NULL. |transaction_observer| must be | 485 // |delegate| must not be NULL. |transaction_observer| must be |
| 486 // initialized. | 486 // initialized. |
| 487 Kernel(const std::string& name, const KernelLoadInfo& info, | 487 Kernel(const std::string& name, const KernelLoadInfo& info, |
| 488 DirectoryChangeDelegate* delegate, | 488 DirectoryChangeDelegate* delegate, |
| 489 const csync::WeakHandle<TransactionObserver>& | 489 const syncer::WeakHandle<TransactionObserver>& |
| 490 transaction_observer); | 490 transaction_observer); |
| 491 | 491 |
| 492 ~Kernel(); | 492 ~Kernel(); |
| 493 | 493 |
| 494 // Implements ReadTransaction / WriteTransaction using a simple lock. | 494 // Implements ReadTransaction / WriteTransaction using a simple lock. |
| 495 base::Lock transaction_mutex; | 495 base::Lock transaction_mutex; |
| 496 | 496 |
| 497 // Protected by transaction_mutex. Used by WriteTransactions. | 497 // Protected by transaction_mutex. Used by WriteTransactions. |
| 498 int64 next_write_transaction_id; | 498 int64 next_write_transaction_id; |
| 499 | 499 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 // time; this mutex protects that activity. | 547 // time; this mutex protects that activity. |
| 548 base::Lock save_changes_mutex; | 548 base::Lock save_changes_mutex; |
| 549 | 549 |
| 550 // The next metahandle is protected by kernel mutex. | 550 // The next metahandle is protected by kernel mutex. |
| 551 int64 next_metahandle; | 551 int64 next_metahandle; |
| 552 | 552 |
| 553 // The delegate for directory change events. Must not be NULL. | 553 // The delegate for directory change events. Must not be NULL. |
| 554 DirectoryChangeDelegate* const delegate; | 554 DirectoryChangeDelegate* const delegate; |
| 555 | 555 |
| 556 // The transaction observer. | 556 // The transaction observer. |
| 557 const csync::WeakHandle<TransactionObserver> transaction_observer; | 557 const syncer::WeakHandle<TransactionObserver> transaction_observer; |
| 558 }; | 558 }; |
| 559 | 559 |
| 560 // Helper method used to do searches on |parent_id_child_index|. | 560 // Helper method used to do searches on |parent_id_child_index|. |
| 561 ParentIdChildIndex::iterator LocateInParentChildIndex( | 561 ParentIdChildIndex::iterator LocateInParentChildIndex( |
| 562 const ScopedKernelLock& lock, | 562 const ScopedKernelLock& lock, |
| 563 const Id& parent_id, | 563 const Id& parent_id, |
| 564 int64 position_in_parent, | 564 int64 position_in_parent, |
| 565 const Id& item_id_for_tiebreaking); | 565 const Id& item_id_for_tiebreaking); |
| 566 | 566 |
| 567 // Return an iterator to the beginning of the range of the children of | 567 // Return an iterator to the beginning of the range of the children of |
| (...skipping 18 matching lines...) Expand all Loading... |
| 586 // no children. | 586 // no children. |
| 587 EntryKernel* GetPossibleFirstChild( | 587 EntryKernel* GetPossibleFirstChild( |
| 588 const ScopedKernelLock& lock, const Id& parent_id); | 588 const ScopedKernelLock& lock, const Id& parent_id); |
| 589 | 589 |
| 590 // Return a pointer to what is probably (but not certainly) the last | 590 // Return a pointer to what is probably (but not certainly) the last |
| 591 // child of |parent_id|, or NULL if |parent_id| definitely has no | 591 // child of |parent_id|, or NULL if |parent_id| definitely has no |
| 592 // children. | 592 // children. |
| 593 EntryKernel* GetPossibleLastChildForTest( | 593 EntryKernel* GetPossibleLastChildForTest( |
| 594 const ScopedKernelLock& lock, const Id& parent_id); | 594 const ScopedKernelLock& lock, const Id& parent_id); |
| 595 | 595 |
| 596 csync::Cryptographer cryptographer_; | 596 syncer::Cryptographer cryptographer_; |
| 597 | 597 |
| 598 Kernel* kernel_; | 598 Kernel* kernel_; |
| 599 | 599 |
| 600 scoped_ptr<DirectoryBackingStore> store_; | 600 scoped_ptr<DirectoryBackingStore> store_; |
| 601 | 601 |
| 602 csync::UnrecoverableErrorHandler* const unrecoverable_error_handler_; | 602 syncer::UnrecoverableErrorHandler* const unrecoverable_error_handler_; |
| 603 const csync::ReportUnrecoverableErrorFunction | 603 const syncer::ReportUnrecoverableErrorFunction |
| 604 report_unrecoverable_error_function_; | 604 report_unrecoverable_error_function_; |
| 605 bool unrecoverable_error_set_; | 605 bool unrecoverable_error_set_; |
| 606 }; | 606 }; |
| 607 | 607 |
| 608 } // namespace syncable | 608 } // namespace syncable |
| 609 | 609 |
| 610 #endif // SYNC_SYNCABLE_DIRECTORY_H_ | 610 #endif // SYNC_SYNCABLE_DIRECTORY_H_ |
| OLD | NEW |