Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / sync / engine / syncer.h
blob7b77d07c1933c3d690f20880431a29cf779a694b
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
3 // found in the LICENSE file.
5 #ifndef SYNC_ENGINE_SYNCER_H_
6 #define SYNC_ENGINE_SYNCER_H_
8 #include <utility>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/callback.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/synchronization/lock.h"
15 #include "sync/base/sync_export.h"
16 #include "sync/engine/conflict_resolver.h"
17 #include "sync/engine/syncer_types.h"
18 #include "sync/internal_api/public/base/model_type.h"
19 #include "sync/sessions/sync_session.h"
20 #include "sync/util/extensions_activity.h"
22 namespace syncer {
24 class CancelationSignal;
25 class CommitProcessor;
26 class GetUpdatesProcessor;
28 // A Syncer provides a control interface for driving the sync cycle. These
29 // cycles consist of downloading updates, parsing the response (aka. process
30 // updates), applying updates while resolving conflicts, and committing local
31 // changes. Some of these steps may be skipped if they're deemed to be
32 // unnecessary.
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
36 // lock contention, or on tasks posted to other threads.
37 class SYNC_EXPORT_PRIVATE Syncer {
38 public:
39 typedef std::vector<int64> UnsyncedMetaHandles;
41 Syncer(CancelationSignal* cancelation_signal);
42 virtual ~Syncer();
44 // Whether an early exist was requested due to a cancelation signal.
45 bool ExitRequested();
47 // Whether the syncer is in the middle of a sync cycle.
48 bool IsSyncing() const;
50 // Fetches and applies updates, resolves conflicts and commits local changes
51 // 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
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.
56 virtual bool NormalSyncShare(ModelTypeSet request_types,
57 sessions::NudgeTracker* nudge_tracker,
58 sessions::SyncSession* session);
60 // 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
62 // 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
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.
67 virtual bool ConfigureSyncShare(
68 ModelTypeSet request_types,
69 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source,
70 sessions::SyncSession* session);
72 // Requests to download updates for the |request_types|. For a well-behaved
73 // 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
75 // 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,
79 sessions::SyncSession* session);
81 // Posts a ClearServerData command.
82 // Returns: false if an error occurred and retries should backoff, true
83 // otherwise.
84 virtual bool PostClearServerData(sessions::SyncSession* session);
86 private:
87 friend class SyncerTest;
88 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver);
89 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates);
90 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent);
91 FRIEND_TEST_ALL_PREFIXES(SyncerTest,
92 TestCommitListOrderingAndNewParentAndChild);
93 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample);
94 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting);
95 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems);
96 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit);
97 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced);
98 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied);
99 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit);
100 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder);
101 FRIEND_TEST_ALL_PREFIXES(SyncerTest,
102 LongChangelistCreatesFakeOrphanedEntries);
103 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy);
104 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict);
105 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits);
106 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest,
107 EntryCreatedInNewFolderMidSync);
109 bool DownloadAndApplyUpdates(
110 ModelTypeSet* request_types,
111 sessions::SyncSession* session,
112 GetUpdatesProcessor* get_updates_processor,
113 bool create_mobile_bookmarks_folder);
115 // 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
117 // encountered. A request to exit early will be treated as an error and will
118 // abort any blocking operations.
119 SyncerError BuildAndPostCommits(ModelTypeSet request_types,
120 sessions::NudgeTracker* nudge_tracker,
121 sessions::SyncSession* session,
122 CommitProcessor* commit_processor);
124 void HandleCycleBegin(sessions::SyncSession* session);
125 bool HandleCycleEnd(
126 sessions::SyncSession* session,
127 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);
129 syncer::CancelationSignal* const cancelation_signal_;
131 // Whether the syncer is in the middle of a sync attempt.
132 bool is_syncing_;
134 DISALLOW_COPY_AND_ASSIGN(Syncer);
137 } // namespace syncer
139 #endif // SYNC_ENGINE_SYNCER_H_