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