| OLD | NEW | 
|   1 // Copyright 2012 The Chromium Authors. All rights reserved. |   1 // Copyright 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 #include "sync/engine/update_applicator.h" |   5 #include "components/sync/engine_impl/update_applicator.h" | 
|   6  |   6  | 
|   7 #include <stdint.h> |   7 #include <stdint.h> | 
|   8  |   8  | 
|   9 #include <vector> |   9 #include <vector> | 
|  10  |  10  | 
|  11 #include "base/logging.h" |  11 #include "base/logging.h" | 
|  12 #include "sync/engine/syncer_util.h" |  12 #include "components/sync/engine_impl/syncer_util.h" | 
|  13 #include "sync/syncable/entry.h" |  13 #include "components/sync/syncable/entry.h" | 
|  14 #include "sync/syncable/mutable_entry.h" |  14 #include "components/sync/syncable/mutable_entry.h" | 
|  15 #include "sync/syncable/syncable_id.h" |  15 #include "components/sync/syncable/syncable_id.h" | 
|  16 #include "sync/syncable/syncable_write_transaction.h" |  16 #include "components/sync/syncable/syncable_write_transaction.h" | 
|  17  |  17  | 
|  18 using std::vector; |  18 using std::vector; | 
|  19  |  19  | 
|  20 namespace syncer { |  20 namespace syncer { | 
|  21  |  21  | 
|  22 using syncable::ID; |  22 using syncable::ID; | 
|  23  |  23  | 
|  24 UpdateApplicator::UpdateApplicator(Cryptographer* cryptographer) |  24 UpdateApplicator::UpdateApplicator(Cryptographer* cryptographer) | 
|  25     : cryptographer_(cryptographer), |  25     : cryptographer_(cryptographer), | 
|  26       updates_applied_(0), |  26       updates_applied_(0), | 
|  27       encryption_conflicts_(0), |  27       encryption_conflicts_(0), | 
|  28       hierarchy_conflicts_(0) { |  28       hierarchy_conflicts_(0) {} | 
|  29 } |  | 
|  30  |  29  | 
|  31 UpdateApplicator::~UpdateApplicator() { |  30 UpdateApplicator::~UpdateApplicator() {} | 
|  32 } |  | 
|  33  |  31  | 
|  34 // Attempt to apply all updates, using multiple passes if necessary. |  32 // Attempt to apply all updates, using multiple passes if necessary. | 
|  35 // |  33 // | 
|  36 // Some updates must be applied in order.  For example, children must be created |  34 // Some updates must be applied in order.  For example, children must be created | 
|  37 // after their parent folder is created.  This function runs an O(n^2) algorithm |  35 // after their parent folder is created.  This function runs an O(n^2) algorithm | 
|  38 // that will keep trying until there is nothing left to apply, or it stops |  36 // that will keep trying until there is nothing left to apply, or it stops | 
|  39 // making progress, which would indicate that the hierarchy is invalid. |  37 // making progress, which would indicate that the hierarchy is invalid. | 
|  40 // |  38 // | 
|  41 // The update applicator also has to deal with simple conflicts, which occur |  39 // The update applicator also has to deal with simple conflicts, which occur | 
|  42 // when an item is modified on both the server and the local model.  We remember |  40 // when an item is modified on both the server and the local model.  We remember | 
|  43 // their IDs so they can be passed to the conflict resolver after all the other |  41 // their IDs so they can be passed to the conflict resolver after all the other | 
|  44 // applications are complete. |  42 // applications are complete. | 
|  45 // |  43 // | 
|  46 // Finally, there are encryption conflicts, which can occur when we don't have |  44 // Finally, there are encryption conflicts, which can occur when we don't have | 
|  47 // access to all the Nigori keys.  There's nothing we can do about them here. |  45 // access to all the Nigori keys.  There's nothing we can do about them here. | 
|  48 void UpdateApplicator::AttemptApplications( |  46 void UpdateApplicator::AttemptApplications( | 
|  49     syncable::WriteTransaction* trans, |  47     syncable::WriteTransaction* trans, | 
|  50     const std::vector<int64_t>& handles) { |  48     const std::vector<int64_t>& handles) { | 
|  51   std::vector<int64_t> to_apply = handles; |  49   std::vector<int64_t> to_apply = handles; | 
|  52  |  50  | 
|  53   DVLOG(1) << "UpdateApplicator running over " << to_apply.size() << " items."; |  51   DVLOG(1) << "UpdateApplicator running over " << to_apply.size() << " items."; | 
|  54   while (!to_apply.empty()) { |  52   while (!to_apply.empty()) { | 
|  55     std::vector<int64_t> to_reapply; |  53     std::vector<int64_t> to_reapply; | 
|  56  |  54  | 
|  57     for (std::vector<int64_t>::iterator i = to_apply.begin(); |  55     for (std::vector<int64_t>::iterator i = to_apply.begin(); | 
|  58          i != to_apply.end(); ++i) { |  56          i != to_apply.end(); ++i) { | 
|  59       syncable::MutableEntry entry(trans, syncable::GET_BY_HANDLE, *i); |  57       syncable::MutableEntry entry(trans, syncable::GET_BY_HANDLE, *i); | 
|  60       UpdateAttemptResponse result = AttemptToUpdateEntry( |  58       UpdateAttemptResponse result = | 
|  61           trans, &entry, cryptographer_); |  59           AttemptToUpdateEntry(trans, &entry, cryptographer_); | 
|  62  |  60  | 
|  63       switch (result) { |  61       switch (result) { | 
|  64         case SUCCESS: |  62         case SUCCESS: | 
|  65           updates_applied_++; |  63           updates_applied_++; | 
|  66           break; |  64           break; | 
|  67         case CONFLICT_SIMPLE: |  65         case CONFLICT_SIMPLE: | 
|  68           simple_conflict_ids_.insert(entry.GetId()); |  66           simple_conflict_ids_.insert(entry.GetId()); | 
|  69           break; |  67           break; | 
|  70         case CONFLICT_ENCRYPTION: |  68         case CONFLICT_ENCRYPTION: | 
|  71           encryption_conflicts_++; |  69           encryption_conflicts_++; | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
|  90  |  88  | 
|  91     // We made some progress, so prepare for what might be another iteration. |  89     // We made some progress, so prepare for what might be another iteration. | 
|  92     // If everything went well, to_reapply will be empty and we'll break out on |  90     // If everything went well, to_reapply will be empty and we'll break out on | 
|  93     // the while condition. |  91     // the while condition. | 
|  94     to_apply.swap(to_reapply); |  92     to_apply.swap(to_reapply); | 
|  95     to_reapply.clear(); |  93     to_reapply.clear(); | 
|  96   } |  94   } | 
|  97 } |  95 } | 
|  98  |  96  | 
|  99 }  // namespace syncer |  97 }  // namespace syncer | 
| OLD | NEW |