| OLD | NEW | 
|---|
|  | (Empty) | 
| 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. |  | 
| 4 |  | 
| 5 #ifndef SYNC_ENGINE_SYNCER_H_ |  | 
| 6 #define SYNC_ENGINE_SYNCER_H_ |  | 
| 7 |  | 
| 8 #include <stdint.h> |  | 
| 9 |  | 
| 10 #include <utility> |  | 
| 11 #include <vector> |  | 
| 12 |  | 
| 13 #include "base/callback.h" |  | 
| 14 #include "base/gtest_prod_util.h" |  | 
| 15 #include "base/macros.h" |  | 
| 16 #include "base/synchronization/lock.h" |  | 
| 17 #include "sync/base/sync_export.h" |  | 
| 18 #include "sync/engine/conflict_resolver.h" |  | 
| 19 #include "sync/engine/syncer_types.h" |  | 
| 20 #include "sync/internal_api/public/base/model_type.h" |  | 
| 21 #include "sync/sessions/sync_session.h" |  | 
| 22 #include "sync/util/extensions_activity.h" |  | 
| 23 |  | 
| 24 namespace syncer { |  | 
| 25 |  | 
| 26 class CancelationSignal; |  | 
| 27 class CommitProcessor; |  | 
| 28 class GetUpdatesProcessor; |  | 
| 29 |  | 
| 30 // A Syncer provides a control interface for driving the sync cycle.  These |  | 
| 31 // cycles consist of downloading updates, parsing the response (aka. process |  | 
| 32 // updates), applying updates while resolving conflicts, and committing local |  | 
| 33 // changes.  Some of these steps may be skipped if they're deemed to be |  | 
| 34 // unnecessary. |  | 
| 35 // |  | 
| 36 // A Syncer instance expects to run on a dedicated thread.  Calls to SyncShare() |  | 
| 37 // may take an unbounded amount of time because it may block on network I/O, on |  | 
| 38 // lock contention, or on tasks posted to other threads. |  | 
| 39 class SYNC_EXPORT Syncer { |  | 
| 40  public: |  | 
| 41   typedef std::vector<int64_t> UnsyncedMetaHandles; |  | 
| 42 |  | 
| 43   explicit Syncer(CancelationSignal* cancelation_signal); |  | 
| 44   virtual ~Syncer(); |  | 
| 45 |  | 
| 46   // Whether an early exist was requested due to a cancelation signal. |  | 
| 47   bool ExitRequested(); |  | 
| 48 |  | 
| 49   // Whether the syncer is in the middle of a sync cycle. |  | 
| 50   bool IsSyncing() const; |  | 
| 51 |  | 
| 52   // Fetches and applies updates, resolves conflicts and commits local changes |  | 
| 53   // for |request_types| as necessary until client and server states are in |  | 
| 54   // sync.  The |nudge_tracker| contains state that describes why the client is |  | 
| 55   // out of sync and what must be done to bring it back into sync. |  | 
| 56   // Returns: false if an error occurred and retries should backoff, true |  | 
| 57   // otherwise. |  | 
| 58   virtual bool NormalSyncShare(ModelTypeSet request_types, |  | 
| 59                                sessions::NudgeTracker* nudge_tracker, |  | 
| 60                                sessions::SyncSession* session); |  | 
| 61 |  | 
| 62   // Performs an initial download for the |request_types|.  It is assumed that |  | 
| 63   // the specified types have no local state, and that their associated change |  | 
| 64   // processors are in "passive" mode, so none of the downloaded updates will be |  | 
| 65   // applied to the model.  The |source| is sent up to the server for debug |  | 
| 66   // purposes.  It describes the reson for performing this initial download. |  | 
| 67   // Returns: false if an error occurred and retries should backoff, true |  | 
| 68   // otherwise. |  | 
| 69   virtual bool ConfigureSyncShare( |  | 
| 70       ModelTypeSet request_types, |  | 
| 71       sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, |  | 
| 72       sessions::SyncSession* session); |  | 
| 73 |  | 
| 74   // Requests to download updates for the |request_types|.  For a well-behaved |  | 
| 75   // client with a working connection to the invalidations server, this should |  | 
| 76   // be unnecessary.  It may be invoked periodically to try to keep the client |  | 
| 77   // in sync despite bugs or transient failures. |  | 
| 78   // Returns: false if an error occurred and retries should backoff, true |  | 
| 79   // otherwise. |  | 
| 80   virtual bool PollSyncShare(ModelTypeSet request_types, |  | 
| 81                              sessions::SyncSession* session); |  | 
| 82 |  | 
| 83   // Posts a ClearServerData command. |  | 
| 84   // Returns: false if an error occurred and retries should backoff, true |  | 
| 85   // otherwise. |  | 
| 86   virtual bool PostClearServerData(sessions::SyncSession* session); |  | 
| 87 |  | 
| 88  private: |  | 
| 89   friend class SyncerTest; |  | 
| 90   FRIEND_TEST_ALL_PREFIXES(SyncerTest, NameClashWithResolver); |  | 
| 91   FRIEND_TEST_ALL_PREFIXES(SyncerTest, IllegalAndLegalUpdates); |  | 
| 92   FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingAndNewParent); |  | 
| 93   FRIEND_TEST_ALL_PREFIXES(SyncerTest, |  | 
| 94                            TestCommitListOrderingAndNewParentAndChild); |  | 
| 95   FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingCounterexample); |  | 
| 96   FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNesting); |  | 
| 97   FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestCommitListOrderingWithNewItems); |  | 
| 98   FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestGetUnsyncedAndSimpleCommit); |  | 
| 99   FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnsynced); |  | 
| 100   FRIEND_TEST_ALL_PREFIXES(SyncerTest, TestPurgeWhileUnapplied); |  | 
| 101   FRIEND_TEST_ALL_PREFIXES(SyncerTest, UnappliedUpdateDuringCommit); |  | 
| 102   FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryInFolder); |  | 
| 103   FRIEND_TEST_ALL_PREFIXES(SyncerTest, |  | 
| 104                            LongChangelistCreatesFakeOrphanedEntries); |  | 
| 105   FRIEND_TEST_ALL_PREFIXES(SyncerTest, QuicklyMergeDualCreatedHierarchy); |  | 
| 106   FRIEND_TEST_ALL_PREFIXES(SyncerTest, LongChangelistWithApplicationConflict); |  | 
| 107   FRIEND_TEST_ALL_PREFIXES(SyncerTest, DeletingEntryWithLocalEdits); |  | 
| 108   FRIEND_TEST_ALL_PREFIXES(EntryCreatedInNewFolderTest, |  | 
| 109                            EntryCreatedInNewFolderMidSync); |  | 
| 110 |  | 
| 111   bool DownloadAndApplyUpdates( |  | 
| 112       ModelTypeSet* request_types, |  | 
| 113       sessions::SyncSession* session, |  | 
| 114       GetUpdatesProcessor* get_updates_processor, |  | 
| 115       bool create_mobile_bookmarks_folder); |  | 
| 116 |  | 
| 117   // This function will commit batches of unsynced items to the server until the |  | 
| 118   // number of unsynced and ready to commit items reaches zero or an error is |  | 
| 119   // encountered.  A request to exit early will be treated as an error and will |  | 
| 120   // abort any blocking operations. |  | 
| 121   SyncerError BuildAndPostCommits(ModelTypeSet request_types, |  | 
| 122                                   sessions::NudgeTracker* nudge_tracker, |  | 
| 123                                   sessions::SyncSession* session, |  | 
| 124                                   CommitProcessor* commit_processor); |  | 
| 125 |  | 
| 126   void HandleCycleBegin(sessions::SyncSession* session); |  | 
| 127   bool HandleCycleEnd( |  | 
| 128       sessions::SyncSession* session, |  | 
| 129       sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source); |  | 
| 130 |  | 
| 131   syncer::CancelationSignal* const cancelation_signal_; |  | 
| 132 |  | 
| 133   // Whether the syncer is in the middle of a sync attempt. |  | 
| 134   bool is_syncing_; |  | 
| 135 |  | 
| 136   DISALLOW_COPY_AND_ASSIGN(Syncer); |  | 
| 137 }; |  | 
| 138 |  | 
| 139 }  // namespace syncer |  | 
| 140 |  | 
| 141 #endif  // SYNC_ENGINE_SYNCER_H_ |  | 
| OLD | NEW | 
|---|