| 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_ENGINE_SYNCER_H_ | 5 #ifndef SYNC_ENGINE_SYNCER_H_ |
| 6 #define SYNC_ENGINE_SYNCER_H_ | 6 #define SYNC_ENGINE_SYNCER_H_ |
| 7 | 7 |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" |
| 12 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 13 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 14 #include "sync/base/sync_export.h" | 15 #include "sync/base/sync_export.h" |
| 15 #include "sync/engine/conflict_resolver.h" | 16 #include "sync/engine/conflict_resolver.h" |
| 16 #include "sync/engine/syncer_types.h" | 17 #include "sync/engine/syncer_types.h" |
| 17 #include "sync/internal_api/public/base/model_type.h" | 18 #include "sync/internal_api/public/base/model_type.h" |
| 18 #include "sync/sessions/sync_session.h" | 19 #include "sync/sessions/sync_session.h" |
| 19 #include "sync/util/extensions_activity_monitor.h" | 20 #include "sync/util/extensions_activity_monitor.h" |
| 20 | 21 |
| 21 namespace syncer { | 22 namespace syncer { |
| 22 | 23 |
| 23 namespace syncable { | |
| 24 class Entry; | |
| 25 class MutableEntry; | |
| 26 } // namespace syncable | |
| 27 | |
| 28 enum SyncerStep { | |
| 29 SYNCER_BEGIN, | |
| 30 DOWNLOAD_UPDATES, | |
| 31 PROCESS_UPDATES, | |
| 32 STORE_TIMESTAMPS, | |
| 33 APPLY_UPDATES, | |
| 34 COMMIT, | |
| 35 SYNCER_END | |
| 36 }; | |
| 37 | |
| 38 // A Syncer provides a control interface for driving the individual steps | 24 // A Syncer provides a control interface for driving the individual steps |
| 39 // of the sync cycle. Each cycle (hopefully) moves the client into closer | 25 // of the sync cycle. Each cycle (hopefully) moves the client into closer |
| 40 // synchronization with the server. The individual steps are modeled | 26 // synchronization with the server. The individual steps are modeled |
| 41 // as SyncerCommands, and the ordering of the steps is expressed using | 27 // as SyncerCommands, and the ordering of the steps is expressed using |
| 42 // the SyncerStep enum. | 28 // the SyncerStep enum. |
| 43 // | 29 // |
| 44 // A Syncer instance expects to run on a dedicated thread. Calls | 30 // A Syncer instance expects to run on a dedicated thread. Calls |
| 45 // to SyncShare() may take an unbounded amount of time, as SyncerCommands | 31 // to SyncShare() may take an unbounded amount of time, as SyncerCommands |
| 46 // may block on network i/o, on lock contention, or on tasks posted to | 32 // may block on network i/o, on lock contention, or on tasks posted to |
| 47 // other threads. | 33 // other threads. |
| 48 class SYNC_EXPORT_PRIVATE Syncer { | 34 class SYNC_EXPORT_PRIVATE Syncer { |
| 49 public: | 35 public: |
| 50 typedef std::vector<int64> UnsyncedMetaHandles; | 36 typedef std::vector<int64> UnsyncedMetaHandles; |
| 51 | 37 |
| 52 Syncer(); | 38 Syncer(); |
| 53 virtual ~Syncer(); | 39 virtual ~Syncer(); |
| 54 | 40 |
| 55 // Called by other threads to tell the syncer to stop what it's doing | 41 // Called by other threads to tell the syncer to stop what it's doing |
| 56 // and return early from SyncShare, if possible. | 42 // and return early from SyncShare, if possible. |
| 57 bool ExitRequested(); | 43 bool ExitRequested(); |
| 58 void RequestEarlyExit(); | 44 void RequestEarlyExit(); |
| 59 | 45 |
| 60 // Runs a sync cycle from |first_step| to |last_step|. | 46 virtual bool NormalSyncShare(ModelTypeSet request_types, |
| 61 // Returns true if the cycle completed with |last_step|, and false | 47 const sessions::NudgeTracker& nudge_tracker, |
| 62 // if it terminated early due to error / exit requested. | 48 sessions::SyncSession* session); |
| 63 virtual bool SyncShare(sessions::SyncSession* session, | 49 virtual bool ConfigureSyncShare(ModelTypeSet request_types, |
| 64 SyncerStep first_step, | 50 sessions::SyncSession* session); |
| 65 SyncerStep last_step); | 51 virtual bool PollSyncShare(ModelTypeSet request_types, |
| 52 sessions::SyncSession* session); |
| 66 | 53 |
| 67 private: | 54 private: |
| 55 void ApplyUpdates(sessions::SyncSession* session); |
| 56 bool DownloadAndApplyUpdates( |
| 57 sessions::SyncSession* session, |
| 58 base::Callback<SyncerError(void)> download_fn); |
| 59 |
| 60 void HandleCycleBegin(sessions::SyncSession* session); |
| 61 bool HandleCycleEnd(sessions::SyncSession* session); |
| 62 |
| 68 bool early_exit_requested_; | 63 bool early_exit_requested_; |
| 69 base::Lock early_exit_requested_lock_; | 64 base::Lock early_exit_requested_lock_; |
| 70 | 65 |
| 71 friend class SyncerTest; | 66 friend class SyncerTest; |
| 72 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver); | 67 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver); |
| 73 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates); | 68 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates); |
| 74 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent); | 69 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent); |
| 75 FRIEND_TEST_ALL_PREFIXES(SyncerTest, | 70 FRIEND_TEST_ALL_PREFIXES(SyncerTest, |
| 76 TestCommitListOrderingAndNewParentAndChild); | 71 TestCommitListOrderingAndNewParentAndChild); |
| 77 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample); | 72 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample); |
| 78 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting); | 73 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting); |
| 79 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems); | 74 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems); |
| 80 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit); | 75 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit); |
| 81 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced); | 76 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced); |
| 82 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied); | 77 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied); |
| 83 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit); | 78 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit); |
| 84 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder); | 79 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder); |
| 85 FRIEND_TEST_ALL_PREFIXES(SyncerTest, | 80 FRIEND_TEST_ALL_PREFIXES(SyncerTest, |
| 86 LongChangelistCreatesFakeOrphanedEntries); | 81 LongChangelistCreatesFakeOrphanedEntries); |
| 87 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy); | 82 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy); |
| 88 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict); | 83 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict); |
| 89 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits); | 84 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits); |
| 90 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest, | 85 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest, |
| 91 EntryCreatedInNewFolderMidSync); | 86 EntryCreatedInNewFolderMidSync); |
| 92 | 87 |
| 93 DISALLOW_COPY_AND_ASSIGN(Syncer); | 88 DISALLOW_COPY_AND_ASSIGN(Syncer); |
| 94 }; | 89 }; |
| 95 | 90 |
| 96 // Utility function declarations. | |
| 97 void CopyServerFields(syncable::Entry* src, syncable::MutableEntry* dest); | |
| 98 const char* SyncerStepToString(const SyncerStep); | |
| 99 | |
| 100 } // namespace syncer | 91 } // namespace syncer |
| 101 | 92 |
| 102 #endif // SYNC_ENGINE_SYNCER_H_ | 93 #endif // SYNC_ENGINE_SYNCER_H_ |
| OLD | NEW |