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 |
36 std::string ObjectIdToString( | 62 std::string ObjectIdToString( |
37 const invalidation::ObjectId& object_id) { | 63 const invalidation::ObjectId& object_id) { |
38 std::stringstream ss; | 64 std::stringstream ss; |
39 ss << "{ "; | 65 ss << "{ "; |
40 ss << "name: " << object_id.name() << ", "; | 66 ss << "name: " << object_id.name() << ", "; |
41 ss << "source: " << object_id.source(); | 67 ss << "source: " << object_id.source(); |
42 ss << " }"; | 68 ss << " }"; |
43 return ss.str(); | 69 return ss.str(); |
44 } | 70 } |
45 | 71 |
46 std::string InvalidationToString( | 72 std::string InvalidationToString( |
47 const invalidation::Invalidation& invalidation) { | 73 const invalidation::Invalidation& invalidation) { |
48 std::stringstream ss; | 74 std::stringstream ss; |
49 ss << "{ "; | 75 ss << "{ "; |
50 ss << "object_id: " << ObjectIdToString(invalidation.object_id()) << ", "; | 76 ss << "object_id: " << ObjectIdToString(invalidation.object_id()) << ", "; |
51 ss << "version: " << invalidation.version(); | 77 ss << "version: " << invalidation.version(); |
52 ss << " }"; | 78 ss << " }"; |
53 return ss.str(); | 79 return ss.str(); |
54 } | 80 } |
55 | 81 |
56 } // namespace syncer | 82 } // namespace syncer |
OLD | NEW |