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

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: Full patch 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
« no previous file with comments | « sync/engine/sync_scheduler_unittest.cc ('k') | sync/engine/syncer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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:
82 friend class SyncerTest;
83 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver);
84 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates);
85 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent);
86 FRIEND_TEST_ALL_PREFIXES(SyncerTest,
87 TestCommitListOrderingAndNewParentAndChild);
88 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample);
89 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting);
90 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems);
91 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit);
92 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced);
93 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied);
94 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit);
95 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder);
96 FRIEND_TEST_ALL_PREFIXES(SyncerTest,
97 LongChangelistCreatesFakeOrphanedEntries);
98 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy);
99 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict);
100 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits);
101 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest,
102 EntryCreatedInNewFolderMidSync);
103
72 bool DownloadAndApplyUpdates( 104 bool DownloadAndApplyUpdates(
73 ModelTypeSet* request_types, 105 ModelTypeSet* request_types,
74 sessions::SyncSession* session, 106 sessions::SyncSession* session,
75 GetUpdatesProcessor* get_updates_processor, 107 GetUpdatesProcessor* get_updates_processor,
76 bool create_mobile_bookmarks_folder); 108 bool create_mobile_bookmarks_folder);
77 109
78 // This function will commit batches of unsynced items to the server until the 110 // 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 111 // 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 112 // encountered. A request to exit early will be treated as an error and will
81 // abort any blocking operations. 113 // abort any blocking operations.
82 SyncerError BuildAndPostCommits(ModelTypeSet request_types, 114 SyncerError BuildAndPostCommits(ModelTypeSet request_types,
83 sessions::NudgeTracker* nudge_tracker, 115 sessions::NudgeTracker* nudge_tracker,
84 sessions::SyncSession* session, 116 sessions::SyncSession* session,
85 CommitProcessor* commit_processor); 117 CommitProcessor* commit_processor);
86 118
87 void HandleCycleBegin(sessions::SyncSession* session); 119 void HandleCycleBegin(sessions::SyncSession* session);
88 bool HandleCycleEnd( 120 bool HandleCycleEnd(
89 sessions::SyncSession* session, 121 sessions::SyncSession* session,
90 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source); 122 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);
91 123
92 syncer::CancelationSignal* const cancelation_signal_; 124 syncer::CancelationSignal* const cancelation_signal_;
93 125
94 friend class SyncerTest; 126 // Whether the syncer is in the middle of a sync attempt.
95 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver); 127 bool is_syncing_;
96 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates);
97 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent);
98 FRIEND_TEST_ALL_PREFIXES(SyncerTest,
99 TestCommitListOrderingAndNewParentAndChild);
100 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample);
101 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting);
102 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems);
103 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit);
104 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced);
105 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied);
106 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit);
107 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder);
108 FRIEND_TEST_ALL_PREFIXES(SyncerTest,
109 LongChangelistCreatesFakeOrphanedEntries);
110 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy);
111 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict);
112 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits);
113 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest,
114 EntryCreatedInNewFolderMidSync);
115 128
116 DISALLOW_COPY_AND_ASSIGN(Syncer); 129 DISALLOW_COPY_AND_ASSIGN(Syncer);
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
« no previous file with comments | « sync/engine/sync_scheduler_unittest.cc ('k') | sync/engine/syncer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698