1 // Copyright 2014 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 #include "sync/test/mock_invalidation_tracker.h" 6 7 #include "base/logging.h" 8 #include "sync/test/trackable_mock_invalidation.h" 9 10 namespace syncer { 11 12 scoped_ptr<TrackableMockInvalidation> 13 MockInvalidationTracker::IssueUnknownVersionInvalidation() { 14 return scoped_ptr<TrackableMockInvalidation>( 15 new TrackableMockInvalidation(true, -1, std::string(), this, next_id_++)); 16 } 17 18 scoped_ptr<TrackableMockInvalidation> 19 MockInvalidationTracker::IssueInvalidation(int64 version, 20 const std::string& payload) { 21 return scoped_ptr<TrackableMockInvalidation>( 22 new TrackableMockInvalidation(false, version, payload, this, next_id_++)); 23 } 24 25 MockInvalidationTracker::MockInvalidationTracker() : next_id_(0) { 26 } 27 28 MockInvalidationTracker::~MockInvalidationTracker() { 29 } 30 31 void MockInvalidationTracker::Acknowledge(int invalidation_id) { 32 acknowledged_.insert(invalidation_id); 33 } 34 35 void MockInvalidationTracker::Drop(int invalidation_id) { 36 dropped_.insert(invalidation_id); 37 } 38 39 bool MockInvalidationTracker::IsUnacked(int invalidation_id) const { 40 DCHECK_LE(invalidation_id, next_id_); 41 return !IsAcknowledged(invalidation_id) && !IsDropped(invalidation_id); 42 } 43 44 bool MockInvalidationTracker::IsAcknowledged(int invalidation_id) const { 45 DCHECK_LE(invalidation_id, next_id_); 46 return acknowledged_.find(invalidation_id) != acknowledged_.end(); 47 } 48 49 bool MockInvalidationTracker::IsDropped(int invalidation_id) const { 50 DCHECK_LE(invalidation_id, next_id_); 51 return dropped_.find(invalidation_id) != dropped_.end(); 52 } 53 54 bool MockInvalidationTracker::AllInvalidationsAccountedFor() const { 55 for (int i = 0; i < next_id_; ++i) { 56 if (IsUnacked(i)) { 57 return false; 58 } 59 } 60 return true; 61 } 62 63 } // namespace syncer 64