OLD | NEW |
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 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
15 #include "sync/base/sync_export.h" | 15 #include "sync/base/sync_export.h" |
16 #include "sync/engine/conflict_resolver.h" | 16 #include "sync/engine/conflict_resolver.h" |
17 #include "sync/engine/syncer_types.h" | 17 #include "sync/engine/syncer_types.h" |
18 #include "sync/internal_api/public/base/model_type.h" | 18 #include "sync/internal_api/public/base/model_type.h" |
19 #include "sync/sessions/sync_session.h" | 19 #include "sync/sessions/sync_session.h" |
20 #include "sync/util/extensions_activity.h" | 20 #include "sync/util/extensions_activity.h" |
21 | 21 |
22 namespace syncer { | 22 namespace syncer { |
23 | 23 |
24 class CancelationSignal; | |
25 | |
26 // A Syncer provides a control interface for driving the individual steps | 24 // A Syncer provides a control interface for driving the individual steps |
27 // of the sync cycle. Each cycle (hopefully) moves the client into closer | 25 // of the sync cycle. Each cycle (hopefully) moves the client into closer |
28 // synchronization with the server. The individual steps are modeled | 26 // synchronization with the server. The individual steps are modeled |
29 // as SyncerCommands, and the ordering of the steps is expressed using | 27 // as SyncerCommands, and the ordering of the steps is expressed using |
30 // the SyncerStep enum. | 28 // the SyncerStep enum. |
31 // | 29 // |
32 // A Syncer instance expects to run on a dedicated thread. Calls | 30 // A Syncer instance expects to run on a dedicated thread. Calls |
33 // to SyncShare() may take an unbounded amount of time, as SyncerCommands | 31 // 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 | 32 // may block on network i/o, on lock contention, or on tasks posted to |
35 // other threads. | 33 // other threads. |
36 class SYNC_EXPORT_PRIVATE Syncer { | 34 class SYNC_EXPORT_PRIVATE Syncer { |
37 public: | 35 public: |
38 typedef std::vector<int64> UnsyncedMetaHandles; | 36 typedef std::vector<int64> UnsyncedMetaHandles; |
39 | 37 |
40 Syncer(CancelationSignal* cancelation_signal); | 38 Syncer(); |
41 virtual ~Syncer(); | 39 virtual ~Syncer(); |
42 | 40 |
| 41 // Called by other threads to tell the syncer to stop what it's doing |
| 42 // and return early from SyncShare, if possible. |
43 bool ExitRequested(); | 43 bool ExitRequested(); |
| 44 void RequestEarlyExit(); |
44 | 45 |
45 // Fetches and applies updates, resolves conflicts and commits local changes | 46 // Fetches and applies updates, resolves conflicts and commits local changes |
46 // for |request_types| as necessary until client and server states are in | 47 // 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 // 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 // out of sync and what must be done to bring it back into sync. |
49 virtual bool NormalSyncShare(ModelTypeSet request_types, | 50 virtual bool NormalSyncShare(ModelTypeSet request_types, |
50 const sessions::NudgeTracker& nudge_tracker, | 51 const sessions::NudgeTracker& nudge_tracker, |
51 sessions::SyncSession* session); | 52 sessions::SyncSession* session); |
52 | 53 |
53 // Performs an initial download for the |request_types|. It is assumed that | 54 // Performs an initial download for the |request_types|. It is assumed that |
(...skipping 17 matching lines...) Expand all Loading... |
71 void ApplyUpdates(sessions::SyncSession* session); | 72 void ApplyUpdates(sessions::SyncSession* session); |
72 bool DownloadAndApplyUpdates( | 73 bool DownloadAndApplyUpdates( |
73 sessions::SyncSession* session, | 74 sessions::SyncSession* session, |
74 base::Callback<void(sync_pb::ClientToServerMessage*)> build_fn); | 75 base::Callback<void(sync_pb::ClientToServerMessage*)> build_fn); |
75 | 76 |
76 void HandleCycleBegin(sessions::SyncSession* session); | 77 void HandleCycleBegin(sessions::SyncSession* session); |
77 bool HandleCycleEnd( | 78 bool HandleCycleEnd( |
78 sessions::SyncSession* session, | 79 sessions::SyncSession* session, |
79 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source); | 80 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source); |
80 | 81 |
81 syncer::CancelationSignal* const cancelation_signal_; | 82 bool early_exit_requested_; |
| 83 base::Lock early_exit_requested_lock_; |
82 | 84 |
83 friend class SyncerTest; | 85 friend class SyncerTest; |
84 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver); | 86 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver); |
85 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates); | 87 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates); |
86 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent); | 88 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent); |
87 FRIEND_TEST_ALL_PREFIXES(SyncerTest, | 89 FRIEND_TEST_ALL_PREFIXES(SyncerTest, |
88 TestCommitListOrderingAndNewParentAndChild); | 90 TestCommitListOrderingAndNewParentAndChild); |
89 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample); | 91 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample); |
90 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting); | 92 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting); |
91 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems); | 93 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems); |
92 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit); | 94 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit); |
93 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced); | 95 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced); |
94 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied); | 96 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied); |
95 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit); | 97 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit); |
96 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder); | 98 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder); |
97 FRIEND_TEST_ALL_PREFIXES(SyncerTest, | 99 FRIEND_TEST_ALL_PREFIXES(SyncerTest, |
98 LongChangelistCreatesFakeOrphanedEntries); | 100 LongChangelistCreatesFakeOrphanedEntries); |
99 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy); | 101 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy); |
100 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict); | 102 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict); |
101 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits); | 103 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits); |
102 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest, | 104 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest, |
103 EntryCreatedInNewFolderMidSync); | 105 EntryCreatedInNewFolderMidSync); |
104 | 106 |
105 DISALLOW_COPY_AND_ASSIGN(Syncer); | 107 DISALLOW_COPY_AND_ASSIGN(Syncer); |
106 }; | 108 }; |
107 | 109 |
108 } // namespace syncer | 110 } // namespace syncer |
109 | 111 |
110 #endif // SYNC_ENGINE_SYNCER_H_ | 112 #endif // SYNC_ENGINE_SYNCER_H_ |
OLD | NEW |