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

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

Issue 15764010: Experimental functionize patch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync: Expose sync functionality as functions Created 7 years, 6 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/gtest_prod_util.h" 12 #include "base/gtest_prod_util.h"
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "sync/base/sync_export.h" 14 #include "sync/base/sync_export.h"
15 #include "sync/engine/conflict_resolver.h" 15 #include "sync/engine/conflict_resolver.h"
16 #include "sync/engine/syncer_types.h" 16 #include "sync/engine/syncer_types.h"
17 #include "sync/internal_api/public/base/model_type.h" 17 #include "sync/internal_api/public/base/model_type.h"
18 #include "sync/sessions/sync_session.h" 18 #include "sync/sessions/sync_session.h"
19 #include "sync/util/extensions_activity_monitor.h" 19 #include "sync/util/extensions_activity_monitor.h"
20 20
21 namespace syncer { 21 namespace syncer {
22 22
23 namespace syncable {
24 class Entry;
25 class MutableEntry;
26 } // namespace syncable
27
28 enum SyncerStep {
29 SYNCER_BEGIN,
30 DOWNLOAD_UPDATES,
31 PROCESS_UPDATES,
32 STORE_TIMESTAMPS,
33 APPLY_UPDATES,
34 COMMIT,
35 SYNCER_END
36 };
37
38 // A Syncer provides a control interface for driving the individual steps 23 // A Syncer provides a control interface for driving the individual steps
39 // of the sync cycle. Each cycle (hopefully) moves the client into closer 24 // of the sync cycle. Each cycle (hopefully) moves the client into closer
40 // synchronization with the server. The individual steps are modeled 25 // synchronization with the server. The individual steps are modeled
41 // as SyncerCommands, and the ordering of the steps is expressed using 26 // as SyncerCommands, and the ordering of the steps is expressed using
42 // the SyncerStep enum. 27 // the SyncerStep enum.
43 // 28 //
44 // A Syncer instance expects to run on a dedicated thread. Calls 29 // A Syncer instance expects to run on a dedicated thread. Calls
45 // to SyncShare() may take an unbounded amount of time, as SyncerCommands 30 // to SyncShare() may take an unbounded amount of time, as SyncerCommands
46 // may block on network i/o, on lock contention, or on tasks posted to 31 // may block on network i/o, on lock contention, or on tasks posted to
47 // other threads. 32 // other threads.
48 class SYNC_EXPORT_PRIVATE Syncer { 33 class SYNC_EXPORT_PRIVATE Syncer {
49 public: 34 public:
50 typedef std::vector<int64> UnsyncedMetaHandles; 35 typedef std::vector<int64> UnsyncedMetaHandles;
51 36
52 Syncer(); 37 Syncer();
53 virtual ~Syncer(); 38 virtual ~Syncer();
54 39
55 // Called by other threads to tell the syncer to stop what it's doing 40 // Called by other threads to tell the syncer to stop what it's doing
56 // and return early from SyncShare, if possible. 41 // and return early from SyncShare, if possible.
57 bool ExitRequested(); 42 bool ExitRequested();
58 void RequestEarlyExit(); 43 void RequestEarlyExit();
59 44
60 // Runs a sync cycle from |first_step| to |last_step|. 45 virtual bool NormalSyncShare(sessions::SyncSession* session,
61 // Returns true if the cycle completed with |last_step|, and false 46 ModelTypeSet request_types,
62 // if it terminated early due to error / exit requested. 47 const sessions::NudgeTracker& nudge_tracker);
63 virtual bool SyncShare(sessions::SyncSession* session, 48 virtual bool ConfigureSyncShare(sessions::SyncSession* session,
64 SyncerStep first_step, 49 ModelTypeSet request_types);
65 SyncerStep last_step); 50 virtual bool PollSyncShare(sessions::SyncSession* session,
51 ModelTypeSet request_types);
66 52
67 private: 53 private:
54 void ApplyUpdates(sessions::SyncSession* session);
55
68 bool early_exit_requested_; 56 bool early_exit_requested_;
69 base::Lock early_exit_requested_lock_; 57 base::Lock early_exit_requested_lock_;
70 58
71 friend class SyncerTest; 59 friend class SyncerTest;
72 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver); 60 FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver);
73 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates); 61 FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates);
74 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent); 62 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent);
75 FRIEND_TEST_ALL_PREFIXES(SyncerTest, 63 FRIEND_TEST_ALL_PREFIXES(SyncerTest,
76 TestCommitListOrderingAndNewParentAndChild); 64 TestCommitListOrderingAndNewParentAndChild);
77 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample); 65 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample);
78 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting); 66 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting);
79 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems); 67 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems);
80 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit); 68 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit);
81 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced); 69 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced);
82 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied); 70 FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied);
83 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit); 71 FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit);
84 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder); 72 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder);
85 FRIEND_TEST_ALL_PREFIXES(SyncerTest, 73 FRIEND_TEST_ALL_PREFIXES(SyncerTest,
86 LongChangelistCreatesFakeOrphanedEntries); 74 LongChangelistCreatesFakeOrphanedEntries);
87 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy); 75 FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy);
88 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict); 76 FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict);
89 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits); 77 FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits);
90 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest, 78 FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest,
91 EntryCreatedInNewFolderMidSync); 79 EntryCreatedInNewFolderMidSync);
92 80
93 DISALLOW_COPY_AND_ASSIGN(Syncer); 81 DISALLOW_COPY_AND_ASSIGN(Syncer);
94 }; 82 };
95 83
96 // Utility function declarations.
97 void CopyServerFields(syncable::Entry* src, syncable::MutableEntry* dest);
98 const char* SyncerStepToString(const SyncerStep);
99
100 } // namespace syncer 84 } // namespace syncer
101 85
102 #endif // SYNC_ENGINE_SYNCER_H_ 86 #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