OLD | NEW |
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/invalidation_util.h" | 5 #include "sync/notifier/invalidation_util.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "google/cacheinvalidation/include/types.h" | 9 #include "google/cacheinvalidation/include/types.h" |
10 #include "google/cacheinvalidation/v2/types.pb.h" | 10 #include "google/cacheinvalidation/v2/types.pb.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 object_id->Init(ipc::invalidation::ObjectSource::CHROME_SYNC, | 26 object_id->Init(ipc::invalidation::ObjectSource::CHROME_SYNC, |
27 notification_type); | 27 notification_type); |
28 return true; | 28 return true; |
29 } | 29 } |
30 | 30 |
31 bool ObjectIdToRealModelType(const invalidation::ObjectId& object_id, | 31 bool ObjectIdToRealModelType(const invalidation::ObjectId& object_id, |
32 ModelType* model_type) { | 32 ModelType* model_type) { |
33 return NotificationTypeToRealModelType(object_id.name(), model_type); | 33 return NotificationTypeToRealModelType(object_id.name(), model_type); |
34 } | 34 } |
35 | 35 |
36 ObjectIdSet ModelTypeSetToObjectIdSet(const ModelTypeSet& model_types) { | |
37 ObjectIdSet ids; | |
38 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { | |
39 invalidation::ObjectId model_type_as_id; | |
40 if (!RealModelTypeToObjectId(it.Get(), &model_type_as_id)) { | |
41 DLOG(WARNING) << "Invalid model type " << it.Get(); | |
42 continue; | |
43 } | |
44 ids.insert(model_type_as_id); | |
45 } | |
46 return ids; | |
47 } | |
48 | |
49 ModelTypeSet ObjectIdSetToModelTypeSet(const ObjectIdSet& ids) { | |
50 ModelTypeSet model_types; | |
51 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { | |
52 ModelType model_type; | |
53 if (!ObjectIdToRealModelType(*it, &model_type)) { | |
54 DLOG(WARNING) << "Invalid object ID " << ObjectIdToString(*it); | |
55 continue; | |
56 } | |
57 model_types.Put(model_type); | |
58 } | |
59 return model_types; | |
60 } | |
61 | |
62 std::string ObjectIdToString( | 36 std::string ObjectIdToString( |
63 const invalidation::ObjectId& object_id) { | 37 const invalidation::ObjectId& object_id) { |
64 std::stringstream ss; | 38 std::stringstream ss; |
65 ss << "{ "; | 39 ss << "{ "; |
66 ss << "name: " << object_id.name() << ", "; | 40 ss << "name: " << object_id.name() << ", "; |
67 ss << "source: " << object_id.source(); | 41 ss << "source: " << object_id.source(); |
68 ss << " }"; | 42 ss << " }"; |
69 return ss.str(); | 43 return ss.str(); |
70 } | 44 } |
71 | 45 |
72 std::string InvalidationToString( | 46 std::string InvalidationToString( |
73 const invalidation::Invalidation& invalidation) { | 47 const invalidation::Invalidation& invalidation) { |
74 std::stringstream ss; | 48 std::stringstream ss; |
75 ss << "{ "; | 49 ss << "{ "; |
76 ss << "object_id: " << ObjectIdToString(invalidation.object_id()) << ", "; | 50 ss << "object_id: " << ObjectIdToString(invalidation.object_id()) << ", "; |
77 ss << "version: " << invalidation.version(); | 51 ss << "version: " << invalidation.version(); |
78 ss << " }"; | 52 ss << " }"; |
79 return ss.str(); | 53 return ss.str(); |
80 } | 54 } |
81 | 55 |
82 } // namespace syncer | 56 } // namespace syncer |
OLD | NEW |