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 |
(...skipping 23 matching lines...) Expand all Loading... |
34 // A Syncer instance expects to run on a dedicated thread. Calls to SyncShare() | 34 // A Syncer instance expects to run on a dedicated thread. Calls to SyncShare() |
35 // may take an unbounded amount of time because it may block on network I/O, on | 35 // may take an unbounded amount of time because it may block on network I/O, on |
36 // lock contention, or on tasks posted to other threads. | 36 // lock contention, or on tasks posted to other threads. |
37 class SYNC_EXPORT_PRIVATE Syncer { | 37 class SYNC_EXPORT_PRIVATE Syncer { |
38 public: | 38 public: |
39 typedef std::vector<int64> UnsyncedMetaHandles; | 39 typedef std::vector<int64> UnsyncedMetaHandles; |
40 | 40 |
41 Syncer(CancelationSignal* cancelation_signal); | 41 Syncer(CancelationSignal* cancelation_signal); |
42 virtual ~Syncer(); | 42 virtual ~Syncer(); |
43 | 43 |
44 // Whether an early exist was requested due to a cancelation signal. | |
45 bool ExitRequested(); | 44 bool ExitRequested(); |
46 | 45 |
47 // Whether the syncer is in the middle of a sync cycle. | |
48 bool IsSyncing() const; | |
49 | |
50 // Fetches and applies updates, resolves conflicts and commits local changes | 46 // Fetches and applies updates, resolves conflicts and commits local changes |
51 // for |request_types| as necessary until client and server states are in | 47 // for |request_types| as necessary until client and server states are in |
52 // sync. The |nudge_tracker| contains state that describes why the client is | 48 // sync. The |nudge_tracker| contains state that describes why the client is |
53 // out of sync and what must be done to bring it back into sync. | 49 // out of sync and what must be done to bring it back into sync. |
54 // Returns: false if an error occurred and retries should backoff, true | |
55 // otherwise. | |
56 virtual bool NormalSyncShare(ModelTypeSet request_types, | 50 virtual bool NormalSyncShare(ModelTypeSet request_types, |
57 sessions::NudgeTracker* nudge_tracker, | 51 sessions::NudgeTracker* nudge_tracker, |
58 sessions::SyncSession* session); | 52 sessions::SyncSession* session); |
59 | 53 |
60 // Performs an initial download for the |request_types|. It is assumed that | 54 // Performs an initial download for the |request_types|. It is assumed that |
61 // the specified types have no local state, and that their associated change | 55 // the specified types have no local state, and that their associated change |
62 // processors are in "passive" mode, so none of the downloaded updates will be | 56 // processors are in "passive" mode, so none of the downloaded updates will be |
63 // applied to the model. The |source| is sent up to the server for debug | 57 // applied to the model. The |source| is sent up to the server for debug |
64 // purposes. It describes the reson for performing this initial download. | 58 // purposes. It describes the reson for performing this initial download. |
65 // Returns: false if an error occurred and retries should backoff, true | |
66 // otherwise. | |
67 virtual bool ConfigureSyncShare( | 59 virtual bool ConfigureSyncShare( |
68 ModelTypeSet request_types, | 60 ModelTypeSet request_types, |
69 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, | 61 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, |
70 sessions::SyncSession* session); | 62 sessions::SyncSession* session); |
71 | 63 |
72 // Requests to download updates for the |request_types|. For a well-behaved | 64 // Requests to download updates for the |request_types|. For a well-behaved |
73 // client with a working connection to the invalidations server, this should | 65 // client with a working connection to the invalidations server, this should |
74 // be unnecessary. It may be invoked periodically to try to keep the client | 66 // be unnecessary. It may be invoked periodically to try to keep the client |
75 // in sync despite bugs or transient failures. | 67 // in sync despite bugs or transient failures. |
76 // Returns: false if an error occurred and retries should backoff, true | |
77 // otherwise. | |
78 virtual bool PollSyncShare(ModelTypeSet request_types, | 68 virtual bool PollSyncShare(ModelTypeSet request_types, |
79 sessions::SyncSession* session); | 69 sessions::SyncSession* session); |
80 | 70 |
81 private: | 71 private: |
| 72 bool DownloadAndApplyUpdates( |
| 73 ModelTypeSet* request_types, |
| 74 sessions::SyncSession* session, |
| 75 GetUpdatesProcessor* get_updates_processor, |
| 76 bool create_mobile_bookmarks_folder); |
| 77 |
| 78 // This function will commit batches of unsynced items to the server until the |
| 79 // number of unsynced and ready to commit items reaches zero or an error is |
| 80 // encountered. A request to exit early will be treated as an error and will |
| 81 // abort any blocking operations. |
| 82 SyncerError BuildAndPostCommits(ModelTypeSet request_types, |
| 83 sessions::NudgeTracker* nudge_tracker, |
| 84 sessions::SyncSession* session, |
| 85 CommitProcessor* commit_processor); |
| 86 |
| 87 void HandleCycleBegin(sessions::SyncSession* session); |
| 88 bool HandleCycleEnd( |
| 89 sessions::SyncSession* session, |
| 90 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source); |
| 91 |
| 92 syncer::CancelationSignal* const cancelation_signal_; |
| 93 |
82 friend class SyncerTest; | 94 friend class SyncerTest; |
83 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver); | 95 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver); |
84 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates); | 96 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates); |
85 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent); | 97 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent); |
86 FRIEND_TEST_ALL_PREFIXES(SyncerTest, | 98 FRIEND_TEST_ALL_PREFIXES(SyncerTest, |
87 TestCommitListOrderingAndNewParentAndChild); | 99 TestCommitListOrderingAndNewParentAndChild); |
88 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample); | 100 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample); |
89 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting); | 101 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting); |
90 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems); | 102 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems); |
91 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit); | 103 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit); |
92 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced); | 104 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced); |
93 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied); | 105 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied); |
94 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit); | 106 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit); |
95 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder); | 107 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder); |
96 FRIEND_TEST_ALL_PREFIXES(SyncerTest, | 108 FRIEND_TEST_ALL_PREFIXES(SyncerTest, |
97 LongChangelistCreatesFakeOrphanedEntries); | 109 LongChangelistCreatesFakeOrphanedEntries); |
98 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy); | 110 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy); |
99 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict); | 111 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict); |
100 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits); | 112 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits); |
101 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest, | 113 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest, |
102 EntryCreatedInNewFolderMidSync); | 114 EntryCreatedInNewFolderMidSync); |
103 | 115 |
104 bool DownloadAndApplyUpdates( | |
105 ModelTypeSet* request_types, | |
106 sessions::SyncSession* session, | |
107 GetUpdatesProcessor* get_updates_processor, | |
108 bool create_mobile_bookmarks_folder); | |
109 | |
110 // This function will commit batches of unsynced items to the server until the | |
111 // number of unsynced and ready to commit items reaches zero or an error is | |
112 // encountered. A request to exit early will be treated as an error and will | |
113 // abort any blocking operations. | |
114 SyncerError BuildAndPostCommits(ModelTypeSet request_types, | |
115 sessions::NudgeTracker* nudge_tracker, | |
116 sessions::SyncSession* session, | |
117 CommitProcessor* commit_processor); | |
118 | |
119 void HandleCycleBegin(sessions::SyncSession* session); | |
120 bool HandleCycleEnd( | |
121 sessions::SyncSession* session, | |
122 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source); | |
123 | |
124 syncer::CancelationSignal* const cancelation_signal_; | |
125 | |
126 // Whether the syncer is in the middle of a sync attempt. | |
127 bool is_syncing_; | |
128 | |
129 DISALLOW_COPY_AND_ASSIGN(Syncer); | 116 DISALLOW_COPY_AND_ASSIGN(Syncer); |
130 }; | 117 }; |
131 | 118 |
132 } // namespace syncer | 119 } // namespace syncer |
133 | 120 |
134 #endif // SYNC_ENGINE_SYNCER_H_ | 121 #endif // SYNC_ENGINE_SYNCER_H_ |
OLD | NEW |