Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: sync/syncable/model_type.cc

Issue 11445002: Sync user's custom spellcheck dictionary (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Merge master Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sync/protocol/sync_proto.gyp ('k') | sync/syncable/nigori_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 break; 81 break;
82 case DEVICE_INFO: 82 case DEVICE_INFO:
83 specifics->mutable_device_info(); 83 specifics->mutable_device_info();
84 break; 84 break;
85 case EXPERIMENTS: 85 case EXPERIMENTS:
86 specifics->mutable_experiments(); 86 specifics->mutable_experiments();
87 break; 87 break;
88 case PRIORITY_PREFERENCES: 88 case PRIORITY_PREFERENCES:
89 specifics->mutable_priority_preference(); 89 specifics->mutable_priority_preference();
90 break; 90 break;
91 case DICTIONARY:
92 specifics->mutable_dictionary();
93 break;
91 default: 94 default:
92 NOTREACHED() << "No known extension for model type."; 95 NOTREACHED() << "No known extension for model type.";
93 } 96 }
94 } 97 }
95 98
96 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { 99 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) {
97 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { 100 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
98 ModelType model_type = ModelTypeFromInt(i); 101 ModelType model_type = ModelTypeFromInt(i);
99 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number) 102 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number)
100 return model_type; 103 return model_type;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 return sync_pb::EntitySpecifics::kSyncedNotificationFieldNumber; 158 return sync_pb::EntitySpecifics::kSyncedNotificationFieldNumber;
156 case DEVICE_INFO: 159 case DEVICE_INFO:
157 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber; 160 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber;
158 break; 161 break;
159 case EXPERIMENTS: 162 case EXPERIMENTS:
160 return sync_pb::EntitySpecifics::kExperimentsFieldNumber; 163 return sync_pb::EntitySpecifics::kExperimentsFieldNumber;
161 break; 164 break;
162 case PRIORITY_PREFERENCES: 165 case PRIORITY_PREFERENCES:
163 return sync_pb::EntitySpecifics::kPriorityPreferenceFieldNumber; 166 return sync_pb::EntitySpecifics::kPriorityPreferenceFieldNumber;
164 break; 167 break;
168 case DICTIONARY:
169 return sync_pb::EntitySpecifics::kDictionaryFieldNumber;
170 break;
165 default: 171 default:
166 NOTREACHED() << "No known extension for model type."; 172 NOTREACHED() << "No known extension for model type.";
167 return 0; 173 return 0;
168 } 174 }
169 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of " 175 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of "
170 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681"; 176 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681";
171 return 0; 177 return 0;
172 } 178 }
173 179
174 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) { 180 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 268
263 if (specifics.has_device_info()) 269 if (specifics.has_device_info())
264 return DEVICE_INFO; 270 return DEVICE_INFO;
265 271
266 if (specifics.has_experiments()) 272 if (specifics.has_experiments())
267 return EXPERIMENTS; 273 return EXPERIMENTS;
268 274
269 if (specifics.has_priority_preference()) 275 if (specifics.has_priority_preference())
270 return PRIORITY_PREFERENCES; 276 return PRIORITY_PREFERENCES;
271 277
278 if (specifics.has_dictionary())
279 return DICTIONARY;
280
272 return UNSPECIFIED; 281 return UNSPECIFIED;
273 } 282 }
274 283
275 bool ShouldMaintainPosition(ModelType model_type) { 284 bool ShouldMaintainPosition(ModelType model_type) {
276 return model_type == BOOKMARKS; 285 return model_type == BOOKMARKS;
277 } 286 }
278 287
279 ModelTypeSet UserTypes() { 288 ModelTypeSet UserTypes() {
280 ModelTypeSet set; 289 ModelTypeSet set;
281 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) { 290 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 case HISTORY_DELETE_DIRECTIVES: 360 case HISTORY_DELETE_DIRECTIVES:
352 return "History Delete Directives"; 361 return "History Delete Directives";
353 case SYNCED_NOTIFICATIONS: 362 case SYNCED_NOTIFICATIONS:
354 return "Synced Notifications"; 363 return "Synced Notifications";
355 case DEVICE_INFO: 364 case DEVICE_INFO:
356 return "Device Info"; 365 return "Device Info";
357 case EXPERIMENTS: 366 case EXPERIMENTS:
358 return "Experiments"; 367 return "Experiments";
359 case PRIORITY_PREFERENCES: 368 case PRIORITY_PREFERENCES:
360 return "Priority Preferences"; 369 return "Priority Preferences";
370 case DICTIONARY:
371 return "Dictionary";
361 default: 372 default:
362 break; 373 break;
363 } 374 }
364 NOTREACHED() << "No known extension for model type."; 375 NOTREACHED() << "No known extension for model type.";
365 return "INVALID"; 376 return "INVALID";
366 } 377 }
367 378
368 StringValue* ModelTypeToValue(ModelType model_type) { 379 StringValue* ModelTypeToValue(ModelType model_type) {
369 if (model_type >= FIRST_REAL_MODEL_TYPE) { 380 if (model_type >= FIRST_REAL_MODEL_TYPE) {
370 return Value::CreateStringValue(ModelTypeToString(model_type)); 381 return Value::CreateStringValue(ModelTypeToString(model_type));
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 else if (model_type_string == "History Delete Directives") 437 else if (model_type_string == "History Delete Directives")
427 return HISTORY_DELETE_DIRECTIVES; 438 return HISTORY_DELETE_DIRECTIVES;
428 else if (model_type_string == "Synced Notifications") 439 else if (model_type_string == "Synced Notifications")
429 return SYNCED_NOTIFICATIONS; 440 return SYNCED_NOTIFICATIONS;
430 else if (model_type_string == "Device Info") 441 else if (model_type_string == "Device Info")
431 return DEVICE_INFO; 442 return DEVICE_INFO;
432 else if (model_type_string == "Experiments") 443 else if (model_type_string == "Experiments")
433 return EXPERIMENTS; 444 return EXPERIMENTS;
434 else if (model_type_string == "Priority Preferences") 445 else if (model_type_string == "Priority Preferences")
435 return PRIORITY_PREFERENCES; 446 return PRIORITY_PREFERENCES;
447 else if (model_type_string == "Dictionary")
448 return DICTIONARY;
436 else 449 else
437 NOTREACHED() << "No known model type corresponding to " 450 NOTREACHED() << "No known model type corresponding to "
438 << model_type_string << "."; 451 << model_type_string << ".";
439 return UNSPECIFIED; 452 return UNSPECIFIED;
440 } 453 }
441 454
442 std::string ModelTypeSetToString(ModelTypeSet model_types) { 455 std::string ModelTypeSetToString(ModelTypeSet model_types) {
443 std::string result; 456 std::string result;
444 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { 457 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) {
445 if (!result.empty()) { 458 if (!result.empty()) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 case HISTORY_DELETE_DIRECTIVES: 517 case HISTORY_DELETE_DIRECTIVES:
505 return "google_chrome_history_delete_directives"; 518 return "google_chrome_history_delete_directives";
506 case SYNCED_NOTIFICATIONS: 519 case SYNCED_NOTIFICATIONS:
507 return "google_chrome_synced_notifications"; 520 return "google_chrome_synced_notifications";
508 case DEVICE_INFO: 521 case DEVICE_INFO:
509 return "google_chrome_device_info"; 522 return "google_chrome_device_info";
510 case EXPERIMENTS: 523 case EXPERIMENTS:
511 return "google_chrome_experiments"; 524 return "google_chrome_experiments";
512 case PRIORITY_PREFERENCES: 525 case PRIORITY_PREFERENCES:
513 return "google_chrome_priority_preferences"; 526 return "google_chrome_priority_preferences";
527 case DICTIONARY:
528 return "google_chrome_dictionary";
514 default: 529 default:
515 break; 530 break;
516 } 531 }
517 NOTREACHED() << "No known extension for model type."; 532 NOTREACHED() << "No known extension for model type.";
518 return "INVALID"; 533 return "INVALID";
519 } 534 }
520 535
521 // TODO(akalin): Figure out a better way to do these mappings. 536 // TODO(akalin): Figure out a better way to do these mappings.
522 537
523 namespace { 538 namespace {
(...skipping 11 matching lines...) Expand all
535 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; 550 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE";
536 const char kSessionNotificationType[] = "SESSION"; 551 const char kSessionNotificationType[] = "SESSION";
537 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; 552 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE";
538 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; 553 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION";
539 const char kHistoryDeleteDirectiveNotificationType[] = 554 const char kHistoryDeleteDirectiveNotificationType[] =
540 "HISTORY_DELETE_DIRECTIVE"; 555 "HISTORY_DELETE_DIRECTIVE";
541 const char kSyncedNotificationType[] = "SYNCED_NOTIFICATION"; 556 const char kSyncedNotificationType[] = "SYNCED_NOTIFICATION";
542 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; 557 const char kDeviceInfoNotificationType[] = "DEVICE_INFO";
543 const char kExperimentsNotificationType[] = "EXPERIMENTS"; 558 const char kExperimentsNotificationType[] = "EXPERIMENTS";
544 const char kPriorityPreferenceNotificationType[] = "PRIORITY_PREFERENCE"; 559 const char kPriorityPreferenceNotificationType[] = "PRIORITY_PREFERENCE";
560 const char kDictionaryNotificationType[] = "DICTIONARY";
545 } // namespace 561 } // namespace
546 562
547 bool RealModelTypeToNotificationType(ModelType model_type, 563 bool RealModelTypeToNotificationType(ModelType model_type,
548 std::string* notification_type) { 564 std::string* notification_type) {
549 switch (model_type) { 565 switch (model_type) {
550 case BOOKMARKS: 566 case BOOKMARKS:
551 *notification_type = kBookmarkNotificationType; 567 *notification_type = kBookmarkNotificationType;
552 return true; 568 return true;
553 case PREFERENCES: 569 case PREFERENCES:
554 *notification_type = kPreferenceNotificationType; 570 *notification_type = kPreferenceNotificationType;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 case SYNCED_NOTIFICATIONS: 613 case SYNCED_NOTIFICATIONS:
598 *notification_type = kSyncedNotificationType; 614 *notification_type = kSyncedNotificationType;
599 case DEVICE_INFO: 615 case DEVICE_INFO:
600 *notification_type = kDeviceInfoNotificationType; 616 *notification_type = kDeviceInfoNotificationType;
601 return true; 617 return true;
602 case EXPERIMENTS: 618 case EXPERIMENTS:
603 *notification_type = kExperimentsNotificationType; 619 *notification_type = kExperimentsNotificationType;
604 return true; 620 return true;
605 case PRIORITY_PREFERENCES: 621 case PRIORITY_PREFERENCES:
606 *notification_type = kPriorityPreferenceNotificationType; 622 *notification_type = kPriorityPreferenceNotificationType;
623 return true;
624 case DICTIONARY:
625 *notification_type = kDictionaryNotificationType;
626 return true;
607 default: 627 default:
608 break; 628 break;
609 } 629 }
610 notification_type->clear(); 630 notification_type->clear();
611 return false; 631 return false;
612 } 632 }
613 633
614 bool NotificationTypeToRealModelType(const std::string& notification_type, 634 bool NotificationTypeToRealModelType(const std::string& notification_type,
615 ModelType* model_type) { 635 ModelType* model_type) {
616 if (notification_type == kBookmarkNotificationType) { 636 if (notification_type == kBookmarkNotificationType) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { 681 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) {
662 *model_type = HISTORY_DELETE_DIRECTIVES; 682 *model_type = HISTORY_DELETE_DIRECTIVES;
663 } else if (notification_type == kSyncedNotificationType) { 683 } else if (notification_type == kSyncedNotificationType) {
664 *model_type = SYNCED_NOTIFICATIONS; 684 *model_type = SYNCED_NOTIFICATIONS;
665 } else if (notification_type == kDeviceInfoNotificationType) { 685 } else if (notification_type == kDeviceInfoNotificationType) {
666 *model_type = DEVICE_INFO;; 686 *model_type = DEVICE_INFO;;
667 return true; 687 return true;
668 } else if (notification_type == kPriorityPreferenceNotificationType) { 688 } else if (notification_type == kPriorityPreferenceNotificationType) {
669 *model_type = PRIORITY_PREFERENCES; 689 *model_type = PRIORITY_PREFERENCES;
670 return true; 690 return true;
691 } else if (notification_type == kDictionaryNotificationType) {
692 *model_type = DICTIONARY;
693 return true;
671 } 694 }
672 *model_type = UNSPECIFIED; 695 *model_type = UNSPECIFIED;
673 return false; 696 return false;
674 } 697 }
675 698
676 bool IsRealDataType(ModelType model_type) { 699 bool IsRealDataType(ModelType model_type) {
677 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; 700 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT;
678 } 701 }
679 702
680 } // namespace syncer 703 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/protocol/sync_proto.gyp ('k') | sync/syncable/nigori_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698