Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: sync/engine/syncer.h

Issue 1132013004: [Sync] Refactoring polling to be reliable. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix SyncClient Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.
44 bool ExitRequested(); 45 bool ExitRequested();
45 46
47 // Whether the syncer is in the middle of a sync cycle.
48 bool IsSyncing() const;
49
46 // Fetches and applies updates, resolves conflicts and commits local changes 50 // Fetches and applies updates, resolves conflicts and commits local changes
47 // for |request_types| as necessary until client and server states are in 51 // for |request_types| as necessary until client and server states are in
48 // sync. The |nudge_tracker| contains state that describes why the client is 52 // sync. The |nudge_tracker| contains state that describes why the client is
49 // out of sync and what must be done to bring it back into sync. 53 // 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.
50 virtual bool NormalSyncShare(ModelTypeSet request_types, 56 virtual bool NormalSyncShare(ModelTypeSet request_types,
51 sessions::NudgeTracker* nudge_tracker, 57 sessions::NudgeTracker* nudge_tracker,
52 sessions::SyncSession* session); 58 sessions::SyncSession* session);
53 59
54 // Performs an initial download for the |request_types|. It is assumed that 60 // Performs an initial download for the |request_types|. It is assumed that
55 // the specified types have no local state, and that their associated change 61 // the specified types have no local state, and that their associated change
56 // processors are in "passive" mode, so none of the downloaded updates will be 62 // processors are in "passive" mode, so none of the downloaded updates will be
57 // applied to the model. The |source| is sent up to the server for debug 63 // applied to the model. The |source| is sent up to the server for debug
58 // purposes. It describes the reson for performing this initial download. 64 // purposes. It describes the reson for performing this initial download.
65 // Returns: false if an error occurred and retries should backoff, true
66 // otherwise.
59 virtual bool ConfigureSyncShare( 67 virtual bool ConfigureSyncShare(
60 ModelTypeSet request_types, 68 ModelTypeSet request_types,
61 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, 69 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source,
62 sessions::SyncSession* session); 70 sessions::SyncSession* session);
63 71
64 // Requests to download updates for the |request_types|. For a well-behaved 72 // Requests to download updates for the |request_types|. For a well-behaved
65 // client with a working connection to the invalidations server, this should 73 // client with a working connection to the invalidations server, this should
66 // be unnecessary. It may be invoked periodically to try to keep the client 74 // be unnecessary. It may be invoked periodically to try to keep the client
67 // in sync despite bugs or transient failures. 75 // in sync despite bugs or transient failures.
76 // Returns: false if an error occurred and retries should backoff, true
77 // otherwise.
68 virtual bool PollSyncShare(ModelTypeSet request_types, 78 virtual bool PollSyncShare(ModelTypeSet request_types,
69 sessions::SyncSession* session); 79 sessions::SyncSession* session);
70 80
71 private: 81 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
94 friend class SyncerTest; 82 friend class SyncerTest;
95 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver); 83 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver);
96 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates); 84 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates);
97 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent); 85 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent);
98 FRIEND_TEST_ALL_PREFIXES(SyncerTest, 86 FRIEND_TEST_ALL_PREFIXES(SyncerTest,
99 TestCommitListOrderingAndNewParentAndChild); 87 TestCommitListOrderingAndNewParentAndChild);
100 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample); 88 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample);
101 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting); 89 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting);
102 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems); 90 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems);
103 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit); 91 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit);
104 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced); 92 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced);
105 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied); 93 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied);
106 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit); 94 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit);
107 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder); 95 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder);
108 FRIEND_TEST_ALL_PREFIXES(SyncerTest, 96 FRIEND_TEST_ALL_PREFIXES(SyncerTest,
109 LongChangelistCreatesFakeOrphanedEntries); 97 LongChangelistCreatesFakeOrphanedEntries);
110 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy); 98 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy);
111 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict); 99 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict);
112 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits); 100 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits);
113 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest, 101 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest,
114 EntryCreatedInNewFolderMidSync); 102 EntryCreatedInNewFolderMidSync);
115 103
116 DISALLOW_COPY_AND_ASSIGN(Syncer); 104 DISALLOW_COPY_AND_ASSIGN(Syncer);
pavely 2015/05/08 23:04:13 nit: DISALLOW_COPY_AND_ASSIGN should be the last t
105
106 bool DownloadAndApplyUpdates(
107 ModelTypeSet* request_types,
108 sessions::SyncSession* session,
109 GetUpdatesProcessor* get_updates_processor,
110 bool create_mobile_bookmarks_folder);
111
112 // This function will commit batches of unsynced items to the server until the
113 // number of unsynced and ready to commit items reaches zero or an error is
114 // encountered. A request to exit early will be treated as an error and will
115 // abort any blocking operations.
116 SyncerError BuildAndPostCommits(ModelTypeSet request_types,
117 sessions::NudgeTracker* nudge_tracker,
118 sessions::SyncSession* session,
119 CommitProcessor* commit_processor);
120
121 void HandleCycleBegin(sessions::SyncSession* session);
122 bool HandleCycleEnd(
123 sessions::SyncSession* session,
124 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);
125
126 syncer::CancelationSignal* const cancelation_signal_;
127
128 // Whether the syncer is in the middle of a sync attempt.
129 bool is_syncing_;
117 }; 130 };
118 131
119 } // namespace syncer 132 } // namespace syncer
120 133
121 #endif // SYNC_ENGINE_SYNCER_H_ 134 #endif // SYNC_ENGINE_SYNCER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698