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/public/base/model_type.h" | 5 #include "sync/internal_api/public/base/model_type.h" |
6 | 6 |
7 #include "base/string_split.h" | 7 #include "base/string_split.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "sync/protocol/app_notification_specifics.pb.h" | 9 #include "sync/protocol/app_notification_specifics.pb.h" |
10 #include "sync/protocol/app_setting_specifics.pb.h" | 10 #include "sync/protocol/app_setting_specifics.pb.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 break; | 66 break; |
67 case APP_SETTINGS: | 67 case APP_SETTINGS: |
68 specifics->mutable_app_setting(); | 68 specifics->mutable_app_setting(); |
69 break; | 69 break; |
70 case EXTENSION_SETTINGS: | 70 case EXTENSION_SETTINGS: |
71 specifics->mutable_extension_setting(); | 71 specifics->mutable_extension_setting(); |
72 break; | 72 break; |
73 case APP_NOTIFICATIONS: | 73 case APP_NOTIFICATIONS: |
74 specifics->mutable_app_notification(); | 74 specifics->mutable_app_notification(); |
75 break; | 75 break; |
| 76 case HISTORY_DELETE_DIRECTIVES: |
| 77 specifics->mutable_history_delete_directive(); |
| 78 break; |
76 case DEVICE_INFO: | 79 case DEVICE_INFO: |
77 specifics->mutable_device_info(); | 80 specifics->mutable_device_info(); |
78 break; | 81 break; |
79 default: | 82 default: |
80 NOTREACHED() << "No known extension for model type."; | 83 NOTREACHED() << "No known extension for model type."; |
81 } | 84 } |
82 } | 85 } |
83 | 86 |
84 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { | 87 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { |
85 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 88 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 break; | 134 break; |
132 case APP_SETTINGS: | 135 case APP_SETTINGS: |
133 return sync_pb::EntitySpecifics::kAppSettingFieldNumber; | 136 return sync_pb::EntitySpecifics::kAppSettingFieldNumber; |
134 break; | 137 break; |
135 case EXTENSION_SETTINGS: | 138 case EXTENSION_SETTINGS: |
136 return sync_pb::EntitySpecifics::kExtensionSettingFieldNumber; | 139 return sync_pb::EntitySpecifics::kExtensionSettingFieldNumber; |
137 break; | 140 break; |
138 case APP_NOTIFICATIONS: | 141 case APP_NOTIFICATIONS: |
139 return sync_pb::EntitySpecifics::kAppNotificationFieldNumber; | 142 return sync_pb::EntitySpecifics::kAppNotificationFieldNumber; |
140 break; | 143 break; |
| 144 case HISTORY_DELETE_DIRECTIVES: |
| 145 return sync_pb::EntitySpecifics::kHistoryDeleteDirectiveFieldNumber; |
141 case DEVICE_INFO: | 146 case DEVICE_INFO: |
142 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber; | 147 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber; |
143 break; | 148 break; |
144 default: | 149 default: |
145 NOTREACHED() << "No known extension for model type."; | 150 NOTREACHED() << "No known extension for model type."; |
146 return 0; | 151 return 0; |
147 } | 152 } |
148 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of " | 153 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of " |
149 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681"; | 154 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681"; |
150 return 0; | 155 return 0; |
151 } | 156 } |
152 | 157 |
153 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) { | 158 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) { |
154 FullModelTypeSet out; | 159 FullModelTypeSet out; |
155 for (ModelTypeSet::Iterator i = in.First(); i.Good(); i.Inc()) { | 160 for (ModelTypeSet::Iterator i = in.First(); i.Good(); i.Inc()) { |
156 out.Put(i.Get()); | 161 out.Put(i.Get()); |
157 } | 162 } |
158 return out; | 163 return out; |
159 } | 164 } |
160 | 165 |
161 // Note: keep this consistent with GetModelType in syncable.cc! | 166 // Note: keep this consistent with GetModelType in entry.cc! |
162 ModelType GetModelType(const sync_pb::SyncEntity& sync_entity) { | 167 ModelType GetModelType(const sync_pb::SyncEntity& sync_entity) { |
163 DCHECK(!IsRoot(sync_entity)); // Root shouldn't ever go over the wire. | 168 DCHECK(!IsRoot(sync_entity)); // Root shouldn't ever go over the wire. |
164 | 169 |
165 if (sync_entity.deleted()) | 170 if (sync_entity.deleted()) |
166 return UNSPECIFIED; | 171 return UNSPECIFIED; |
167 | 172 |
168 // Backwards compatibility with old (pre-specifics) protocol. | 173 // Backwards compatibility with old (pre-specifics) protocol. |
169 if (sync_entity.has_bookmarkdata()) | 174 if (sync_entity.has_bookmarkdata()) |
170 return BOOKMARKS; | 175 return BOOKMARKS; |
171 | 176 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 231 |
227 if (specifics.has_app_setting()) | 232 if (specifics.has_app_setting()) |
228 return APP_SETTINGS; | 233 return APP_SETTINGS; |
229 | 234 |
230 if (specifics.has_extension_setting()) | 235 if (specifics.has_extension_setting()) |
231 return EXTENSION_SETTINGS; | 236 return EXTENSION_SETTINGS; |
232 | 237 |
233 if (specifics.has_app_notification()) | 238 if (specifics.has_app_notification()) |
234 return APP_NOTIFICATIONS; | 239 return APP_NOTIFICATIONS; |
235 | 240 |
| 241 if (specifics.has_history_delete_directive()) |
| 242 return HISTORY_DELETE_DIRECTIVES; |
| 243 |
236 if (specifics.has_device_info()) | 244 if (specifics.has_device_info()) |
237 return DEVICE_INFO; | 245 return DEVICE_INFO; |
238 | 246 |
239 return UNSPECIFIED; | 247 return UNSPECIFIED; |
240 } | 248 } |
241 | 249 |
242 bool ShouldMaintainPosition(ModelType model_type) { | 250 bool ShouldMaintainPosition(ModelType model_type) { |
243 return model_type == BOOKMARKS; | 251 return model_type == BOOKMARKS; |
244 } | 252 } |
245 | 253 |
246 ModelTypeSet UserTypes() { | 254 ModelTypeSet UserTypes() { |
247 ModelTypeSet set; | 255 ModelTypeSet set; |
248 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) { | 256 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) { |
249 set.Put(ModelTypeFromInt(i)); | 257 set.Put(ModelTypeFromInt(i)); |
250 } | 258 } |
251 return set; | 259 return set; |
252 } | 260 } |
253 | 261 |
| 262 ModelTypeSet EncryptableUserTypes() { |
| 263 ModelTypeSet encryptable_user_types = UserTypes(); |
| 264 // We never encrypt history delete directives. |
| 265 encryptable_user_types.Remove(HISTORY_DELETE_DIRECTIVES); |
| 266 return encryptable_user_types; |
| 267 } |
| 268 |
254 ModelTypeSet ControlTypes() { | 269 ModelTypeSet ControlTypes() { |
255 ModelTypeSet set; | 270 ModelTypeSet set; |
256 for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) { | 271 for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) { |
257 set.Put(ModelTypeFromInt(i)); | 272 set.Put(ModelTypeFromInt(i)); |
258 } | 273 } |
259 | 274 |
260 // TODO(rlarocque): Re-enable this when the server supports it. | 275 // TODO(rlarocque): Re-enable this when the server supports it. |
261 set.Remove(DEVICE_INFO); | 276 set.Remove(DEVICE_INFO); |
262 | 277 |
263 return set; | 278 return set; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 case APPS: | 314 case APPS: |
300 return "Apps"; | 315 return "Apps"; |
301 case AUTOFILL_PROFILE: | 316 case AUTOFILL_PROFILE: |
302 return "Autofill Profiles"; | 317 return "Autofill Profiles"; |
303 case APP_SETTINGS: | 318 case APP_SETTINGS: |
304 return "App settings"; | 319 return "App settings"; |
305 case EXTENSION_SETTINGS: | 320 case EXTENSION_SETTINGS: |
306 return "Extension settings"; | 321 return "Extension settings"; |
307 case APP_NOTIFICATIONS: | 322 case APP_NOTIFICATIONS: |
308 return "App Notifications"; | 323 return "App Notifications"; |
| 324 case HISTORY_DELETE_DIRECTIVES: |
| 325 return "History Delete Directives"; |
309 case DEVICE_INFO: | 326 case DEVICE_INFO: |
310 return "Device Info"; | 327 return "Device Info"; |
311 default: | 328 default: |
312 break; | 329 break; |
313 } | 330 } |
314 NOTREACHED() << "No known extension for model type."; | 331 NOTREACHED() << "No known extension for model type."; |
315 return "INVALID"; | 332 return "INVALID"; |
316 } | 333 } |
317 | 334 |
318 StringValue* ModelTypeToValue(ModelType model_type) { | 335 StringValue* ModelTypeToValue(ModelType model_type) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 else if (model_type_string == "Sessions") | 383 else if (model_type_string == "Sessions") |
367 return SESSIONS; | 384 return SESSIONS; |
368 else if (model_type_string == "Apps") | 385 else if (model_type_string == "Apps") |
369 return APPS; | 386 return APPS; |
370 else if (model_type_string == "App settings") | 387 else if (model_type_string == "App settings") |
371 return APP_SETTINGS; | 388 return APP_SETTINGS; |
372 else if (model_type_string == "Extension settings") | 389 else if (model_type_string == "Extension settings") |
373 return EXTENSION_SETTINGS; | 390 return EXTENSION_SETTINGS; |
374 else if (model_type_string == "App Notifications") | 391 else if (model_type_string == "App Notifications") |
375 return APP_NOTIFICATIONS; | 392 return APP_NOTIFICATIONS; |
| 393 else if (model_type_string == "History Delete Directives") |
| 394 return HISTORY_DELETE_DIRECTIVES; |
376 else if (model_type_string == "Device Info") | 395 else if (model_type_string == "Device Info") |
377 return DEVICE_INFO; | 396 return DEVICE_INFO; |
378 else | 397 else |
379 NOTREACHED() << "No known model type corresponding to " | 398 NOTREACHED() << "No known model type corresponding to " |
380 << model_type_string << "."; | 399 << model_type_string << "."; |
381 return UNSPECIFIED; | 400 return UNSPECIFIED; |
382 } | 401 } |
383 | 402 |
384 std::string ModelTypeSetToString(ModelTypeSet model_types) { | 403 std::string ModelTypeSetToString(ModelTypeSet model_types) { |
385 std::string result; | 404 std::string result; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 case APPS: | 455 case APPS: |
437 return "google_chrome_apps"; | 456 return "google_chrome_apps"; |
438 case AUTOFILL_PROFILE: | 457 case AUTOFILL_PROFILE: |
439 return "google_chrome_autofill_profiles"; | 458 return "google_chrome_autofill_profiles"; |
440 case APP_SETTINGS: | 459 case APP_SETTINGS: |
441 return "google_chrome_app_settings"; | 460 return "google_chrome_app_settings"; |
442 case EXTENSION_SETTINGS: | 461 case EXTENSION_SETTINGS: |
443 return "google_chrome_extension_settings"; | 462 return "google_chrome_extension_settings"; |
444 case APP_NOTIFICATIONS: | 463 case APP_NOTIFICATIONS: |
445 return "google_chrome_app_notifications"; | 464 return "google_chrome_app_notifications"; |
| 465 case HISTORY_DELETE_DIRECTIVES: |
| 466 return "google_chrome_history_delete_directives"; |
446 case DEVICE_INFO: | 467 case DEVICE_INFO: |
447 return "google_chrome_device_info"; | 468 return "google_chrome_device_info"; |
448 default: | 469 default: |
449 break; | 470 break; |
450 } | 471 } |
451 NOTREACHED() << "No known extension for model type."; | 472 NOTREACHED() << "No known extension for model type."; |
452 return "INVALID"; | 473 return "INVALID"; |
453 } | 474 } |
454 | 475 |
455 // TODO(akalin): Figure out a better way to do these mappings. | 476 // TODO(akalin): Figure out a better way to do these mappings. |
456 | 477 |
457 namespace { | 478 namespace { |
458 const char kBookmarkNotificationType[] = "BOOKMARK"; | 479 const char kBookmarkNotificationType[] = "BOOKMARK"; |
459 const char kPreferenceNotificationType[] = "PREFERENCE"; | 480 const char kPreferenceNotificationType[] = "PREFERENCE"; |
460 const char kPasswordNotificationType[] = "PASSWORD"; | 481 const char kPasswordNotificationType[] = "PASSWORD"; |
461 const char kAutofillNotificationType[] = "AUTOFILL"; | 482 const char kAutofillNotificationType[] = "AUTOFILL"; |
462 const char kThemeNotificationType[] = "THEME"; | 483 const char kThemeNotificationType[] = "THEME"; |
463 const char kTypedUrlNotificationType[] = "TYPED_URL"; | 484 const char kTypedUrlNotificationType[] = "TYPED_URL"; |
464 const char kExtensionNotificationType[] = "EXTENSION"; | 485 const char kExtensionNotificationType[] = "EXTENSION"; |
465 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; | 486 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; |
466 const char kNigoriNotificationType[] = "NIGORI"; | 487 const char kNigoriNotificationType[] = "NIGORI"; |
467 const char kAppSettingNotificationType[] = "APP_SETTING"; | 488 const char kAppSettingNotificationType[] = "APP_SETTING"; |
468 const char kAppNotificationType[] = "APP"; | 489 const char kAppNotificationType[] = "APP"; |
469 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; | 490 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; |
470 const char kSessionNotificationType[] = "SESSION"; | 491 const char kSessionNotificationType[] = "SESSION"; |
471 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; | 492 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; |
472 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; | 493 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; |
| 494 const char kHistoryDeleteDirectiveNotificationType[] = |
| 495 "HISTORY_DELETE_DIRECTIVE"; |
473 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; | 496 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; |
474 } // namespace | 497 } // namespace |
475 | 498 |
476 bool RealModelTypeToNotificationType(ModelType model_type, | 499 bool RealModelTypeToNotificationType(ModelType model_type, |
477 std::string* notification_type) { | 500 std::string* notification_type) { |
478 switch (model_type) { | 501 switch (model_type) { |
479 case BOOKMARKS: | 502 case BOOKMARKS: |
480 *notification_type = kBookmarkNotificationType; | 503 *notification_type = kBookmarkNotificationType; |
481 return true; | 504 return true; |
482 case PREFERENCES: | 505 case PREFERENCES: |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 return true; | 537 return true; |
515 case AUTOFILL_PROFILE: | 538 case AUTOFILL_PROFILE: |
516 *notification_type = kAutofillProfileNotificationType; | 539 *notification_type = kAutofillProfileNotificationType; |
517 return true; | 540 return true; |
518 case EXTENSION_SETTINGS: | 541 case EXTENSION_SETTINGS: |
519 *notification_type = kExtensionSettingNotificationType; | 542 *notification_type = kExtensionSettingNotificationType; |
520 return true; | 543 return true; |
521 case APP_NOTIFICATIONS: | 544 case APP_NOTIFICATIONS: |
522 *notification_type = kAppNotificationNotificationType; | 545 *notification_type = kAppNotificationNotificationType; |
523 return true; | 546 return true; |
| 547 case HISTORY_DELETE_DIRECTIVES: |
| 548 *notification_type = kHistoryDeleteDirectiveNotificationType; |
524 case DEVICE_INFO: | 549 case DEVICE_INFO: |
525 *notification_type = kDeviceInfoNotificationType; | 550 *notification_type = kDeviceInfoNotificationType; |
526 return true; | 551 return true; |
527 default: | 552 default: |
528 break; | 553 break; |
529 } | 554 } |
530 notification_type->clear(); | 555 notification_type->clear(); |
531 return false; | 556 return false; |
532 } | 557 } |
533 | 558 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
571 return true; | 596 return true; |
572 } else if (notification_type == kAppSettingNotificationType) { | 597 } else if (notification_type == kAppSettingNotificationType) { |
573 *model_type = APP_SETTINGS; | 598 *model_type = APP_SETTINGS; |
574 return true; | 599 return true; |
575 } else if (notification_type == kExtensionSettingNotificationType) { | 600 } else if (notification_type == kExtensionSettingNotificationType) { |
576 *model_type = EXTENSION_SETTINGS; | 601 *model_type = EXTENSION_SETTINGS; |
577 return true; | 602 return true; |
578 } else if (notification_type == kAppNotificationNotificationType) { | 603 } else if (notification_type == kAppNotificationNotificationType) { |
579 *model_type = APP_NOTIFICATIONS; | 604 *model_type = APP_NOTIFICATIONS; |
580 return true; | 605 return true; |
| 606 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { |
| 607 *model_type = HISTORY_DELETE_DIRECTIVES; |
581 } else if (notification_type == kDeviceInfoNotificationType) { | 608 } else if (notification_type == kDeviceInfoNotificationType) { |
582 *model_type = DEVICE_INFO;; | 609 *model_type = DEVICE_INFO;; |
583 return true; | 610 return true; |
584 } else { | |
585 *model_type = UNSPECIFIED; | |
586 return false; | |
587 } | 611 } |
| 612 *model_type = UNSPECIFIED; |
| 613 return false; |
588 } | 614 } |
589 | 615 |
590 bool IsRealDataType(ModelType model_type) { | 616 bool IsRealDataType(ModelType model_type) { |
591 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; | 617 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; |
592 } | 618 } |
593 | 619 |
594 } // namespace syncer | 620 } // namespace syncer |
OLD | NEW |