| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "components/invalidation/mock_ack_handler.h" | 5 #include "components/invalidation/mock_ack_handler.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop_proxy.h" |
| 7 #include "components/invalidation/ack_handle.h" | 8 #include "components/invalidation/ack_handle.h" |
| 8 #include "components/invalidation/invalidation.h" | 9 #include "components/invalidation/invalidation.h" |
| 9 | 10 |
| 10 namespace syncer { | 11 namespace syncer { |
| 11 | 12 |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 struct AckHandleMatcher { | 15 struct AckHandleMatcher { |
| 15 AckHandleMatcher(const AckHandle& handle); | 16 AckHandleMatcher(const AckHandle& handle); |
| 16 bool operator()(const syncer::Invalidation& invalidation) const; | 17 bool operator()(const syncer::Invalidation& invalidation) const; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 27 } | 28 } |
| 28 | 29 |
| 29 } // namespace | 30 } // namespace |
| 30 | 31 |
| 31 MockAckHandler::MockAckHandler() {} | 32 MockAckHandler::MockAckHandler() {} |
| 32 | 33 |
| 33 MockAckHandler::~MockAckHandler() {} | 34 MockAckHandler::~MockAckHandler() {} |
| 34 | 35 |
| 35 void MockAckHandler::RegisterInvalidation(Invalidation* invalidation) { | 36 void MockAckHandler::RegisterInvalidation(Invalidation* invalidation) { |
| 36 unacked_invalidations_.push_back(*invalidation); | 37 unacked_invalidations_.push_back(*invalidation); |
| 37 invalidation->set_ack_handler(WeakHandleThis()); | 38 invalidation->SetAckHandler(AsWeakPtr(), base::MessageLoopProxy::current()); |
| 38 } | 39 } |
| 39 | 40 |
| 40 void MockAckHandler::RegisterUnsentInvalidation(Invalidation* invalidation) { | 41 void MockAckHandler::RegisterUnsentInvalidation(Invalidation* invalidation) { |
| 41 unsent_invalidations_.push_back(*invalidation); | 42 unsent_invalidations_.push_back(*invalidation); |
| 42 } | 43 } |
| 43 | 44 |
| 44 bool MockAckHandler::IsUnacked(const Invalidation& invalidation) const { | 45 bool MockAckHandler::IsUnacked(const Invalidation& invalidation) const { |
| 45 AckHandleMatcher matcher(invalidation.ack_handle()); | 46 AckHandleMatcher matcher(invalidation.ack_handle()); |
| 46 InvalidationVector::const_iterator it = std::find_if( | 47 InvalidationVector::const_iterator it = std::find_if( |
| 47 unacked_invalidations_.begin(), | 48 unacked_invalidations_.begin(), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 unacked_invalidations_.end(), | 110 unacked_invalidations_.end(), |
| 110 matcher); | 111 matcher); |
| 111 if (it != unacked_invalidations_.end()) { | 112 if (it != unacked_invalidations_.end()) { |
| 112 dropped_invalidations_.push_back(*it); | 113 dropped_invalidations_.push_back(*it); |
| 113 unacked_invalidations_.erase(it); | 114 unacked_invalidations_.erase(it); |
| 114 } | 115 } |
| 115 unrecovered_drop_events_.erase(id); | 116 unrecovered_drop_events_.erase(id); |
| 116 unrecovered_drop_events_.insert(std::make_pair(id, handle)); | 117 unrecovered_drop_events_.insert(std::make_pair(id, handle)); |
| 117 } | 118 } |
| 118 | 119 |
| 119 WeakHandle<AckHandler> MockAckHandler::WeakHandleThis() { | |
| 120 return WeakHandle<AckHandler>(AsWeakPtr()); | |
| 121 } | |
| 122 | |
| 123 } // namespace syncer | 120 } // namespace syncer |
| OLD | NEW |