Home | History | Annotate | Download | only in engine
      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 // An UpdateApplicator is used to iterate over a number of unapplied updates,
      6 // applying them to the client using the given syncer session.
      7 //
      8 // UpdateApplicator might resemble an iterator, but it actually keeps retrying
      9 // failed updates until no remaining updates can be successfully applied.
     10 
     11 #ifndef SYNC_ENGINE_UPDATE_APPLICATOR_H_
     12 #define SYNC_ENGINE_UPDATE_APPLICATOR_H_
     13 
     14 #include <vector>
     15 
     16 #include "base/basictypes.h"
     17 #include "base/port.h"
     18 #include "sync/internal_api/public/engine/model_safe_worker.h"
     19 #include "sync/syncable/syncable_id.h"
     20 #include "sync/sessions/status_controller.h"
     21 
     22 namespace syncer {
     23 
     24 namespace sessions {
     25 class StatusController;
     26 }
     27 
     28 namespace syncable {
     29 class WriteTransaction;
     30 class Entry;
     31 }
     32 
     33 class ConflictResolver;
     34 class Cryptographer;
     35 
     36 class UpdateApplicator {
     37  public:
     38   UpdateApplicator(Cryptographer* cryptographer,
     39                    const ModelSafeRoutingInfo& routes,
     40                    ModelSafeGroup group_filter);
     41   ~UpdateApplicator();
     42 
     43   // Attempt to apply the specified updates.
     44   void AttemptApplications(syncable::WriteTransaction* trans,
     45                            const std::vector<int64>& handles);
     46 
     47   int updates_applied() {
     48     return updates_applied_;
     49   }
     50 
     51   int encryption_conflicts() {
     52     return encryption_conflicts_;
     53   }
     54 
     55   int hierarchy_conflicts() {
     56     return hierarchy_conflicts_;
     57   }
     58 
     59   const std::set<syncable::Id>& simple_conflict_ids() {
     60     return simple_conflict_ids_;
     61   }
     62 
     63  private:
     64   // If true, AttemptOneApplication will skip over |entry| and return true.
     65   bool SkipUpdate(const syncable::Entry& entry);
     66 
     67   // Used to decrypt sensitive sync nodes.
     68   Cryptographer* cryptographer_;
     69 
     70   ModelSafeGroup group_filter_;
     71 
     72   const ModelSafeRoutingInfo routing_info_;
     73 
     74   DISALLOW_COPY_AND_ASSIGN(UpdateApplicator);
     75 
     76   int updates_applied_;
     77   int encryption_conflicts_;
     78   int hierarchy_conflicts_;
     79   std::set<syncable::Id> simple_conflict_ids_;
     80 };
     81 
     82 }  // namespace syncer
     83 
     84 #endif  // SYNC_ENGINE_UPDATE_APPLICATOR_H_
     85