1 // Copyright (c) 2010 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. 4 5 #include "chrome/browser/sync/notifier/invalidation_util.h" 6 7 #include <sstream> 8 9 namespace sync_notifier { 10 11 void RunAndDeleteClosure(invalidation::Closure* task) { 12 task->Run(); 13 delete task; 14 } 15 16 bool RealModelTypeToObjectId(syncable::ModelType model_type, 17 invalidation::ObjectId* object_id) { 18 std::string notification_type; 19 if (!syncable::RealModelTypeToNotificationType( 20 model_type, ¬ification_type)) { 21 return false; 22 } 23 object_id->Init(invalidation::ObjectSource::CHROME_SYNC, notification_type); 24 return true; 25 } 26 27 bool ObjectIdToRealModelType(const invalidation::ObjectId& object_id, 28 syncable::ModelType* model_type) { 29 return 30 syncable::NotificationTypeToRealModelType( 31 object_id.name(), model_type); 32 } 33 34 std::string ObjectIdToString( 35 const invalidation::ObjectId& object_id) { 36 std::stringstream ss; 37 ss << "{ "; 38 ss << "name: " << object_id.name() << ", "; 39 ss << "source: " << object_id.source(); 40 ss << " }"; 41 return ss.str(); 42 } 43 44 std::string ObjectIdPToString( 45 const invalidation::ObjectIdP& object_id) { 46 return ObjectIdToString( 47 invalidation::ObjectId( 48 (invalidation::ObjectSource_Type) object_id.source(), 49 object_id.name().string_value())); 50 } 51 52 std::string StatusToString( 53 const invalidation::Status& status) { 54 std::stringstream ss; 55 ss << "{ "; 56 ss << "code: " << status.code() << ", "; 57 ss << "description: " << status.description(); 58 ss << " }"; 59 return ss.str(); 60 } 61 62 std::string InvalidationToString( 63 const invalidation::Invalidation& invalidation) { 64 std::stringstream ss; 65 ss << "{ "; 66 ss << "object_id: " << ObjectIdToString(invalidation.object_id()) << ", "; 67 ss << "version: " << invalidation.version(); 68 ss << " }"; 69 return ss.str(); 70 } 71 72 std::string RegistrationUpdateToString( 73 const invalidation::RegistrationUpdate& update) { 74 std::stringstream ss; 75 ss << "{ "; 76 ss << "type: " << update.type() << ", "; 77 ss << "object_id: " << ObjectIdPToString(update.object_id()) << ", "; 78 ss << "version: " << update.version() << ", "; 79 ss << "sequence_number: " << update.sequence_number(); 80 ss << " }"; 81 return ss.str(); 82 } 83 84 std::string RegistrationUpdateResultToString( 85 const invalidation::RegistrationUpdateResult& update_result) { 86 std::stringstream ss; 87 ss << "{ "; 88 ss << "operation: " 89 << RegistrationUpdateToString(update_result.operation()) << ", "; 90 ss << "status: " << StatusToString(update_result.status()); 91 ss << " }"; 92 return ss.str(); 93 } 94 95 } // namespace sync_notifier 96