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

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

Issue 10855037: [Sync] Add history delete directive type (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync to head, add TODO Created 8 years, 2 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
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 case APPS: 307 case APPS:
300 return "Apps"; 308 return "Apps";
301 case AUTOFILL_PROFILE: 309 case AUTOFILL_PROFILE:
302 return "Autofill Profiles"; 310 return "Autofill Profiles";
303 case APP_SETTINGS: 311 case APP_SETTINGS:
304 return "App settings"; 312 return "App settings";
305 case EXTENSION_SETTINGS: 313 case EXTENSION_SETTINGS:
306 return "Extension settings"; 314 return "Extension settings";
307 case APP_NOTIFICATIONS: 315 case APP_NOTIFICATIONS:
308 return "App Notifications"; 316 return "App Notifications";
317 case HISTORY_DELETE_DIRECTIVES:
318 return "History Delete Directives";
309 case DEVICE_INFO: 319 case DEVICE_INFO:
310 return "Device Info"; 320 return "Device Info";
311 default: 321 default:
312 break; 322 break;
313 } 323 }
314 NOTREACHED() << "No known extension for model type."; 324 NOTREACHED() << "No known extension for model type.";
315 return "INVALID"; 325 return "INVALID";
316 } 326 }
317 327
318 StringValue* ModelTypeToValue(ModelType model_type) { 328 StringValue* ModelTypeToValue(ModelType model_type) {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 else if (model_type_string == "Sessions") 376 else if (model_type_string == "Sessions")
367 return SESSIONS; 377 return SESSIONS;
368 else if (model_type_string == "Apps") 378 else if (model_type_string == "Apps")
369 return APPS; 379 return APPS;
370 else if (model_type_string == "App settings") 380 else if (model_type_string == "App settings")
371 return APP_SETTINGS; 381 return APP_SETTINGS;
372 else if (model_type_string == "Extension settings") 382 else if (model_type_string == "Extension settings")
373 return EXTENSION_SETTINGS; 383 return EXTENSION_SETTINGS;
374 else if (model_type_string == "App Notifications") 384 else if (model_type_string == "App Notifications")
375 return APP_NOTIFICATIONS; 385 return APP_NOTIFICATIONS;
386 else if (model_type_string == "History Delete Directives")
387 return HISTORY_DELETE_DIRECTIVES;
376 else if (model_type_string == "Device Info") 388 else if (model_type_string == "Device Info")
377 return DEVICE_INFO; 389 return DEVICE_INFO;
378 else 390 else
379 NOTREACHED() << "No known model type corresponding to " 391 NOTREACHED() << "No known model type corresponding to "
380 << model_type_string << "."; 392 << model_type_string << ".";
381 return UNSPECIFIED; 393 return UNSPECIFIED;
382 } 394 }
383 395
384 std::string ModelTypeSetToString(ModelTypeSet model_types) { 396 std::string ModelTypeSetToString(ModelTypeSet model_types) {
385 std::string result; 397 std::string result;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 case APPS: 448 case APPS:
437 return "google_chrome_apps"; 449 return "google_chrome_apps";
438 case AUTOFILL_PROFILE: 450 case AUTOFILL_PROFILE:
439 return "google_chrome_autofill_profiles"; 451 return "google_chrome_autofill_profiles";
440 case APP_SETTINGS: 452 case APP_SETTINGS:
441 return "google_chrome_app_settings"; 453 return "google_chrome_app_settings";
442 case EXTENSION_SETTINGS: 454 case EXTENSION_SETTINGS:
443 return "google_chrome_extension_settings"; 455 return "google_chrome_extension_settings";
444 case APP_NOTIFICATIONS: 456 case APP_NOTIFICATIONS:
445 return "google_chrome_app_notifications"; 457 return "google_chrome_app_notifications";
458 case HISTORY_DELETE_DIRECTIVES:
459 return "google_chrome_history_delete_directives";
446 case DEVICE_INFO: 460 case DEVICE_INFO:
447 return "google_chrome_device_info"; 461 return "google_chrome_device_info";
448 default: 462 default:
449 break; 463 break;
450 } 464 }
451 NOTREACHED() << "No known extension for model type."; 465 NOTREACHED() << "No known extension for model type.";
452 return "INVALID"; 466 return "INVALID";
453 } 467 }
454 468
455 // TODO(akalin): Figure out a better way to do these mappings. 469 // TODO(akalin): Figure out a better way to do these mappings.
456 470
457 namespace { 471 namespace {
458 const char kBookmarkNotificationType[] = "BOOKMARK"; 472 const char kBookmarkNotificationType[] = "BOOKMARK";
459 const char kPreferenceNotificationType[] = "PREFERENCE"; 473 const char kPreferenceNotificationType[] = "PREFERENCE";
460 const char kPasswordNotificationType[] = "PASSWORD"; 474 const char kPasswordNotificationType[] = "PASSWORD";
461 const char kAutofillNotificationType[] = "AUTOFILL"; 475 const char kAutofillNotificationType[] = "AUTOFILL";
462 const char kThemeNotificationType[] = "THEME"; 476 const char kThemeNotificationType[] = "THEME";
463 const char kTypedUrlNotificationType[] = "TYPED_URL"; 477 const char kTypedUrlNotificationType[] = "TYPED_URL";
464 const char kExtensionNotificationType[] = "EXTENSION"; 478 const char kExtensionNotificationType[] = "EXTENSION";
465 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; 479 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING";
466 const char kNigoriNotificationType[] = "NIGORI"; 480 const char kNigoriNotificationType[] = "NIGORI";
467 const char kAppSettingNotificationType[] = "APP_SETTING"; 481 const char kAppSettingNotificationType[] = "APP_SETTING";
468 const char kAppNotificationType[] = "APP"; 482 const char kAppNotificationType[] = "APP";
469 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; 483 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE";
470 const char kSessionNotificationType[] = "SESSION"; 484 const char kSessionNotificationType[] = "SESSION";
471 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; 485 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE";
472 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; 486 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION";
487 const char kHistoryDeleteDirectiveNotificationType[] =
488 "HISTORY_DELETE_DIRECTIVE";
473 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; 489 const char kDeviceInfoNotificationType[] = "DEVICE_INFO";
474 } // namespace 490 } // namespace
475 491
476 bool RealModelTypeToNotificationType(ModelType model_type, 492 bool RealModelTypeToNotificationType(ModelType model_type,
477 std::string* notification_type) { 493 std::string* notification_type) {
478 switch (model_type) { 494 switch (model_type) {
479 case BOOKMARKS: 495 case BOOKMARKS:
480 *notification_type = kBookmarkNotificationType; 496 *notification_type = kBookmarkNotificationType;
481 return true; 497 return true;
482 case PREFERENCES: 498 case PREFERENCES:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 return true; 530 return true;
515 case AUTOFILL_PROFILE: 531 case AUTOFILL_PROFILE:
516 *notification_type = kAutofillProfileNotificationType; 532 *notification_type = kAutofillProfileNotificationType;
517 return true; 533 return true;
518 case EXTENSION_SETTINGS: 534 case EXTENSION_SETTINGS:
519 *notification_type = kExtensionSettingNotificationType; 535 *notification_type = kExtensionSettingNotificationType;
520 return true; 536 return true;
521 case APP_NOTIFICATIONS: 537 case APP_NOTIFICATIONS:
522 *notification_type = kAppNotificationNotificationType; 538 *notification_type = kAppNotificationNotificationType;
523 return true; 539 return true;
540 case HISTORY_DELETE_DIRECTIVES:
541 *notification_type = kHistoryDeleteDirectiveNotificationType;
524 case DEVICE_INFO: 542 case DEVICE_INFO:
525 *notification_type = kDeviceInfoNotificationType; 543 *notification_type = kDeviceInfoNotificationType;
526 return true; 544 return true;
527 default: 545 default:
528 break; 546 break;
529 } 547 }
530 notification_type->clear(); 548 notification_type->clear();
531 return false; 549 return false;
532 } 550 }
533 551
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 return true; 589 return true;
572 } else if (notification_type == kAppSettingNotificationType) { 590 } else if (notification_type == kAppSettingNotificationType) {
573 *model_type = APP_SETTINGS; 591 *model_type = APP_SETTINGS;
574 return true; 592 return true;
575 } else if (notification_type == kExtensionSettingNotificationType) { 593 } else if (notification_type == kExtensionSettingNotificationType) {
576 *model_type = EXTENSION_SETTINGS; 594 *model_type = EXTENSION_SETTINGS;
577 return true; 595 return true;
578 } else if (notification_type == kAppNotificationNotificationType) { 596 } else if (notification_type == kAppNotificationNotificationType) {
579 *model_type = APP_NOTIFICATIONS; 597 *model_type = APP_NOTIFICATIONS;
580 return true; 598 return true;
599 } else if (notification_type == kHistoryDeleteDirectiveNotificationType) {
600 *model_type = HISTORY_DELETE_DIRECTIVES;
581 } else if (notification_type == kDeviceInfoNotificationType) { 601 } else if (notification_type == kDeviceInfoNotificationType) {
582 *model_type = DEVICE_INFO;; 602 *model_type = DEVICE_INFO;;
583 return true; 603 return true;
584 } else {
585 *model_type = UNSPECIFIED;
586 return false;
587 } 604 }
605 *model_type = UNSPECIFIED;
606 return false;
588 } 607 }
589 608
590 bool IsRealDataType(ModelType model_type) { 609 bool IsRealDataType(ModelType model_type) {
591 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; 610 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT;
592 } 611 }
593 612
594 } // namespace syncer 613 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698