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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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: | 76 case HISTORY_DELETE_DIRECTIVES: |
77 specifics->mutable_history_delete_directive(); | 77 specifics->mutable_history_delete_directive(); |
78 break; | 78 break; |
| 79 case PUSH_NOTIFICATIONS: |
| 80 specifics->push_notifications(); |
| 81 break; |
79 case DEVICE_INFO: | 82 case DEVICE_INFO: |
80 specifics->mutable_device_info(); | 83 specifics->mutable_device_info(); |
81 break; | 84 break; |
82 case EXPERIMENTS: | 85 case EXPERIMENTS: |
83 specifics->mutable_experiments(); | 86 specifics->mutable_experiments(); |
84 break; | 87 break; |
85 default: | 88 default: |
86 NOTREACHED() << "No known extension for model type."; | 89 NOTREACHED() << "No known extension for model type."; |
87 } | 90 } |
88 } | 91 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 return sync_pb::EntitySpecifics::kAppSettingFieldNumber; | 142 return sync_pb::EntitySpecifics::kAppSettingFieldNumber; |
140 break; | 143 break; |
141 case EXTENSION_SETTINGS: | 144 case EXTENSION_SETTINGS: |
142 return sync_pb::EntitySpecifics::kExtensionSettingFieldNumber; | 145 return sync_pb::EntitySpecifics::kExtensionSettingFieldNumber; |
143 break; | 146 break; |
144 case APP_NOTIFICATIONS: | 147 case APP_NOTIFICATIONS: |
145 return sync_pb::EntitySpecifics::kAppNotificationFieldNumber; | 148 return sync_pb::EntitySpecifics::kAppNotificationFieldNumber; |
146 break; | 149 break; |
147 case HISTORY_DELETE_DIRECTIVES: | 150 case HISTORY_DELETE_DIRECTIVES: |
148 return sync_pb::EntitySpecifics::kHistoryDeleteDirectiveFieldNumber; | 151 return sync_pb::EntitySpecifics::kHistoryDeleteDirectiveFieldNumber; |
| 152 case PUSH_NOTIFICATIONS: |
| 153 return sync_pb::EntitySpecifics::kPushNotificationsFieldNumber; |
149 case DEVICE_INFO: | 154 case DEVICE_INFO: |
150 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber; | 155 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber; |
151 break; | 156 break; |
152 case EXPERIMENTS: | 157 case EXPERIMENTS: |
153 return sync_pb::EntitySpecifics::kExperimentsFieldNumber; | 158 return sync_pb::EntitySpecifics::kExperimentsFieldNumber; |
154 break; | 159 break; |
155 default: | 160 default: |
156 NOTREACHED() << "No known extension for model type."; | 161 NOTREACHED() << "No known extension for model type."; |
157 return 0; | 162 return 0; |
158 } | 163 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 | 245 |
241 if (specifics.has_extension_setting()) | 246 if (specifics.has_extension_setting()) |
242 return EXTENSION_SETTINGS; | 247 return EXTENSION_SETTINGS; |
243 | 248 |
244 if (specifics.has_app_notification()) | 249 if (specifics.has_app_notification()) |
245 return APP_NOTIFICATIONS; | 250 return APP_NOTIFICATIONS; |
246 | 251 |
247 if (specifics.has_history_delete_directive()) | 252 if (specifics.has_history_delete_directive()) |
248 return HISTORY_DELETE_DIRECTIVES; | 253 return HISTORY_DELETE_DIRECTIVES; |
249 | 254 |
| 255 if (specifics.has_push_notifications()) |
| 256 return PUSH_NOTIFICATIONS; |
| 257 |
250 if (specifics.has_device_info()) | 258 if (specifics.has_device_info()) |
251 return DEVICE_INFO; | 259 return DEVICE_INFO; |
252 | 260 |
253 if (specifics.has_experiments()) | 261 if (specifics.has_experiments()) |
254 return EXPERIMENTS; | 262 return EXPERIMENTS; |
255 | 263 |
256 return UNSPECIFIED; | 264 return UNSPECIFIED; |
257 } | 265 } |
258 | 266 |
259 bool ShouldMaintainPosition(ModelType model_type) { | 267 bool ShouldMaintainPosition(ModelType model_type) { |
260 return model_type == BOOKMARKS; | 268 return model_type == BOOKMARKS; |
261 } | 269 } |
262 | 270 |
263 ModelTypeSet UserTypes() { | 271 ModelTypeSet UserTypes() { |
264 ModelTypeSet set; | 272 ModelTypeSet set; |
265 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) { | 273 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) { |
266 set.Put(ModelTypeFromInt(i)); | 274 set.Put(ModelTypeFromInt(i)); |
267 } | 275 } |
268 return set; | 276 return set; |
269 } | 277 } |
270 | 278 |
271 ModelTypeSet EncryptableUserTypes() { | 279 ModelTypeSet EncryptableUserTypes() { |
272 ModelTypeSet encryptable_user_types = UserTypes(); | 280 ModelTypeSet encryptable_user_types = UserTypes(); |
273 // We never encrypt history delete directives. | 281 // We never encrypt history delete directives. |
274 encryptable_user_types.Remove(HISTORY_DELETE_DIRECTIVES); | 282 encryptable_user_types.Remove(HISTORY_DELETE_DIRECTIVES); |
| 283 // Push notifications are not encrypted since the server must see changes. |
| 284 encryptable_user_types.Remove(PUSH_NOTIFICATIONS); |
275 return encryptable_user_types; | 285 return encryptable_user_types; |
276 } | 286 } |
277 | 287 |
278 ModelTypeSet ControlTypes() { | 288 ModelTypeSet ControlTypes() { |
279 ModelTypeSet set; | 289 ModelTypeSet set; |
280 for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) { | 290 for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) { |
281 set.Put(ModelTypeFromInt(i)); | 291 set.Put(ModelTypeFromInt(i)); |
282 } | 292 } |
283 | 293 |
284 return set; | 294 return set; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 case AUTOFILL_PROFILE: | 332 case AUTOFILL_PROFILE: |
323 return "Autofill Profiles"; | 333 return "Autofill Profiles"; |
324 case APP_SETTINGS: | 334 case APP_SETTINGS: |
325 return "App settings"; | 335 return "App settings"; |
326 case EXTENSION_SETTINGS: | 336 case EXTENSION_SETTINGS: |
327 return "Extension settings"; | 337 return "Extension settings"; |
328 case APP_NOTIFICATIONS: | 338 case APP_NOTIFICATIONS: |
329 return "App Notifications"; | 339 return "App Notifications"; |
330 case HISTORY_DELETE_DIRECTIVES: | 340 case HISTORY_DELETE_DIRECTIVES: |
331 return "History Delete Directives"; | 341 return "History Delete Directives"; |
| 342 case PUSH_NOTIFICATIONS: |
| 343 return "Push Notifications"; |
332 case DEVICE_INFO: | 344 case DEVICE_INFO: |
333 return "Device Info"; | 345 return "Device Info"; |
334 case EXPERIMENTS: | 346 case EXPERIMENTS: |
335 return "Experiments"; | 347 return "Experiments"; |
336 default: | 348 default: |
337 break; | 349 break; |
338 } | 350 } |
339 NOTREACHED() << "No known extension for model type."; | 351 NOTREACHED() << "No known extension for model type."; |
340 return "INVALID"; | 352 return "INVALID"; |
341 } | 353 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 else if (model_type_string == "Apps") | 405 else if (model_type_string == "Apps") |
394 return APPS; | 406 return APPS; |
395 else if (model_type_string == "App settings") | 407 else if (model_type_string == "App settings") |
396 return APP_SETTINGS; | 408 return APP_SETTINGS; |
397 else if (model_type_string == "Extension settings") | 409 else if (model_type_string == "Extension settings") |
398 return EXTENSION_SETTINGS; | 410 return EXTENSION_SETTINGS; |
399 else if (model_type_string == "App Notifications") | 411 else if (model_type_string == "App Notifications") |
400 return APP_NOTIFICATIONS; | 412 return APP_NOTIFICATIONS; |
401 else if (model_type_string == "History Delete Directives") | 413 else if (model_type_string == "History Delete Directives") |
402 return HISTORY_DELETE_DIRECTIVES; | 414 return HISTORY_DELETE_DIRECTIVES; |
| 415 else if (model_type_string == "Push Notifications") |
| 416 return PUSH_NOTIFICATIONS; |
403 else if (model_type_string == "Device Info") | 417 else if (model_type_string == "Device Info") |
404 return DEVICE_INFO; | 418 return DEVICE_INFO; |
405 else if (model_type_string == "Experiments") | 419 else if (model_type_string == "Experiments") |
406 return EXPERIMENTS; | 420 return EXPERIMENTS; |
407 else | 421 else |
408 NOTREACHED() << "No known model type corresponding to " | 422 NOTREACHED() << "No known model type corresponding to " |
409 << model_type_string << "."; | 423 << model_type_string << "."; |
410 return UNSPECIFIED; | 424 return UNSPECIFIED; |
411 } | 425 } |
412 | 426 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 case AUTOFILL_PROFILE: | 481 case AUTOFILL_PROFILE: |
468 return "google_chrome_autofill_profiles"; | 482 return "google_chrome_autofill_profiles"; |
469 case APP_SETTINGS: | 483 case APP_SETTINGS: |
470 return "google_chrome_app_settings"; | 484 return "google_chrome_app_settings"; |
471 case EXTENSION_SETTINGS: | 485 case EXTENSION_SETTINGS: |
472 return "google_chrome_extension_settings"; | 486 return "google_chrome_extension_settings"; |
473 case APP_NOTIFICATIONS: | 487 case APP_NOTIFICATIONS: |
474 return "google_chrome_app_notifications"; | 488 return "google_chrome_app_notifications"; |
475 case HISTORY_DELETE_DIRECTIVES: | 489 case HISTORY_DELETE_DIRECTIVES: |
476 return "google_chrome_history_delete_directives"; | 490 return "google_chrome_history_delete_directives"; |
| 491 case PUSH_NOTIFICATIONS: |
| 492 return "push_notifications_settings"; |
477 case DEVICE_INFO: | 493 case DEVICE_INFO: |
478 return "google_chrome_device_info"; | 494 return "google_chrome_device_info"; |
479 case EXPERIMENTS: | 495 case EXPERIMENTS: |
480 return "google_chrome_experiments"; | 496 return "google_chrome_experiments"; |
481 default: | 497 default: |
482 break; | 498 break; |
483 } | 499 } |
484 NOTREACHED() << "No known extension for model type."; | 500 NOTREACHED() << "No known extension for model type."; |
485 return "INVALID"; | 501 return "INVALID"; |
486 } | 502 } |
(...skipping 11 matching lines...) Expand all Loading... |
498 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; | 514 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; |
499 const char kNigoriNotificationType[] = "NIGORI"; | 515 const char kNigoriNotificationType[] = "NIGORI"; |
500 const char kAppSettingNotificationType[] = "APP_SETTING"; | 516 const char kAppSettingNotificationType[] = "APP_SETTING"; |
501 const char kAppNotificationType[] = "APP"; | 517 const char kAppNotificationType[] = "APP"; |
502 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; | 518 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; |
503 const char kSessionNotificationType[] = "SESSION"; | 519 const char kSessionNotificationType[] = "SESSION"; |
504 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; | 520 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; |
505 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; | 521 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; |
506 const char kHistoryDeleteDirectiveNotificationType[] = | 522 const char kHistoryDeleteDirectiveNotificationType[] = |
507 "HISTORY_DELETE_DIRECTIVE"; | 523 "HISTORY_DELETE_DIRECTIVE"; |
| 524 const char kPushNotificationsType[] = "PUSH_NOTIFICATIONS"; |
508 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; | 525 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; |
509 const char kExperimentsNotificationType[] = "EXPERIMENTS"; | 526 const char kExperimentsNotificationType[] = "EXPERIMENTS"; |
510 } // namespace | 527 } // namespace |
511 | 528 |
512 bool RealModelTypeToNotificationType(ModelType model_type, | 529 bool RealModelTypeToNotificationType(ModelType model_type, |
513 std::string* notification_type) { | 530 std::string* notification_type) { |
514 switch (model_type) { | 531 switch (model_type) { |
515 case BOOKMARKS: | 532 case BOOKMARKS: |
516 *notification_type = kBookmarkNotificationType; | 533 *notification_type = kBookmarkNotificationType; |
517 return true; | 534 return true; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 *notification_type = kAutofillProfileNotificationType; | 569 *notification_type = kAutofillProfileNotificationType; |
553 return true; | 570 return true; |
554 case EXTENSION_SETTINGS: | 571 case EXTENSION_SETTINGS: |
555 *notification_type = kExtensionSettingNotificationType; | 572 *notification_type = kExtensionSettingNotificationType; |
556 return true; | 573 return true; |
557 case APP_NOTIFICATIONS: | 574 case APP_NOTIFICATIONS: |
558 *notification_type = kAppNotificationNotificationType; | 575 *notification_type = kAppNotificationNotificationType; |
559 return true; | 576 return true; |
560 case HISTORY_DELETE_DIRECTIVES: | 577 case HISTORY_DELETE_DIRECTIVES: |
561 *notification_type = kHistoryDeleteDirectiveNotificationType; | 578 *notification_type = kHistoryDeleteDirectiveNotificationType; |
| 579 case PUSH_NOTIFICATIONS: |
| 580 *notification_type = kPushNotificationsType; |
562 case DEVICE_INFO: | 581 case DEVICE_INFO: |
563 *notification_type = kDeviceInfoNotificationType; | 582 *notification_type = kDeviceInfoNotificationType; |
564 return true; | 583 return true; |
565 case EXPERIMENTS: | 584 case EXPERIMENTS: |
566 *notification_type = kExperimentsNotificationType; | 585 *notification_type = kExperimentsNotificationType; |
567 return true; | 586 return true; |
568 default: | 587 default: |
569 break; | 588 break; |
570 } | 589 } |
571 notification_type->clear(); | 590 notification_type->clear(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 *model_type = APP_SETTINGS; | 633 *model_type = APP_SETTINGS; |
615 return true; | 634 return true; |
616 } else if (notification_type == kExtensionSettingNotificationType) { | 635 } else if (notification_type == kExtensionSettingNotificationType) { |
617 *model_type = EXTENSION_SETTINGS; | 636 *model_type = EXTENSION_SETTINGS; |
618 return true; | 637 return true; |
619 } else if (notification_type == kAppNotificationNotificationType) { | 638 } else if (notification_type == kAppNotificationNotificationType) { |
620 *model_type = APP_NOTIFICATIONS; | 639 *model_type = APP_NOTIFICATIONS; |
621 return true; | 640 return true; |
622 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { | 641 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { |
623 *model_type = HISTORY_DELETE_DIRECTIVES; | 642 *model_type = HISTORY_DELETE_DIRECTIVES; |
| 643 } else if (notification_type == kPushNotificationsType) { |
| 644 *model_type = PUSH_NOTIFICATIONS; |
624 } else if (notification_type == kDeviceInfoNotificationType) { | 645 } else if (notification_type == kDeviceInfoNotificationType) { |
625 *model_type = DEVICE_INFO;; | 646 *model_type = DEVICE_INFO;; |
626 return true; | 647 return true; |
627 } | 648 } |
628 *model_type = UNSPECIFIED; | 649 *model_type = UNSPECIFIED; |
629 return false; | 650 return false; |
630 } | 651 } |
631 | 652 |
632 bool IsRealDataType(ModelType model_type) { | 653 bool IsRealDataType(ModelType model_type) { |
633 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; | 654 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; |
634 } | 655 } |
635 | 656 |
636 } // namespace syncer | 657 } // namespace syncer |
OLD | NEW |