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

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

Issue 11734009: sync: Add ControlPreference protobuf and supporting code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Daily rebase 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 | Annotate | Revision Log
« no previous file with comments | « sync/protocol/sync_proto.gyp ('k') | sync/util/data_type_histogram.h » ('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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 break; 78 break;
79 case SYNCED_NOTIFICATIONS: 79 case SYNCED_NOTIFICATIONS:
80 specifics->mutable_synced_notification(); 80 specifics->mutable_synced_notification();
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:
89 specifics->mutable_priority_preference();
90 break;
88 default: 91 default:
89 NOTREACHED() << "No known extension for model type."; 92 NOTREACHED() << "No known extension for model type.";
90 } 93 }
91 } 94 }
92 95
93 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { 96 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) {
94 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { 97 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
95 ModelType model_type = ModelTypeFromInt(i); 98 ModelType model_type = ModelTypeFromInt(i);
96 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number) 99 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number)
97 return model_type; 100 return model_type;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 case HISTORY_DELETE_DIRECTIVES: 152 case HISTORY_DELETE_DIRECTIVES:
150 return sync_pb::EntitySpecifics::kHistoryDeleteDirectiveFieldNumber; 153 return sync_pb::EntitySpecifics::kHistoryDeleteDirectiveFieldNumber;
151 case SYNCED_NOTIFICATIONS: 154 case SYNCED_NOTIFICATIONS:
152 return sync_pb::EntitySpecifics::kSyncedNotificationFieldNumber; 155 return sync_pb::EntitySpecifics::kSyncedNotificationFieldNumber;
153 case DEVICE_INFO: 156 case DEVICE_INFO:
154 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber; 157 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber;
155 break; 158 break;
156 case EXPERIMENTS: 159 case EXPERIMENTS:
157 return sync_pb::EntitySpecifics::kExperimentsFieldNumber; 160 return sync_pb::EntitySpecifics::kExperimentsFieldNumber;
158 break; 161 break;
162 case PRIORITY_PREFERENCES:
163 return sync_pb::EntitySpecifics::kPriorityPreferenceFieldNumber;
164 break;
159 default: 165 default:
160 NOTREACHED() << "No known extension for model type."; 166 NOTREACHED() << "No known extension for model type.";
161 return 0; 167 return 0;
162 } 168 }
163 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of " 169 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of "
164 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681"; 170 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681";
165 return 0; 171 return 0;
166 } 172 }
167 173
168 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) { 174 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 259
254 if (specifics.has_synced_notification()) 260 if (specifics.has_synced_notification())
255 return SYNCED_NOTIFICATIONS; 261 return SYNCED_NOTIFICATIONS;
256 262
257 if (specifics.has_device_info()) 263 if (specifics.has_device_info())
258 return DEVICE_INFO; 264 return DEVICE_INFO;
259 265
260 if (specifics.has_experiments()) 266 if (specifics.has_experiments())
261 return EXPERIMENTS; 267 return EXPERIMENTS;
262 268
269 if (specifics.has_priority_preference())
270 return PRIORITY_PREFERENCES;
271
263 return UNSPECIFIED; 272 return UNSPECIFIED;
264 } 273 }
265 274
266 bool ShouldMaintainPosition(ModelType model_type) { 275 bool ShouldMaintainPosition(ModelType model_type) {
267 return model_type == BOOKMARKS; 276 return model_type == BOOKMARKS;
268 } 277 }
269 278
270 ModelTypeSet UserTypes() { 279 ModelTypeSet UserTypes() {
271 ModelTypeSet set; 280 ModelTypeSet set;
272 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) { 281 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) {
(...skipping 10 matching lines...) Expand all
283 encryptable_user_types.Remove(SYNCED_NOTIFICATIONS); 292 encryptable_user_types.Remove(SYNCED_NOTIFICATIONS);
284 return encryptable_user_types; 293 return encryptable_user_types;
285 } 294 }
286 295
287 ModelTypeSet ControlTypes() { 296 ModelTypeSet ControlTypes() {
288 ModelTypeSet set; 297 ModelTypeSet set;
289 for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) { 298 for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) {
290 set.Put(ModelTypeFromInt(i)); 299 set.Put(ModelTypeFromInt(i));
291 } 300 }
292 301
302 // TODO(albertb): Re-enable this when the server supports it.
303 set.Remove(PRIORITY_PREFERENCES);
304
293 return set; 305 return set;
294 } 306 }
295 307
296 bool IsControlType(ModelType model_type) { 308 bool IsControlType(ModelType model_type) {
297 return ControlTypes().Has(model_type); 309 return ControlTypes().Has(model_type);
298 } 310 }
299 311
300 const char* ModelTypeToString(ModelType model_type) { 312 const char* ModelTypeToString(ModelType model_type) {
301 // This is used in serialization routines as well as for displaying debug 313 // This is used in serialization routines as well as for displaying debug
302 // information. Do not attempt to change these string values unless you know 314 // information. Do not attempt to change these string values unless you know
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 case APP_NOTIFICATIONS: 349 case APP_NOTIFICATIONS:
338 return "App Notifications"; 350 return "App Notifications";
339 case HISTORY_DELETE_DIRECTIVES: 351 case HISTORY_DELETE_DIRECTIVES:
340 return "History Delete Directives"; 352 return "History Delete Directives";
341 case SYNCED_NOTIFICATIONS: 353 case SYNCED_NOTIFICATIONS:
342 return "Synced Notifications"; 354 return "Synced Notifications";
343 case DEVICE_INFO: 355 case DEVICE_INFO:
344 return "Device Info"; 356 return "Device Info";
345 case EXPERIMENTS: 357 case EXPERIMENTS:
346 return "Experiments"; 358 return "Experiments";
359 case PRIORITY_PREFERENCES:
360 return "Priority Preferences";
347 default: 361 default:
348 break; 362 break;
349 } 363 }
350 NOTREACHED() << "No known extension for model type."; 364 NOTREACHED() << "No known extension for model type.";
351 return "INVALID"; 365 return "INVALID";
352 } 366 }
353 367
354 StringValue* ModelTypeToValue(ModelType model_type) { 368 StringValue* ModelTypeToValue(ModelType model_type) {
355 if (model_type >= FIRST_REAL_MODEL_TYPE) { 369 if (model_type >= FIRST_REAL_MODEL_TYPE) {
356 return Value::CreateStringValue(ModelTypeToString(model_type)); 370 return Value::CreateStringValue(ModelTypeToString(model_type));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 else if (model_type_string == "App Notifications") 424 else if (model_type_string == "App Notifications")
411 return APP_NOTIFICATIONS; 425 return APP_NOTIFICATIONS;
412 else if (model_type_string == "History Delete Directives") 426 else if (model_type_string == "History Delete Directives")
413 return HISTORY_DELETE_DIRECTIVES; 427 return HISTORY_DELETE_DIRECTIVES;
414 else if (model_type_string == "Synced Notifications") 428 else if (model_type_string == "Synced Notifications")
415 return SYNCED_NOTIFICATIONS; 429 return SYNCED_NOTIFICATIONS;
416 else if (model_type_string == "Device Info") 430 else if (model_type_string == "Device Info")
417 return DEVICE_INFO; 431 return DEVICE_INFO;
418 else if (model_type_string == "Experiments") 432 else if (model_type_string == "Experiments")
419 return EXPERIMENTS; 433 return EXPERIMENTS;
434 else if (model_type_string == "Priority Preferences")
435 return PRIORITY_PREFERENCES;
420 else 436 else
421 NOTREACHED() << "No known model type corresponding to " 437 NOTREACHED() << "No known model type corresponding to "
422 << model_type_string << "."; 438 << model_type_string << ".";
423 return UNSPECIFIED; 439 return UNSPECIFIED;
424 } 440 }
425 441
426 std::string ModelTypeSetToString(ModelTypeSet model_types) { 442 std::string ModelTypeSetToString(ModelTypeSet model_types) {
427 std::string result; 443 std::string result;
428 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { 444 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) {
429 if (!result.empty()) { 445 if (!result.empty()) {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 case APP_NOTIFICATIONS: 502 case APP_NOTIFICATIONS:
487 return "google_chrome_app_notifications"; 503 return "google_chrome_app_notifications";
488 case HISTORY_DELETE_DIRECTIVES: 504 case HISTORY_DELETE_DIRECTIVES:
489 return "google_chrome_history_delete_directives"; 505 return "google_chrome_history_delete_directives";
490 case SYNCED_NOTIFICATIONS: 506 case SYNCED_NOTIFICATIONS:
491 return "google_chrome_synced_notifications"; 507 return "google_chrome_synced_notifications";
492 case DEVICE_INFO: 508 case DEVICE_INFO:
493 return "google_chrome_device_info"; 509 return "google_chrome_device_info";
494 case EXPERIMENTS: 510 case EXPERIMENTS:
495 return "google_chrome_experiments"; 511 return "google_chrome_experiments";
512 case PRIORITY_PREFERENCES:
513 return "google_chrome_priority_preferences";
496 default: 514 default:
497 break; 515 break;
498 } 516 }
499 NOTREACHED() << "No known extension for model type."; 517 NOTREACHED() << "No known extension for model type.";
500 return "INVALID"; 518 return "INVALID";
501 } 519 }
502 520
503 // TODO(akalin): Figure out a better way to do these mappings. 521 // TODO(akalin): Figure out a better way to do these mappings.
504 522
505 namespace { 523 namespace {
(...skipping 10 matching lines...) Expand all
516 const char kAppNotificationType[] = "APP"; 534 const char kAppNotificationType[] = "APP";
517 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; 535 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE";
518 const char kSessionNotificationType[] = "SESSION"; 536 const char kSessionNotificationType[] = "SESSION";
519 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; 537 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE";
520 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; 538 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION";
521 const char kHistoryDeleteDirectiveNotificationType[] = 539 const char kHistoryDeleteDirectiveNotificationType[] =
522 "HISTORY_DELETE_DIRECTIVE"; 540 "HISTORY_DELETE_DIRECTIVE";
523 const char kSyncedNotificationType[] = "SYNCED_NOTIFICATION"; 541 const char kSyncedNotificationType[] = "SYNCED_NOTIFICATION";
524 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; 542 const char kDeviceInfoNotificationType[] = "DEVICE_INFO";
525 const char kExperimentsNotificationType[] = "EXPERIMENTS"; 543 const char kExperimentsNotificationType[] = "EXPERIMENTS";
544 const char kPriorityPreferenceNotificationType[] = "PRIORITY_PREFERENCE";
526 } // namespace 545 } // namespace
527 546
528 bool RealModelTypeToNotificationType(ModelType model_type, 547 bool RealModelTypeToNotificationType(ModelType model_type,
529 std::string* notification_type) { 548 std::string* notification_type) {
530 switch (model_type) { 549 switch (model_type) {
531 case BOOKMARKS: 550 case BOOKMARKS:
532 *notification_type = kBookmarkNotificationType; 551 *notification_type = kBookmarkNotificationType;
533 return true; 552 return true;
534 case PREFERENCES: 553 case PREFERENCES:
535 *notification_type = kPreferenceNotificationType; 554 *notification_type = kPreferenceNotificationType;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 case HISTORY_DELETE_DIRECTIVES: 595 case HISTORY_DELETE_DIRECTIVES:
577 *notification_type = kHistoryDeleteDirectiveNotificationType; 596 *notification_type = kHistoryDeleteDirectiveNotificationType;
578 case SYNCED_NOTIFICATIONS: 597 case SYNCED_NOTIFICATIONS:
579 *notification_type = kSyncedNotificationType; 598 *notification_type = kSyncedNotificationType;
580 case DEVICE_INFO: 599 case DEVICE_INFO:
581 *notification_type = kDeviceInfoNotificationType; 600 *notification_type = kDeviceInfoNotificationType;
582 return true; 601 return true;
583 case EXPERIMENTS: 602 case EXPERIMENTS:
584 *notification_type = kExperimentsNotificationType; 603 *notification_type = kExperimentsNotificationType;
585 return true; 604 return true;
605 case PRIORITY_PREFERENCES:
606 *notification_type = kPriorityPreferenceNotificationType;
586 default: 607 default:
587 break; 608 break;
588 } 609 }
589 notification_type->clear(); 610 notification_type->clear();
590 return false; 611 return false;
591 } 612 }
592 613
593 bool NotificationTypeToRealModelType(const std::string& notification_type, 614 bool NotificationTypeToRealModelType(const std::string& notification_type,
594 ModelType* model_type) { 615 ModelType* model_type) {
595 if (notification_type == kBookmarkNotificationType) { 616 if (notification_type == kBookmarkNotificationType) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 } else if (notification_type == kAppNotificationNotificationType) { 658 } else if (notification_type == kAppNotificationNotificationType) {
638 *model_type = APP_NOTIFICATIONS; 659 *model_type = APP_NOTIFICATIONS;
639 return true; 660 return true;
640 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) { 661 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) {
641 *model_type = HISTORY_DELETE_DIRECTIVES; 662 *model_type = HISTORY_DELETE_DIRECTIVES;
642 } else if (notification_type == kSyncedNotificationType) { 663 } else if (notification_type == kSyncedNotificationType) {
643 *model_type = SYNCED_NOTIFICATIONS; 664 *model_type = SYNCED_NOTIFICATIONS;
644 } else if (notification_type == kDeviceInfoNotificationType) { 665 } else if (notification_type == kDeviceInfoNotificationType) {
645 *model_type = DEVICE_INFO;; 666 *model_type = DEVICE_INFO;;
646 return true; 667 return true;
668 } else if (notification_type == kPriorityPreferenceNotificationType) {
669 *model_type = PRIORITY_PREFERENCES;
670 return true;
647 } 671 }
648 *model_type = UNSPECIFIED; 672 *model_type = UNSPECIFIED;
649 return false; 673 return false;
650 } 674 }
651 675
652 bool IsRealDataType(ModelType model_type) { 676 bool IsRealDataType(ModelType model_type) {
653 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; 677 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT;
654 } 678 }
655 679
656 } // namespace syncer 680 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/protocol/sync_proto.gyp ('k') | sync/util/data_type_histogram.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698