| 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 COMPONENTS_SYNC_ENGINE_IMPL_SYNCER_H_ | 5 #ifndef COMPONENTS_SYNC_ENGINE_IMPL_SYNCER_H_ |
| 6 #define COMPONENTS_SYNC_ENGINE_IMPL_SYNCER_H_ | 6 #define COMPONENTS_SYNC_ENGINE_IMPL_SYNCER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "components/sync/base/extensions_activity.h" | 17 #include "components/sync/base/extensions_activity.h" |
| 18 #include "components/sync/base/model_type.h" | 18 #include "components/sync/base/model_type.h" |
| 19 #include "components/sync/engine_impl/conflict_resolver.h" | 19 #include "components/sync/engine_impl/conflict_resolver.h" |
| 20 #include "components/sync/engine_impl/cycle/sync_cycle.h" |
| 20 #include "components/sync/engine_impl/syncer_types.h" | 21 #include "components/sync/engine_impl/syncer_types.h" |
| 21 #include "components/sync/sessions_impl/sync_session.h" | |
| 22 | 22 |
| 23 namespace syncer { | 23 namespace syncer { |
| 24 | 24 |
| 25 class CancelationSignal; | 25 class CancelationSignal; |
| 26 class CommitProcessor; | 26 class CommitProcessor; |
| 27 class GetUpdatesProcessor; | 27 class GetUpdatesProcessor; |
| 28 | 28 |
| 29 // A Syncer provides a control interface for driving the sync cycle. These | 29 // A Syncer provides a control interface for driving the sync cycle. These |
| 30 // cycles consist of downloading updates, parsing the response (aka. process | 30 // cycles consist of downloading updates, parsing the response (aka. process |
| 31 // updates), applying updates while resolving conflicts, and committing local | 31 // updates), applying updates while resolving conflicts, and committing local |
| (...skipping 16 matching lines...) Expand all Loading... |
| 48 // Whether the syncer is in the middle of a sync cycle. | 48 // Whether the syncer is in the middle of a sync cycle. |
| 49 bool IsSyncing() const; | 49 bool IsSyncing() const; |
| 50 | 50 |
| 51 // Fetches and applies updates, resolves conflicts and commits local changes | 51 // Fetches and applies updates, resolves conflicts and commits local changes |
| 52 // for |request_types| as necessary until client and server states are in | 52 // for |request_types| as necessary until client and server states are in |
| 53 // sync. The |nudge_tracker| contains state that describes why the client is | 53 // sync. The |nudge_tracker| contains state that describes why the client is |
| 54 // out of sync and what must be done to bring it back into sync. | 54 // out of sync and what must be done to bring it back into sync. |
| 55 // Returns: false if an error occurred and retries should backoff, true | 55 // Returns: false if an error occurred and retries should backoff, true |
| 56 // otherwise. | 56 // otherwise. |
| 57 virtual bool NormalSyncShare(ModelTypeSet request_types, | 57 virtual bool NormalSyncShare(ModelTypeSet request_types, |
| 58 sessions::NudgeTracker* nudge_tracker, | 58 NudgeTracker* nudge_tracker, |
| 59 sessions::SyncSession* session); | 59 SyncCycle* cycle); |
| 60 | 60 |
| 61 // Performs an initial download for the |request_types|. It is assumed that | 61 // Performs an initial download for the |request_types|. It is assumed that |
| 62 // the specified types have no local state, and that their associated change | 62 // the specified types have no local state, and that their associated change |
| 63 // processors are in "passive" mode, so none of the downloaded updates will be | 63 // processors are in "passive" mode, so none of the downloaded updates will be |
| 64 // applied to the model. The |source| is sent up to the server for debug | 64 // applied to the model. The |source| is sent up to the server for debug |
| 65 // purposes. It describes the reson for performing this initial download. | 65 // purposes. It describes the reson for performing this initial download. |
| 66 // Returns: false if an error occurred and retries should backoff, true | 66 // Returns: false if an error occurred and retries should backoff, true |
| 67 // otherwise. | 67 // otherwise. |
| 68 virtual bool ConfigureSyncShare( | 68 virtual bool ConfigureSyncShare( |
| 69 ModelTypeSet request_types, | 69 ModelTypeSet request_types, |
| 70 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, | 70 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, |
| 71 sessions::SyncSession* session); | 71 SyncCycle* cycle); |
| 72 | 72 |
| 73 // Requests to download updates for the |request_types|. For a well-behaved | 73 // Requests to download updates for the |request_types|. For a well-behaved |
| 74 // client with a working connection to the invalidations server, this should | 74 // client with a working connection to the invalidations server, this should |
| 75 // be unnecessary. It may be invoked periodically to try to keep the client | 75 // be unnecessary. It may be invoked periodically to try to keep the client |
| 76 // in sync despite bugs or transient failures. | 76 // in sync despite bugs or transient failures. |
| 77 // Returns: false if an error occurred and retries should backoff, true | 77 // Returns: false if an error occurred and retries should backoff, true |
| 78 // otherwise. | 78 // otherwise. |
| 79 virtual bool PollSyncShare(ModelTypeSet request_types, | 79 virtual bool PollSyncShare(ModelTypeSet request_types, SyncCycle* cycle); |
| 80 sessions::SyncSession* session); | |
| 81 | 80 |
| 82 // Posts a ClearServerData command. | 81 // Posts a ClearServerData command. |
| 83 // Returns: false if an error occurred and retries should backoff, true | 82 // Returns: false if an error occurred and retries should backoff, true |
| 84 // otherwise. | 83 // otherwise. |
| 85 virtual bool PostClearServerData(sessions::SyncSession* session); | 84 virtual bool PostClearServerData(SyncCycle* cycle); |
| 86 | 85 |
| 87 private: | 86 private: |
| 88 friend class SyncerTest; | 87 friend class SyncerTest; |
| 89 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver); | 88 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver); |
| 90 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates); | 89 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates); |
| 91 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent); | 90 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent); |
| 92 FRIEND_TEST_ALL_PREFIXES(SyncerTest, | 91 FRIEND_TEST_ALL_PREFIXES(SyncerTest, |
| 93 TestCommitListOrderingAndNewParentAndChild); | 92 TestCommitListOrderingAndNewParentAndChild); |
| 94 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample); | 93 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample); |
| 95 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting); | 94 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting); |
| 96 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems); | 95 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems); |
| 97 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit); | 96 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit); |
| 98 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced); | 97 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced); |
| 99 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied); | 98 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied); |
| 100 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit); | 99 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit); |
| 101 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder); | 100 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder); |
| 102 FRIEND_TEST_ALL_PREFIXES(SyncerTest, | 101 FRIEND_TEST_ALL_PREFIXES(SyncerTest, |
| 103 LongChangelistCreatesFakeOrphanedEntries); | 102 LongChangelistCreatesFakeOrphanedEntries); |
| 104 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy); | 103 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy); |
| 105 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict); | 104 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict); |
| 106 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits); | 105 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits); |
| 107 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest, | 106 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest, |
| 108 EntryCreatedInNewFolderMidSync); | 107 EntryCreatedInNewFolderMidSync); |
| 109 | 108 |
| 110 bool DownloadAndApplyUpdates(ModelTypeSet* request_types, | 109 bool DownloadAndApplyUpdates(ModelTypeSet* request_types, |
| 111 sessions::SyncSession* session, | 110 SyncCycle* cycle, |
| 112 GetUpdatesProcessor* get_updates_processor, | 111 GetUpdatesProcessor* get_updates_processor, |
| 113 bool create_mobile_bookmarks_folder); | 112 bool create_mobile_bookmarks_folder); |
| 114 | 113 |
| 115 // This function will commit batches of unsynced items to the server until the | 114 // This function will commit batches of unsynced items to the server until the |
| 116 // number of unsynced and ready to commit items reaches zero or an error is | 115 // number of unsynced and ready to commit items reaches zero or an error is |
| 117 // encountered. A request to exit early will be treated as an error and will | 116 // encountered. A request to exit early will be treated as an error and will |
| 118 // abort any blocking operations. | 117 // abort any blocking operations. |
| 119 SyncerError BuildAndPostCommits(ModelTypeSet request_types, | 118 SyncerError BuildAndPostCommits(ModelTypeSet request_types, |
| 120 sessions::NudgeTracker* nudge_tracker, | 119 NudgeTracker* nudge_tracker, |
| 121 sessions::SyncSession* session, | 120 SyncCycle* cycle, |
| 122 CommitProcessor* commit_processor); | 121 CommitProcessor* commit_processor); |
| 123 | 122 |
| 124 void HandleCycleBegin(sessions::SyncSession* session); | 123 void HandleCycleBegin(SyncCycle* cycle); |
| 125 bool HandleCycleEnd(sessions::SyncSession* session, | 124 bool HandleCycleEnd(SyncCycle* cycle, |
| 126 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source); | 125 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source); |
| 127 | 126 |
| 128 syncer::CancelationSignal* const cancelation_signal_; | 127 syncer::CancelationSignal* const cancelation_signal_; |
| 129 | 128 |
| 130 // Whether the syncer is in the middle of a sync attempt. | 129 // Whether the syncer is in the middle of a sync attempt. |
| 131 bool is_syncing_; | 130 bool is_syncing_; |
| 132 | 131 |
| 133 DISALLOW_COPY_AND_ASSIGN(Syncer); | 132 DISALLOW_COPY_AND_ASSIGN(Syncer); |
| 134 }; | 133 }; |
| 135 | 134 |
| 136 } // namespace syncer | 135 } // namespace syncer |
| 137 | 136 |
| 138 #endif // COMPONENTS_SYNC_ENGINE_IMPL_SYNCER_H_ | 137 #endif // COMPONENTS_SYNC_ENGINE_IMPL_SYNCER_H_ |
| OLD | NEW |