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

Side by Side Diff: sync/engine/syncer.h

Issue 23189021: sync: Gracefully handle very early shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Retry: sync non-blocking early shutdown Created 7 years, 3 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 | Annotate | Revision Log
« 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
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
24 // A Syncer provides a control interface for driving the individual steps 26 // A Syncer provides a control interface for driving the individual steps
25 // of the sync cycle. Each cycle (hopefully) moves the client into closer 27 // of the sync cycle. Each cycle (hopefully) moves the client into closer
26 // synchronization with the server. The individual steps are modeled 28 // synchronization with the server. The individual steps are modeled
27 // as SyncerCommands, and the ordering of the steps is expressed using 29 // as SyncerCommands, and the ordering of the steps is expressed using
28 // the SyncerStep enum. 30 // the SyncerStep enum.
29 // 31 //
30 // A Syncer instance expects to run on a dedicated thread. Calls 32 // A Syncer instance expects to run on a dedicated thread. Calls
31 // to SyncShare() may take an unbounded amount of time, as SyncerCommands 33 // to SyncShare() may take an unbounded amount of time, as SyncerCommands
32 // may block on network i/o, on lock contention, or on tasks posted to 34 // may block on network i/o, on lock contention, or on tasks posted to
33 // other threads. 35 // other threads.
34 class SYNC_EXPORT_PRIVATE Syncer { 36 class SYNC_EXPORT_PRIVATE Syncer {
35 public: 37 public:
36 typedef std::vector<int64> UnsyncedMetaHandles; 38 typedef std::vector<int64> UnsyncedMetaHandles;
37 39
38 Syncer(); 40 Syncer(CancelationSignal* cancelation_signal);
39 virtual ~Syncer(); 41 virtual ~Syncer();
40 42
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();
45 44
46 // Fetches and applies updates, resolves conflicts and commits local changes 45 // Fetches and applies updates, resolves conflicts and commits local changes
47 // for |request_types| as necessary until client and server states are in 46 // 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 47 // 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. 48 // out of sync and what must be done to bring it back into sync.
50 virtual bool NormalSyncShare(ModelTypeSet request_types, 49 virtual bool NormalSyncShare(ModelTypeSet request_types,
51 const sessions::NudgeTracker& nudge_tracker, 50 const sessions::NudgeTracker& nudge_tracker,
52 sessions::SyncSession* session); 51 sessions::SyncSession* session);
53 52
54 // Performs an initial download for the |request_types|. It is assumed that 53 // Performs an initial download for the |request_types|. It is assumed that
(...skipping 17 matching lines...) Expand all
72 void ApplyUpdates(sessions::SyncSession* session); 71 void ApplyUpdates(sessions::SyncSession* session);
73 bool DownloadAndApplyUpdates( 72 bool DownloadAndApplyUpdates(
74 sessions::SyncSession* session, 73 sessions::SyncSession* session,
75 base::Callback<void(sync_pb::ClientToServerMessage*)> build_fn); 74 base::Callback<void(sync_pb::ClientToServerMessage*)> build_fn);
76 75
77 void HandleCycleBegin(sessions::SyncSession* session); 76 void HandleCycleBegin(sessions::SyncSession* session);
78 bool HandleCycleEnd( 77 bool HandleCycleEnd(
79 sessions::SyncSession* session, 78 sessions::SyncSession* session,
80 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source); 79 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source);
81 80
82 bool early_exit_requested_; 81 syncer::CancelationSignal* const cancelation_signal_;
83 base::Lock early_exit_requested_lock_;
84 82
85 friend class SyncerTest; 83 friend class SyncerTest;
86 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver); 84 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver);
87 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates); 85 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates);
88 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent); 86 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent);
89 FRIEND_TEST_ALL_PREFIXES(SyncerTest, 87 FRIEND_TEST_ALL_PREFIXES(SyncerTest,
90 TestCommitListOrderingAndNewParentAndChild); 88 TestCommitListOrderingAndNewParentAndChild);
91 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample); 89 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample);
92 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting); 90 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting);
93 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems); 91 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems);
94 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit); 92 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit);
95 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced); 93 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced);
96 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied); 94 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied);
97 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit); 95 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit);
98 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder); 96 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder);
99 FRIEND_TEST_ALL_PREFIXES(SyncerTest, 97 FRIEND_TEST_ALL_PREFIXES(SyncerTest,
100 LongChangelistCreatesFakeOrphanedEntries); 98 LongChangelistCreatesFakeOrphanedEntries);
101 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy); 99 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy);
102 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict); 100 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict);
103 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits); 101 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits);
104 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest, 102 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest,
105 EntryCreatedInNewFolderMidSync); 103 EntryCreatedInNewFolderMidSync);
106 104
107 DISALLOW_COPY_AND_ASSIGN(Syncer); 105 DISALLOW_COPY_AND_ASSIGN(Syncer);
108 }; 106 };
109 107
110 } // namespace syncer 108 } // namespace syncer
111 109
112 #endif // SYNC_ENGINE_SYNCER_H_ 110 #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