| 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 // An UpdateApplicator is used to iterate over a number of unapplied updates, |    5 // An UpdateApplicator is used to iterate over a number of unapplied updates, | 
|    6 // applying them to the client using the given syncer session. |    6 // applying them to the client using the given syncer session. | 
|    7 // |    7 // | 
|    8 // UpdateApplicator might resemble an iterator, but it actually keeps retrying |    8 // UpdateApplicator might resemble an iterator, but it actually keeps retrying | 
|    9 // failed updates until no remaining updates can be successfully applied. |    9 // failed updates until no remaining updates can be successfully applied. | 
|   10  |   10  | 
|   11 #ifndef SYNC_ENGINE_UPDATE_APPLICATOR_H_ |   11 #ifndef SYNC_ENGINE_UPDATE_APPLICATOR_H_ | 
|   12 #define SYNC_ENGINE_UPDATE_APPLICATOR_H_ |   12 #define SYNC_ENGINE_UPDATE_APPLICATOR_H_ | 
|   13  |   13  | 
|   14 #include <vector> |   14 #include <vector> | 
|   15  |   15  | 
|   16 #include "base/basictypes.h" |   16 #include "base/basictypes.h" | 
|   17 #include "base/port.h" |   17 #include "base/port.h" | 
|   18 #include "sync/internal_api/public/engine/model_safe_worker.h" |   18 #include "sync/internal_api/public/engine/model_safe_worker.h" | 
|   19 #include "sync/syncable/syncable_id.h" |   19 #include "sync/syncable/syncable_id.h" | 
|   20 #include "sync/sessions/status_controller.h" |   20 #include "sync/sessions/status_controller.h" | 
|   21  |   21  | 
|   22 namespace syncer { |   22 namespace syncer { | 
|   23  |   23  | 
|   24 namespace sessions { |   24 namespace sessions { | 
|   25 class StatusController; |   25 class StatusController; | 
|   26 class UpdateProgress; |  | 
|   27 } |   26 } | 
|   28  |   27  | 
|   29 namespace syncable { |   28 namespace syncable { | 
|   30 class WriteTransaction; |   29 class WriteTransaction; | 
|   31 class Entry; |   30 class Entry; | 
|   32 } |   31 } | 
|   33  |   32  | 
|   34 class ConflictResolver; |   33 class ConflictResolver; | 
|   35 class Cryptographer; |   34 class Cryptographer; | 
|   36  |   35  | 
|   37 class UpdateApplicator { |   36 class UpdateApplicator { | 
|   38  public: |   37  public: | 
|   39   typedef std::vector<int64>::iterator UpdateIterator; |   38   typedef std::vector<int64>::iterator UpdateIterator; | 
|   40  |   39  | 
|   41   UpdateApplicator(Cryptographer* cryptographer, |   40   UpdateApplicator(Cryptographer* cryptographer, | 
|   42                    const ModelSafeRoutingInfo& routes, |   41                    const ModelSafeRoutingInfo& routes, | 
|   43                    ModelSafeGroup group_filter); |   42                    ModelSafeGroup group_filter); | 
|   44   ~UpdateApplicator(); |   43   ~UpdateApplicator(); | 
|   45  |   44  | 
|   46   // Attempt to apply the specified updates. |   45   // Attempt to apply the specified updates. | 
|   47   void AttemptApplications(syncable::WriteTransaction* trans, |   46   void AttemptApplications(syncable::WriteTransaction* trans, | 
|   48                            const std::vector<int64>& handles, |   47                            const std::vector<int64>& handles, | 
|   49                            sessions::StatusController* status); |   48                            sessions::StatusController* status); | 
|   50  |   49  | 
|   51   // This class does not automatically save its progress into the |  | 
|   52   // SyncSession -- to get that to happen, call this method after update |  | 
|   53   // application is finished (i.e., when AttemptOneAllocation stops returning |  | 
|   54   // true). |  | 
|   55   void SaveProgressIntoSessionState( |  | 
|   56       std::set<syncable::Id>* simple_conflict_ids, |  | 
|   57       sessions::UpdateProgress* update_progress); |  | 
|   58  |  | 
|   59  private: |   50  private: | 
|   60   // Track the status of all applications. |  | 
|   61   class ResultTracker { |  | 
|   62    public: |  | 
|   63      explicit ResultTracker(); |  | 
|   64      virtual ~ResultTracker(); |  | 
|   65      void AddSimpleConflict(syncable::Id); |  | 
|   66      void AddEncryptionConflict(syncable::Id); |  | 
|   67      void AddHierarchyConflict(syncable::Id); |  | 
|   68      void AddSuccess(syncable::Id); |  | 
|   69      void SaveProgress(std::set<syncable::Id>* simple_conflict_ids, |  | 
|   70                        sessions::UpdateProgress* update_progress); |  | 
|   71      void ClearHierarchyConflicts(); |  | 
|   72  |  | 
|   73      // Returns true iff conflicting_ids_ is empty. Does not check |  | 
|   74      // encryption_conflict_ids_. |  | 
|   75      bool no_conflicts() const; |  | 
|   76    private: |  | 
|   77     std::set<syncable::Id> conflicting_ids_; |  | 
|   78     std::set<syncable::Id> successful_ids_; |  | 
|   79     std::set<syncable::Id> encryption_conflict_ids_; |  | 
|   80     std::set<syncable::Id> hierarchy_conflict_ids_; |  | 
|   81   }; |  | 
|   82  |  | 
|   83   // If true, AttemptOneApplication will skip over |entry| and return true. |   51   // If true, AttemptOneApplication will skip over |entry| and return true. | 
|   84   bool SkipUpdate(const syncable::Entry& entry); |   52   bool SkipUpdate(const syncable::Entry& entry); | 
|   85  |   53  | 
|   86   // Used to decrypt sensitive sync nodes. |   54   // Used to decrypt sensitive sync nodes. | 
|   87   Cryptographer* cryptographer_; |   55   Cryptographer* cryptographer_; | 
|   88  |   56  | 
|   89   ModelSafeGroup group_filter_; |   57   ModelSafeGroup group_filter_; | 
|   90  |   58  | 
|   91   const ModelSafeRoutingInfo routing_info_; |   59   const ModelSafeRoutingInfo routing_info_; | 
|   92  |   60  | 
|   93   // Track the result of the attempts to update applications. |  | 
|   94   ResultTracker application_results_; |  | 
|   95  |  | 
|   96   DISALLOW_COPY_AND_ASSIGN(UpdateApplicator); |   61   DISALLOW_COPY_AND_ASSIGN(UpdateApplicator); | 
|   97 }; |   62 }; | 
|   98  |   63  | 
|   99 }  // namespace syncer |   64 }  // namespace syncer | 
|  100  |   65  | 
|  101 #endif  // SYNC_ENGINE_UPDATE_APPLICATOR_H_ |   66 #endif  // SYNC_ENGINE_UPDATE_APPLICATOR_H_ | 
| OLD | NEW |