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
3 // found in the LICENSE file.
5 #include "sync/notifier/invalidation_util.h"
9 #include "google/cacheinvalidation/include/types.h"
10 #include "google/cacheinvalidation/types.pb.h"
14 bool ObjectIdLessThan::operator()(const invalidation::ObjectId
& lhs
,
15 const invalidation::ObjectId
& rhs
) const {
16 return (lhs
.source() < rhs
.source()) ||
17 (lhs
.source() == rhs
.source() && lhs
.name() < rhs
.name());
20 bool RealModelTypeToObjectId(ModelType model_type
,
21 invalidation::ObjectId
* object_id
) {
22 std::string notification_type
;
23 if (!RealModelTypeToNotificationType(model_type
, ¬ification_type
)) {
26 object_id
->Init(ipc::invalidation::ObjectSource::CHROME_SYNC
,
31 bool ObjectIdToRealModelType(const invalidation::ObjectId
& object_id
,
32 ModelType
* model_type
) {
33 return NotificationTypeToRealModelType(object_id
.name(), model_type
);
36 ObjectIdSet
ModelTypeSetToObjectIdSet(const ModelTypeSet
& model_types
) {
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();
44 ids
.insert(model_type_as_id
);
49 ModelTypeSet
ObjectIdSetToModelTypeSet(const ObjectIdSet
& ids
) {
50 ModelTypeSet model_types
;
51 for (ObjectIdSet::const_iterator it
= ids
.begin(); it
!= ids
.end(); ++it
) {
53 if (!ObjectIdToRealModelType(*it
, &model_type
)) {
54 DLOG(WARNING
) << "Invalid object ID " << ObjectIdToString(*it
);
57 model_types
.Put(model_type
);
62 std::string
ObjectIdToString(
63 const invalidation::ObjectId
& object_id
) {
66 ss
<< "name: " << object_id
.name() << ", ";
67 ss
<< "source: " << object_id
.source();
72 std::string
InvalidationToString(
73 const invalidation::Invalidation
& invalidation
) {
76 ss
<< "object_id: " << ObjectIdToString(invalidation
.object_id()) << ", ";
77 ss
<< "version: " << invalidation
.version();