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

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

Issue 11052007: Rename ModelType/ObjectIdStateMap to InvalidationMap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 months 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/object_id_state_map.h" 5 #include "sync/notifier/object_id_invalidation_map.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 11
12 namespace syncer { 12 namespace syncer {
13 13
14 ObjectIdSet ObjectIdStateMapToSet(const ObjectIdStateMap& id_state_map) { 14 ObjectIdSet ObjectIdInvalidationMapToSet(
15 const ObjectIdInvalidationMap& invalidation_map) {
15 ObjectIdSet ids; 16 ObjectIdSet ids;
16 for (ObjectIdStateMap::const_iterator it = id_state_map.begin(); 17 for (ObjectIdInvalidationMap::const_iterator it = invalidation_map.begin();
17 it != id_state_map.end(); ++it) { 18 it != invalidation_map.end(); ++it) {
18 ids.insert(it->first); 19 ids.insert(it->first);
19 } 20 }
20 return ids; 21 return ids;
21 } 22 }
22 23
23 ObjectIdStateMap ObjectIdSetToStateMap(const ObjectIdSet& ids, 24 ObjectIdInvalidationMap ObjectIdSetToInvalidationMap(
24 const std::string& payload) { 25 const ObjectIdSet& ids, const std::string& payload) {
25 ObjectIdStateMap id_state_map; 26 ObjectIdInvalidationMap invalidation_map;
26 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { 27 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) {
27 // TODO(dcheng): Do we need to provide a way to set AckHandle? 28 // TODO(dcheng): Do we need to provide a way to set AckHandle?
28 id_state_map[*it].payload = payload; 29 invalidation_map[*it].payload = payload;
29 } 30 }
30 return id_state_map; 31 return invalidation_map;
31 } 32 }
32 33
33 namespace { 34 namespace {
34 35
35 struct ObjectIdStateMapValueEquals { 36 struct ObjectIdInvalidationMapValueEquals {
36 bool operator()(const ObjectIdStateMap::value_type& value1, 37 bool operator()(const ObjectIdInvalidationMap::value_type& value1,
37 const ObjectIdStateMap::value_type& value2) const { 38 const ObjectIdInvalidationMap::value_type& value2) const {
38 return 39 return
39 (value1.first == value2.first) && 40 (value1.first == value2.first) &&
40 value1.second.Equals(value2.second); 41 value1.second.Equals(value2.second);
41 } 42 }
42 }; 43 };
43 44
44 } // namespace 45 } // namespace
45 46
46 bool ObjectIdStateMapEquals(const ObjectIdStateMap& id_state_map1, 47 bool ObjectIdInvalidationMapEquals(
47 const ObjectIdStateMap& id_state_map2) { 48 const ObjectIdInvalidationMap& invalidation_map1,
49 const ObjectIdInvalidationMap& invalidation_map2) {
48 return 50 return
49 (id_state_map1.size() == id_state_map2.size()) && 51 (invalidation_map1.size() == invalidation_map2.size()) &&
50 std::equal(id_state_map1.begin(), id_state_map1.end(), 52 std::equal(invalidation_map1.begin(), invalidation_map1.end(),
51 id_state_map2.begin(), ObjectIdStateMapValueEquals()); 53 invalidation_map2.begin(),
54 ObjectIdInvalidationMapValueEquals());
52 } 55 }
53 56
54 scoped_ptr<base::ListValue> ObjectIdStateMapToValue( 57 scoped_ptr<base::ListValue> ObjectIdInvalidationMapToValue(
55 const ObjectIdStateMap& id_state_map) { 58 const ObjectIdInvalidationMap& invalidation_map) {
56 scoped_ptr<ListValue> value(new ListValue()); 59 scoped_ptr<ListValue> value(new ListValue());
57 for (ObjectIdStateMap::const_iterator it = id_state_map.begin(); 60 for (ObjectIdInvalidationMap::const_iterator it = invalidation_map.begin();
58 it != id_state_map.end(); ++it) { 61 it != invalidation_map.end(); ++it) {
59 DictionaryValue* entry = new DictionaryValue(); 62 DictionaryValue* entry = new DictionaryValue();
60 entry->Set("objectId", ObjectIdToValue(it->first).release()); 63 entry->Set("objectId", ObjectIdToValue(it->first).release());
61 entry->Set("state", it->second.ToValue().release()); 64 entry->Set("state", it->second.ToValue().release());
62 value->Append(entry); 65 value->Append(entry);
63 } 66 }
64 return value.Pass(); 67 return value.Pass();
65 } 68 }
66 69
67 bool ObjectIdStateMapFromValue(const base::ListValue& value, 70 bool ObjectIdInvalidationMapFromValue(const base::ListValue& value,
68 ObjectIdStateMap* out) { 71 ObjectIdInvalidationMap* out) {
69 out->clear(); 72 out->clear();
70 for (base::ListValue::const_iterator it = value.begin(); 73 for (base::ListValue::const_iterator it = value.begin();
71 it != value.end(); ++it) { 74 it != value.end(); ++it) {
72 const base::DictionaryValue* entry = NULL; 75 const base::DictionaryValue* entry = NULL;
73 const base::DictionaryValue* id_value = NULL; 76 const base::DictionaryValue* id_value = NULL;
74 const base::DictionaryValue* state_value = NULL; 77 const base::DictionaryValue* invalidation_value = NULL;
75 invalidation::ObjectId id; 78 invalidation::ObjectId id;
76 InvalidationState state; 79 Invalidation invalidation;
77 if (!(*it)->GetAsDictionary(&entry) || 80 if (!(*it)->GetAsDictionary(&entry) ||
78 !entry->GetDictionary("objectId", &id_value) || 81 !entry->GetDictionary("objectId", &id_value) ||
79 !entry->GetDictionary("state", &state_value) || 82 !entry->GetDictionary("state", &invalidation_value) ||
80 !ObjectIdFromValue(*id_value, &id) || 83 !ObjectIdFromValue(*id_value, &id) ||
81 !state.ResetFromValue(*state_value)) { 84 !invalidation.ResetFromValue(*invalidation_value)) {
82 return false; 85 return false;
83 } 86 }
84 ignore_result(out->insert(std::make_pair(id, state))); 87 ignore_result(out->insert(std::make_pair(id, invalidation)));
85 } 88 }
86 return true; 89 return true;
87 } 90 }
88 91
89 ModelTypeStateMap ObjectIdStateMapToModelTypeStateMap( 92 ModelTypeInvalidationMap ObjectIdInvalidationMapToModelTypeInvalidationMap(
90 const ObjectIdStateMap& id_state_map) { 93 const ObjectIdInvalidationMap& invalidation_map) {
91 ModelTypeStateMap type_state_map; 94 ModelTypeInvalidationMap type_invalidation_map;
92 for (ObjectIdStateMap::const_iterator it = id_state_map.begin(); 95 for (ObjectIdInvalidationMap::const_iterator it = invalidation_map.begin();
93 it != id_state_map.end(); ++it) { 96 it != invalidation_map.end(); ++it) {
94 ModelType model_type; 97 ModelType model_type;
95 if (!ObjectIdToRealModelType(it->first, &model_type)) { 98 if (!ObjectIdToRealModelType(it->first, &model_type)) {
96 DLOG(WARNING) << "Invalid object ID: " 99 DLOG(WARNING) << "Invalid object ID: "
97 << ObjectIdToString(it->first); 100 << ObjectIdToString(it->first);
98 continue; 101 continue;
99 } 102 }
100 type_state_map[model_type] = it->second; 103 type_invalidation_map[model_type] = it->second;
101 } 104 }
102 return type_state_map; 105 return type_invalidation_map;
103 } 106 }
104 107
105 ObjectIdStateMap ModelTypeStateMapToObjectIdStateMap( 108 ObjectIdInvalidationMap ModelTypeInvalidationMapToObjectIdInvalidationMap(
106 const ModelTypeStateMap& type_state_map) { 109 const ModelTypeInvalidationMap& invalidation_map) {
107 ObjectIdStateMap id_state_map; 110 ObjectIdInvalidationMap id_invalidation_map;
108 for (ModelTypeStateMap::const_iterator it = type_state_map.begin(); 111 for (ModelTypeInvalidationMap::const_iterator it = invalidation_map.begin();
109 it != type_state_map.end(); ++it) { 112 it != invalidation_map.end(); ++it) {
110 invalidation::ObjectId id; 113 invalidation::ObjectId id;
111 if (!RealModelTypeToObjectId(it->first, &id)) { 114 if (!RealModelTypeToObjectId(it->first, &id)) {
112 DLOG(WARNING) << "Invalid model type " << it->first; 115 DLOG(WARNING) << "Invalid model type " << it->first;
113 continue; 116 continue;
114 } 117 }
115 id_state_map[id] = it->second; 118 id_invalidation_map[id] = it->second;
116 } 119 }
117 return id_state_map; 120 return id_invalidation_map;
118 } 121 }
119 122
120 } // namespace syncer 123 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/notifier/object_id_invalidation_map.h ('k') | sync/notifier/object_id_invalidation_map_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698