More bring up of ui code on iOS.
[chromium-blink-merge.git] / sync / engine / syncer.h
blob8fadde9ecb74a09878bb518e5b7a6ddcd0b26c8e
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/gtest_prod_util.h"
13 #include "base/synchronization/lock.h"
14 #include "sync/engine/conflict_resolver.h"
15 #include "sync/engine/syncer_types.h"
16 #include "sync/internal_api/public/base/model_type.h"
17 #include "sync/sessions/sync_session.h"
18 #include "sync/util/extensions_activity_monitor.h"
20 namespace syncer {
22 namespace syncable {
23 class Entry;
24 class MutableEntry;
25 } // namespace syncable
27 enum SyncerStep {
28 SYNCER_BEGIN,
29 DOWNLOAD_UPDATES,
30 VERIFY_UPDATES,
31 PROCESS_UPDATES,
32 STORE_TIMESTAMPS,
33 APPLY_UPDATES,
34 COMMIT,
35 RESOLVE_CONFLICTS,
36 APPLY_UPDATES_TO_RESOLVE_CONFLICTS,
37 SYNCER_END
40 // A Syncer provides a control interface for driving the individual steps
41 // of the sync cycle. Each cycle (hopefully) moves the client into closer
42 // synchronization with the server. The individual steps are modeled
43 // as SyncerCommands, and the ordering of the steps is expressed using
44 // the SyncerStep enum.
46 // A Syncer instance expects to run on a dedicated thread. Calls
47 // to SyncShare() may take an unbounded amount of time, as SyncerCommands
48 // may block on network i/o, on lock contention, or on tasks posted to
49 // other threads.
50 class Syncer {
51 public:
52 typedef std::vector<int64> UnsyncedMetaHandles;
54 Syncer();
55 virtual ~Syncer();
57 // Called by other threads to tell the syncer to stop what it's doing
58 // and return early from SyncShare, if possible.
59 bool ExitRequested();
60 void RequestEarlyExit();
62 // Runs a sync cycle from |first_step| to |last_step|.
63 virtual void SyncShare(sessions::SyncSession* session,
64 SyncerStep first_step,
65 SyncerStep last_step);
67 private:
68 bool early_exit_requested_;
69 base::Lock early_exit_requested_lock_;
71 ConflictResolver resolver_;
73 friend class SyncerTest;
74 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver);
75 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates);
76 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent);
77 FRIEND_TEST_ALL_PREFIXES(SyncerTest,
78 TestCommitListOrderingAndNewParentAndChild);
79 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample);
80 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting);
81 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems);
82 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit);
83 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced);
84 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied);
85 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit);
86 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder);
87 FRIEND_TEST_ALL_PREFIXES(SyncerTest,
88 LongChangelistCreatesFakeOrphanedEntries);
89 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy);
90 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict);
91 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits);
92 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest,
93 EntryCreatedInNewFolderMidSync);
95 DISALLOW_COPY_AND_ASSIGN(Syncer);
98 // Utility function declarations.
99 void CopyServerFields(syncable::Entry* src, syncable::MutableEntry* dest);
100 void ClearServerData(syncable::MutableEntry* entry);
101 const char* SyncerStepToString(const SyncerStep);
103 } // namespace syncer
105 #endif // SYNC_ENGINE_SYNCER_H_