Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Side by Side Diff: sync/notifier/mock_ack_handler.cc

Issue 40303005: Add code for new invalidation local ack system (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another attempt at fixing win Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/notifier/mock_ack_handler.h ('k') | sync/sync_notifier.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 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/notifier/mock_ack_handler.h"
6
7 #include "sync/internal_api/public/base/ack_handle.h"
8 #include "sync/internal_api/public/base/invalidation.h"
9
10 namespace syncer {
11
12 namespace {
13
14 struct AckHandleMatcher {
15 AckHandleMatcher(const AckHandle& handle);
16 bool operator()(const syncer::Invalidation& invalidation) const;
17
18 syncer::AckHandle handle_;
19 };
20
21 AckHandleMatcher::AckHandleMatcher(const AckHandle& handle)
22 : handle_(handle) {}
23
24 bool AckHandleMatcher::operator()(
25 const syncer::Invalidation& invalidation) const {
26 return handle_.Equals(invalidation.ack_handle());
27 }
28
29 } // namespace
30
31 MockAckHandler::MockAckHandler() {}
32
33 MockAckHandler::~MockAckHandler() {}
34
35 void MockAckHandler::RegisterInvalidation(Invalidation* invalidation) {
36 unacked_invalidations_.push_back(*invalidation);
37 invalidation->set_ack_handler(WeakHandleThis());
38 }
39
40 void MockAckHandler::RegisterUnsentInvalidation(Invalidation* invalidation) {
41 unsent_invalidations_.push_back(*invalidation);
42 }
43
44 bool MockAckHandler::IsUnacked(const Invalidation& invalidation) const {
45 AckHandleMatcher matcher(invalidation.ack_handle());
46 InvalidationVector::const_iterator it = std::find_if(
47 unacked_invalidations_.begin(),
48 unacked_invalidations_.end(),
49 matcher);
50 return it != unacked_invalidations_.end();
51 }
52
53 bool MockAckHandler::IsUnsent(const Invalidation& invalidation) const {
54 AckHandleMatcher matcher(invalidation.ack_handle());
55 InvalidationVector::const_iterator it1 = std::find_if(
56 unsent_invalidations_.begin(),
57 unsent_invalidations_.end(),
58 matcher);
59 return it1 != unsent_invalidations_.end();
60 }
61
62 void MockAckHandler::Acknowledge(
63 const invalidation::ObjectId& id,
64 const AckHandle& handle) {
65 AckHandleMatcher matcher(handle);
66 InvalidationVector::iterator it = std::find_if(
67 unacked_invalidations_.begin(),
68 unacked_invalidations_.end(),
69 matcher);
70 if (it != unacked_invalidations_.end()) {
71 acked_invalidations_.push_back(*it);
72 unacked_invalidations_.erase(it);
73 }
74 }
75
76 void MockAckHandler::Drop(
77 const invalidation::ObjectId& id,
78 const AckHandle& handle) {
79 }
80
81 WeakHandle<AckHandler> MockAckHandler::WeakHandleThis() {
82 return WeakHandle<AckHandler>(AsWeakPtr());
83 }
84
85 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/mock_ack_handler.h ('k') | sync/sync_notifier.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698