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

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

Issue 11415049: Implement features needed for local ack handling in InvalidationStateTracker. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ...... Created 8 years 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
OLDNEW
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 #include "sync/notifier/fake_invalidation_state_tracker.h" 5 #include "sync/notifier/fake_invalidation_state_tracker.h"
6 6
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "base/location.h"
10 #include "base/task_runner.h"
7 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
8 12
9 namespace syncer { 13 namespace syncer {
10 14
11 const int64 FakeInvalidationStateTracker::kMinVersion = kint64min; 15 const int64 FakeInvalidationStateTracker::kMinVersion = kint64min;
12 16
13 FakeInvalidationStateTracker::FakeInvalidationStateTracker() {} 17 FakeInvalidationStateTracker::FakeInvalidationStateTracker() {}
14 18
15 FakeInvalidationStateTracker::~FakeInvalidationStateTracker() {} 19 FakeInvalidationStateTracker::~FakeInvalidationStateTracker() {}
16 20
17 int64 FakeInvalidationStateTracker::GetMaxVersion( 21 int64 FakeInvalidationStateTracker::GetMaxVersion(
18 const invalidation::ObjectId& id) const { 22 const invalidation::ObjectId& id) const {
19 InvalidationStateMap::const_iterator it = state_map_.find(id); 23 InvalidationStateMap::const_iterator it = state_map_.find(id);
20 return (it == state_map_.end()) ? kMinVersion : it->second.version; 24 return (it == state_map_.end()) ? kMinVersion : it->second.version;
21 } 25 }
22 26
23 InvalidationStateMap 27 InvalidationStateMap
24 FakeInvalidationStateTracker::GetAllInvalidationStates() const { 28 FakeInvalidationStateTracker::GetAllInvalidationStates() const {
25 return state_map_; 29 return state_map_;
26 } 30 }
27 31
28 void FakeInvalidationStateTracker::SetMaxVersion( 32 void FakeInvalidationStateTracker::SetMaxVersionAndPayload(
29 const invalidation::ObjectId& id, int64 max_version) { 33 const invalidation::ObjectId& id,
34 int64 max_version,
35 const std::string& payload) {
30 InvalidationStateMap::const_iterator it = state_map_.find(id); 36 InvalidationStateMap::const_iterator it = state_map_.find(id);
31 if ((it != state_map_.end()) && (max_version <= it->second.version)) { 37 if ((it != state_map_.end()) && (max_version <= it->second.version)) {
32 ADD_FAILURE(); 38 ADD_FAILURE();
33 return; 39 return;
34 } 40 }
35 state_map_[id].version = max_version; 41 state_map_[id].version = max_version;
36 } 42 }
37 43
38 void FakeInvalidationStateTracker::Forget(const ObjectIdSet& ids) { 44 void FakeInvalidationStateTracker::Forget(const ObjectIdSet& ids) {
39 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { 45 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) {
40 state_map_.erase(*it); 46 state_map_.erase(*it);
41 } 47 }
42 } 48 }
43 49
44 void FakeInvalidationStateTracker::SetBootstrapData( 50 void FakeInvalidationStateTracker::SetBootstrapData(
45 const std::string& data) { 51 const std::string& data) {
46 bootstrap_data_ = data; 52 bootstrap_data_ = data;
47 } 53 }
48 54
49 std::string FakeInvalidationStateTracker::GetBootstrapData() const { 55 std::string FakeInvalidationStateTracker::GetBootstrapData() const {
50 return bootstrap_data_; 56 return bootstrap_data_;
51 } 57 }
52 58
59 void FakeInvalidationStateTracker::GenerateAckHandles(
60 const ObjectIdSet& ids,
61 const scoped_refptr<base::TaskRunner>& task_runner,
62 base::Callback<void(const AckHandleMap&)> callback) {
63 AckHandleMap ack_handles;
64 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) {
65 state_map_[*it].expected = AckHandle::CreateUnique();
66 ack_handles.insert(std::make_pair(*it, state_map_[*it].expected));
67 }
68 if (!task_runner->PostTask(FROM_HERE, base::Bind(callback, ack_handles)))
69 ADD_FAILURE();
70 }
71
72 void FakeInvalidationStateTracker::Acknowledge(const invalidation::ObjectId& id,
73 const AckHandle& ack_handle) {
74 InvalidationStateMap::iterator it = state_map_.find(id);
75 if (it == state_map_.end())
76 ADD_FAILURE();
77 it->second.current = ack_handle;
78 }
79
53 } // namespace syncer 80 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/fake_invalidation_state_tracker.h ('k') | sync/notifier/invalidation_state_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698