Refactor management of overview window copy lifetime into a separate class.
[chromium-blink-merge.git] / sync / engine / syncer.h
blobd943e5f1206dbd4855988f4467a27936dd6f4c59
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;
26 // A Syncer provides a control interface for driving the individual steps
27 // of the sync cycle. Each cycle (hopefully) moves the client into closer
28 // synchronization with the server. The individual steps are modeled
29 // as SyncerCommands, and the ordering of the steps is expressed using
30 // the SyncerStep enum.
32 // A Syncer instance expects to run on a dedicated thread. Calls
33 // to SyncShare() may take an unbounded amount of time, as SyncerCommands
34 // may block on network i/o, on lock contention, or on tasks posted to
35 // other threads.
36 class SYNC_EXPORT_PRIVATE Syncer {
37 public:
38 typedef std::vector<int64> UnsyncedMetaHandles;
40 Syncer(CancelationSignal* cancelation_signal);
41 virtual ~Syncer();
43 bool ExitRequested();
45 // Fetches and applies updates, resolves conflicts and commits local changes
46 // for |request_types| as necessary until client and server states are in
47 // sync. The |nudge_tracker| contains state that describes why the client is
48 // out of sync and what must be done to bring it back into sync.
49 virtual bool NormalSyncShare(ModelTypeSet request_types,
50 const sessions::NudgeTracker& nudge_tracker,
51 sessions::SyncSession* session);
53 // Performs an initial download for the |request_types|. It is assumed that
54 // the specified types have no local state, and that their associated change
55 // processors are in "passive" mode, so none of the downloaded updates will be
56 // applied to the model. The |source| is sent up to the server for debug
57 // purposes. It describes the reson for performing this initial download.
58 virtual bool ConfigureSyncShare(
59 ModelTypeSet request_types,
60 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source,
61 sessions::SyncSession* session);
63 // Requests to download updates for the |request_types|. For a well-behaved
64 // client with a working connection to the invalidations server, this should
65 // be unnecessary. It may be invoked periodically to try to keep the client
66 // in sync despite bugs or transient failures.
67 virtual bool PollSyncShare(ModelTypeSet request_types,
68 sessions::SyncSession* session);
70 private:
71 void ApplyUpdates(sessions::SyncSession* session);
72 bool DownloadAndApplyUpdates(
73 sessions::SyncSession* session,
74 base::Callback<void(sync_pb::ClientToServerMessage*)> build_fn);
76 // This function will commit batches of unsynced items to the server until the
77 // number of unsynced and ready to commit items reaches zero or an error is
78 // encountered. A request to exit early will be treated as an error and will
79 // abort any blocking operations.
80 SyncerError BuildAndPostCommits(
81 ModelTypeSet request_types,
82 sessions::SyncSession* session);
84 void HandleCycleBegin(sessions::SyncSession* session);
85 bool HandleCycleEnd(
86 sessions::SyncSession* session,
87 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);
89 syncer::CancelationSignal* const cancelation_signal_;
91 friend class SyncerTest;
92 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver);
93 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates);
94 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent);
95 FRIEND_TEST_ALL_PREFIXES(SyncerTest,
96 TestCommitListOrderingAndNewParentAndChild);
97 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample);
98 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting);
99 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems);
100 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit);
101 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced);
102 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied);
103 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit);
104 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder);
105 FRIEND_TEST_ALL_PREFIXES(SyncerTest,
106 LongChangelistCreatesFakeOrphanedEntries);
107 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy);
108 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict);
109 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits);
110 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest,
111 EntryCreatedInNewFolderMidSync);
113 DISALLOW_COPY_AND_ASSIGN(Syncer);
116 } // namespace syncer
118 #endif // SYNC_ENGINE_SYNCER_H_