| 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/internal_api/sync_manager_impl.h" | 5 #include "sync/internal_api/sync_manager_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 } | 184 } |
| 185 | 185 |
| 186 // Bind message handlers. | 186 // Bind message handlers. |
| 187 BindJsMessageHandler( | 187 BindJsMessageHandler( |
| 188 "getNotificationState", | 188 "getNotificationState", |
| 189 &SyncManagerImpl::GetNotificationState); | 189 &SyncManagerImpl::GetNotificationState); |
| 190 BindJsMessageHandler( | 190 BindJsMessageHandler( |
| 191 "getNotificationInfo", | 191 "getNotificationInfo", |
| 192 &SyncManagerImpl::GetNotificationInfo); | 192 &SyncManagerImpl::GetNotificationInfo); |
| 193 BindJsMessageHandler( | 193 BindJsMessageHandler( |
| 194 "getRootNodeDetails", | |
| 195 &SyncManagerImpl::GetRootNodeDetails); | |
| 196 BindJsMessageHandler( | |
| 197 "getNodeSummariesById", | |
| 198 &SyncManagerImpl::GetNodeSummariesById); | |
| 199 BindJsMessageHandler( | |
| 200 "getNodeDetailsById", | |
| 201 &SyncManagerImpl::GetNodeDetailsById); | |
| 202 BindJsMessageHandler( | |
| 203 "getAllNodes", | 194 "getAllNodes", |
| 204 &SyncManagerImpl::GetAllNodes); | 195 &SyncManagerImpl::GetAllNodes); |
| 205 BindJsMessageHandler( | 196 BindJsMessageHandler( |
| 206 "getChildNodeIds", | |
| 207 &SyncManagerImpl::GetChildNodeIds); | |
| 208 BindJsMessageHandler( | |
| 209 "getClientServerTraffic", | 197 "getClientServerTraffic", |
| 210 &SyncManagerImpl::GetClientServerTraffic); | 198 &SyncManagerImpl::GetClientServerTraffic); |
| 211 } | 199 } |
| 212 | 200 |
| 213 SyncManagerImpl::~SyncManagerImpl() { | 201 SyncManagerImpl::~SyncManagerImpl() { |
| 214 DCHECK(thread_checker_.CalledOnValidThread()); | 202 DCHECK(thread_checker_.CalledOnValidThread()); |
| 215 CHECK(!initialized_); | 203 CHECK(!initialized_); |
| 216 } | 204 } |
| 217 | 205 |
| 218 SyncManagerImpl::NotificationInfo::NotificationInfo() : total_count(0) {} | 206 SyncManagerImpl::NotificationInfo::NotificationInfo() : total_count(0) {} |
| (...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1034 | 1022 |
| 1035 JsArgList SyncManagerImpl::GetNotificationInfo( | 1023 JsArgList SyncManagerImpl::GetNotificationInfo( |
| 1036 const JsArgList& args) { | 1024 const JsArgList& args) { |
| 1037 DVLOG(1) << "GetNotificationInfo: " | 1025 DVLOG(1) << "GetNotificationInfo: " |
| 1038 << NotificationInfoToString(notification_info_map_); | 1026 << NotificationInfoToString(notification_info_map_); |
| 1039 base::ListValue return_args; | 1027 base::ListValue return_args; |
| 1040 return_args.Append(NotificationInfoToValue(notification_info_map_)); | 1028 return_args.Append(NotificationInfoToValue(notification_info_map_)); |
| 1041 return JsArgList(&return_args); | 1029 return JsArgList(&return_args); |
| 1042 } | 1030 } |
| 1043 | 1031 |
| 1044 JsArgList SyncManagerImpl::GetRootNodeDetails( | |
| 1045 const JsArgList& args) { | |
| 1046 ReadTransaction trans(FROM_HERE, GetUserShare()); | |
| 1047 ReadNode root(&trans); | |
| 1048 root.InitByRootLookup(); | |
| 1049 base::ListValue return_args; | |
| 1050 return_args.Append(root.GetDetailsAsValue()); | |
| 1051 return JsArgList(&return_args); | |
| 1052 } | |
| 1053 | |
| 1054 JsArgList SyncManagerImpl::GetClientServerTraffic( | 1032 JsArgList SyncManagerImpl::GetClientServerTraffic( |
| 1055 const JsArgList& args) { | 1033 const JsArgList& args) { |
| 1056 base::ListValue return_args; | 1034 base::ListValue return_args; |
| 1057 base::ListValue* value = traffic_recorder_.ToValue(); | 1035 base::ListValue* value = traffic_recorder_.ToValue(); |
| 1058 if (value != NULL) | 1036 if (value != NULL) |
| 1059 return_args.Append(value); | 1037 return_args.Append(value); |
| 1060 return JsArgList(&return_args); | 1038 return JsArgList(&return_args); |
| 1061 } | 1039 } |
| 1062 | 1040 |
| 1063 namespace { | 1041 JsArgList SyncManagerImpl::GetAllNodes(const JsArgList& args) { |
| 1064 | 1042 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 1065 int64 GetId(const base::ListValue& ids, int i) { | |
| 1066 std::string id_str; | |
| 1067 if (!ids.GetString(i, &id_str)) { | |
| 1068 return kInvalidId; | |
| 1069 } | |
| 1070 int64 id = kInvalidId; | |
| 1071 if (!base::StringToInt64(id_str, &id)) { | |
| 1072 return kInvalidId; | |
| 1073 } | |
| 1074 return id; | |
| 1075 } | |
| 1076 | |
| 1077 JsArgList GetNodeInfoById( | |
| 1078 const JsArgList& args, | |
| 1079 UserShare* user_share, | |
| 1080 base::DictionaryValue* (BaseNode::*info_getter)() const) { | |
| 1081 CHECK(info_getter); | |
| 1082 base::ListValue return_args; | 1043 base::ListValue return_args; |
| 1083 base::ListValue* node_summaries = new base::ListValue(); | 1044 scoped_ptr<base::ListValue> nodes( |
| 1084 return_args.Append(node_summaries); | 1045 trans.GetDirectory()->GetAllNodeDetails(trans.GetWrappedTrans())); |
| 1085 const base::ListValue* id_list = NULL; | 1046 return_args.Append(nodes.release()); |
| 1086 ReadTransaction trans(FROM_HERE, user_share); | |
| 1087 if (args.Get().GetList(0, &id_list)) { | |
| 1088 CHECK(id_list); | |
| 1089 for (size_t i = 0; i < id_list->GetSize(); ++i) { | |
| 1090 int64 id = GetId(*id_list, i); | |
| 1091 if (id == kInvalidId) { | |
| 1092 continue; | |
| 1093 } | |
| 1094 ReadNode node(&trans); | |
| 1095 if (node.InitByIdLookup(id) != BaseNode::INIT_OK) { | |
| 1096 continue; | |
| 1097 } | |
| 1098 node_summaries->Append((node.*info_getter)()); | |
| 1099 } | |
| 1100 } | |
| 1101 return JsArgList(&return_args); | 1047 return JsArgList(&return_args); |
| 1102 } | 1048 } |
| 1103 | 1049 |
| 1104 } // namespace | |
| 1105 | |
| 1106 JsArgList SyncManagerImpl::GetNodeSummariesById(const JsArgList& args) { | |
| 1107 return GetNodeInfoById(args, GetUserShare(), &BaseNode::GetSummaryAsValue); | |
| 1108 } | |
| 1109 | |
| 1110 JsArgList SyncManagerImpl::GetNodeDetailsById(const JsArgList& args) { | |
| 1111 return GetNodeInfoById(args, GetUserShare(), &BaseNode::GetDetailsAsValue); | |
| 1112 } | |
| 1113 | |
| 1114 JsArgList SyncManagerImpl::GetAllNodes(const JsArgList& args) { | |
| 1115 base::ListValue return_args; | |
| 1116 base::ListValue* result = new base::ListValue(); | |
| 1117 return_args.Append(result); | |
| 1118 | |
| 1119 ReadTransaction trans(FROM_HERE, GetUserShare()); | |
| 1120 std::vector<const syncable::EntryKernel*> entry_kernels; | |
| 1121 trans.GetDirectory()->GetAllEntryKernels(trans.GetWrappedTrans(), | |
| 1122 &entry_kernels); | |
| 1123 | |
| 1124 for (std::vector<const syncable::EntryKernel*>::const_iterator it = | |
| 1125 entry_kernels.begin(); it != entry_kernels.end(); ++it) { | |
| 1126 result->Append((*it)->ToValue(trans.GetCryptographer())); | |
| 1127 } | |
| 1128 | |
| 1129 return JsArgList(&return_args); | |
| 1130 } | |
| 1131 | |
| 1132 JsArgList SyncManagerImpl::GetChildNodeIds(const JsArgList& args) { | |
| 1133 base::ListValue return_args; | |
| 1134 base::ListValue* child_ids = new base::ListValue(); | |
| 1135 return_args.Append(child_ids); | |
| 1136 int64 id = GetId(args.Get(), 0); | |
| 1137 if (id != kInvalidId) { | |
| 1138 ReadTransaction trans(FROM_HERE, GetUserShare()); | |
| 1139 syncable::Directory::Metahandles child_handles; | |
| 1140 trans.GetDirectory()->GetChildHandlesByHandle(trans.GetWrappedTrans(), | |
| 1141 id, &child_handles); | |
| 1142 for (syncable::Directory::Metahandles::const_iterator it = | |
| 1143 child_handles.begin(); it != child_handles.end(); ++it) { | |
| 1144 child_ids->Append(new base::StringValue(base::Int64ToString(*it))); | |
| 1145 } | |
| 1146 } | |
| 1147 return JsArgList(&return_args); | |
| 1148 } | |
| 1149 | |
| 1150 void SyncManagerImpl::UpdateNotificationInfo( | 1050 void SyncManagerImpl::UpdateNotificationInfo( |
| 1151 const ObjectIdInvalidationMap& invalidation_map) { | 1051 const ObjectIdInvalidationMap& invalidation_map) { |
| 1152 ObjectIdSet ids = invalidation_map.GetObjectIds(); | 1052 ObjectIdSet ids = invalidation_map.GetObjectIds(); |
| 1153 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { | 1053 for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { |
| 1154 ModelType type = UNSPECIFIED; | 1054 ModelType type = UNSPECIFIED; |
| 1155 if (!ObjectIdToRealModelType(*it, &type)) { | 1055 if (!ObjectIdToRealModelType(*it, &type)) { |
| 1156 continue; | 1056 continue; |
| 1157 } | 1057 } |
| 1158 const SingleObjectInvalidationSet& type_invalidations = | 1058 const SingleObjectInvalidationSet& type_invalidations = |
| 1159 invalidation_map.ForObject(*it); | 1059 invalidation_map.ForObject(*it); |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 int SyncManagerImpl::GetDefaultNudgeDelay() { | 1238 int SyncManagerImpl::GetDefaultNudgeDelay() { |
| 1339 return kDefaultNudgeDelayMilliseconds; | 1239 return kDefaultNudgeDelayMilliseconds; |
| 1340 } | 1240 } |
| 1341 | 1241 |
| 1342 // static. | 1242 // static. |
| 1343 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 1243 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
| 1344 return kPreferencesNudgeDelayMilliseconds; | 1244 return kPreferencesNudgeDelayMilliseconds; |
| 1345 } | 1245 } |
| 1346 | 1246 |
| 1347 } // namespace syncer | 1247 } // namespace syncer |
| OLD | NEW |