| 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/syncable/model_type.h" | 5 #include "chrome/browser/sync/syncable/model_type.h" |
| 6 | 6 |
| 7 #include "chrome/browser/sync/engine/syncproto.h" | 7 #include "chrome/browser/sync/engine/syncproto.h" |
| 8 #include "chrome/browser/sync/protocol/app_specifics.pb.h" | 8 #include "chrome/browser/sync/protocol/app_specifics.pb.h" |
| 9 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 9 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
| 10 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 10 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
| 11 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 11 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
| 12 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" | 12 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" |
| 13 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 13 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
| 14 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" | 14 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" |
| 15 #include "chrome/browser/sync/protocol/session_specifics.pb.h" | |
| 16 #include "chrome/browser/sync/protocol/sync.pb.h" | 15 #include "chrome/browser/sync/protocol/sync.pb.h" |
| 17 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" | 16 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" |
| 18 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" | 17 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" |
| 19 | 18 |
| 20 namespace syncable { | 19 namespace syncable { |
| 21 | 20 |
| 22 void AddDefaultExtensionValue(syncable::ModelType datatype, | 21 void AddDefaultExtensionValue(syncable::ModelType datatype, |
| 23 sync_pb::EntitySpecifics* specifics) { | 22 sync_pb::EntitySpecifics* specifics) { |
| 24 switch (datatype) { | 23 switch (datatype) { |
| 25 case BOOKMARKS: | 24 case BOOKMARKS: |
| (...skipping 13 matching lines...) Expand all Loading... |
| 39 break; | 38 break; |
| 40 case TYPED_URLS: | 39 case TYPED_URLS: |
| 41 specifics->MutableExtension(sync_pb::typed_url); | 40 specifics->MutableExtension(sync_pb::typed_url); |
| 42 break; | 41 break; |
| 43 case EXTENSIONS: | 42 case EXTENSIONS: |
| 44 specifics->MutableExtension(sync_pb::extension); | 43 specifics->MutableExtension(sync_pb::extension); |
| 45 break; | 44 break; |
| 46 case NIGORI: | 45 case NIGORI: |
| 47 specifics->MutableExtension(sync_pb::nigori); | 46 specifics->MutableExtension(sync_pb::nigori); |
| 48 break; | 47 break; |
| 49 case SESSIONS: | |
| 50 specifics->MutableExtension(sync_pb::session); | |
| 51 break; | |
| 52 case APPS: | 48 case APPS: |
| 53 specifics->MutableExtension(sync_pb::app); | 49 specifics->MutableExtension(sync_pb::app); |
| 54 break; | 50 break; |
| 55 default: | 51 default: |
| 56 NOTREACHED() << "No known extension for model type."; | 52 NOTREACHED() << "No known extension for model type."; |
| 57 } | 53 } |
| 58 } | 54 } |
| 59 | 55 |
| 60 // Note: keep this consistent with GetModelType in syncable.cc! | 56 // Note: keep this consistent with GetModelType in syncable.cc! |
| 61 ModelType GetModelType(const sync_pb::SyncEntity& sync_pb_entity) { | 57 ModelType GetModelType(const sync_pb::SyncEntity& sync_pb_entity) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 105 |
| 110 if (specifics.HasExtension(sync_pb::extension)) | 106 if (specifics.HasExtension(sync_pb::extension)) |
| 111 return EXTENSIONS; | 107 return EXTENSIONS; |
| 112 | 108 |
| 113 if (specifics.HasExtension(sync_pb::nigori)) | 109 if (specifics.HasExtension(sync_pb::nigori)) |
| 114 return NIGORI; | 110 return NIGORI; |
| 115 | 111 |
| 116 if (specifics.HasExtension(sync_pb::app)) | 112 if (specifics.HasExtension(sync_pb::app)) |
| 117 return APPS; | 113 return APPS; |
| 118 | 114 |
| 119 if (specifics.HasExtension(sync_pb::session)) | |
| 120 return SESSIONS; | |
| 121 | |
| 122 return UNSPECIFIED; | 115 return UNSPECIFIED; |
| 123 } | 116 } |
| 124 | 117 |
| 125 std::string ModelTypeToString(ModelType model_type) { | 118 std::string ModelTypeToString(ModelType model_type) { |
| 126 switch (model_type) { | 119 switch (model_type) { |
| 127 case BOOKMARKS: | 120 case BOOKMARKS: |
| 128 return "Bookmarks"; | 121 return "Bookmarks"; |
| 129 case PREFERENCES: | 122 case PREFERENCES: |
| 130 return "Preferences"; | 123 return "Preferences"; |
| 131 case PASSWORDS: | 124 case PASSWORDS: |
| 132 return "Passwords"; | 125 return "Passwords"; |
| 133 case AUTOFILL: | 126 case AUTOFILL: |
| 134 return "Autofill"; | 127 return "Autofill"; |
| 135 case THEMES: | 128 case THEMES: |
| 136 return "Themes"; | 129 return "Themes"; |
| 137 case TYPED_URLS: | 130 case TYPED_URLS: |
| 138 return "Typed URLs"; | 131 return "Typed URLs"; |
| 139 case EXTENSIONS: | 132 case EXTENSIONS: |
| 140 return "Extensions"; | 133 return "Extensions"; |
| 141 case NIGORI: | 134 case NIGORI: |
| 142 return "Encryption keys"; | 135 return "Encryption keys"; |
| 143 case SESSIONS: | |
| 144 return "Sessions"; | |
| 145 case APPS: | 136 case APPS: |
| 146 return "Apps"; | 137 return "Apps"; |
| 147 default: | 138 default: |
| 148 NOTREACHED() << "No known extension for model type."; | 139 NOTREACHED() << "No known extension for model type."; |
| 149 return "INVALID"; | 140 return "INVALID"; |
| 150 } | 141 } |
| 151 } | 142 } |
| 152 | 143 |
| 153 // TODO(akalin): Figure out a better way to do these mappings. | 144 // TODO(akalin): Figure out a better way to do these mappings. |
| 154 | 145 |
| 155 namespace { | 146 namespace { |
| 156 const char kBookmarkNotificationType[] = "BOOKMARK"; | 147 const char kBookmarkNotificationType[] = "BOOKMARK"; |
| 157 const char kPreferenceNotificationType[] = "PREFERENCE"; | 148 const char kPreferenceNotificationType[] = "PREFERENCE"; |
| 158 const char kPasswordNotificationType[] = "PASSWORD"; | 149 const char kPasswordNotificationType[] = "PASSWORD"; |
| 159 const char kAutofillNotificationType[] = "AUTOFILL"; | 150 const char kAutofillNotificationType[] = "AUTOFILL"; |
| 160 const char kThemeNotificationType[] = "THEME"; | 151 const char kThemeNotificationType[] = "THEME"; |
| 161 const char kTypedUrlNotificationType[] = "TYPED_URL"; | 152 const char kTypedUrlNotificationType[] = "TYPED_URL"; |
| 162 const char kExtensionNotificationType[] = "EXTENSION"; | 153 const char kExtensionNotificationType[] = "EXTENSION"; |
| 163 const char kNigoriNotificationType[] = "NIGORI"; | 154 const char kNigoriNotificationType[] = "NIGORI"; |
| 164 const char kAppNotificationType[] = "APP"; | 155 const char kAppNotificationType[] = "APP"; |
| 165 const char kSessionNotificationType[] = "SESSION"; | |
| 166 // TODO(akalin): This is a hack to make new sync data types work with | 156 // TODO(akalin): This is a hack to make new sync data types work with |
| 167 // server-issued notifications. Remove this when it's not needed | 157 // server-issued notifications. Remove this when it's not needed |
| 168 // anymore. | 158 // anymore. |
| 169 const char kUnknownNotificationType[] = "UNKNOWN"; | 159 const char kUnknownNotificationType[] = "UNKNOWN"; |
| 170 } // namespace | 160 } // namespace |
| 171 | 161 |
| 172 bool RealModelTypeToNotificationType(ModelType model_type, | 162 bool RealModelTypeToNotificationType(ModelType model_type, |
| 173 std::string* notification_type) { | 163 std::string* notification_type) { |
| 174 switch (model_type) { | 164 switch (model_type) { |
| 175 case BOOKMARKS: | 165 case BOOKMARKS: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 192 return true; | 182 return true; |
| 193 case EXTENSIONS: | 183 case EXTENSIONS: |
| 194 *notification_type = kExtensionNotificationType; | 184 *notification_type = kExtensionNotificationType; |
| 195 return true; | 185 return true; |
| 196 case NIGORI: | 186 case NIGORI: |
| 197 *notification_type = kNigoriNotificationType; | 187 *notification_type = kNigoriNotificationType; |
| 198 return true; | 188 return true; |
| 199 case APPS: | 189 case APPS: |
| 200 *notification_type = kAppNotificationType; | 190 *notification_type = kAppNotificationType; |
| 201 return true; | 191 return true; |
| 202 case SESSIONS: | |
| 203 *notification_type = kSessionNotificationType; | |
| 204 return true; | |
| 205 // TODO(akalin): This is a hack to make new sync data types work with | 192 // TODO(akalin): This is a hack to make new sync data types work with |
| 206 // server-issued notifications. Remove this when it's not needed | 193 // server-issued notifications. Remove this when it's not needed |
| 207 // anymore. | 194 // anymore. |
| 208 case UNSPECIFIED: | 195 case UNSPECIFIED: |
| 209 *notification_type = kUnknownNotificationType; | 196 *notification_type = kUnknownNotificationType; |
| 210 return true; | 197 return true; |
| 211 default: | 198 default: |
| 212 break; | 199 break; |
| 213 } | 200 } |
| 214 notification_type->clear(); | 201 notification_type->clear(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 237 return true; | 224 return true; |
| 238 } else if (notification_type == kExtensionNotificationType) { | 225 } else if (notification_type == kExtensionNotificationType) { |
| 239 *model_type = EXTENSIONS; | 226 *model_type = EXTENSIONS; |
| 240 return true; | 227 return true; |
| 241 } else if (notification_type == kNigoriNotificationType) { | 228 } else if (notification_type == kNigoriNotificationType) { |
| 242 *model_type = NIGORI; | 229 *model_type = NIGORI; |
| 243 return true; | 230 return true; |
| 244 } else if (notification_type == kAppNotificationType) { | 231 } else if (notification_type == kAppNotificationType) { |
| 245 *model_type = APPS; | 232 *model_type = APPS; |
| 246 return true; | 233 return true; |
| 247 } else if (notification_type == kSessionNotificationType) { | 234 } else if (notification_type == kUnknownNotificationType) { |
| 248 *model_type = SESSIONS; | |
| 249 return true; | |
| 250 } | |
| 251 else if (notification_type == kUnknownNotificationType) { | |
| 252 // TODO(akalin): This is a hack to make new sync data types work with | 235 // TODO(akalin): This is a hack to make new sync data types work with |
| 253 // server-issued notifications. Remove this when it's not needed | 236 // server-issued notifications. Remove this when it's not needed |
| 254 // anymore. | 237 // anymore. |
| 255 *model_type = UNSPECIFIED; | 238 *model_type = UNSPECIFIED; |
| 256 return true; | 239 return true; |
| 257 } | 240 } |
| 258 *model_type = UNSPECIFIED; | 241 *model_type = UNSPECIFIED; |
| 259 return false; | 242 return false; |
| 260 } | 243 } |
| 261 | 244 |
| 262 } // namespace syncable | 245 } // namespace syncable |
| OLD | NEW |