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

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

Issue 10911073: NOT FOR COMMIT: Add DeviceInfo type and ChangeProcessor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix several issues Created 8 years, 3 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/sync.gyp ('k') | sync/test/engine/test_directory_setter_upper.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 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 DEVICE_INFO:
77 specifics->mutable_device_info();
78 break;
76 default: 79 default:
77 NOTREACHED() << "No known extension for model type."; 80 NOTREACHED() << "No known extension for model type.";
78 } 81 }
79 } 82 }
80 83
81 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { 84 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) {
82 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { 85 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
83 ModelType model_type = ModelTypeFromInt(i); 86 ModelType model_type = ModelTypeFromInt(i);
84 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number) 87 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number)
85 return model_type; 88 return model_type;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 break; 131 break;
129 case APP_SETTINGS: 132 case APP_SETTINGS:
130 return sync_pb::EntitySpecifics::kAppSettingFieldNumber; 133 return sync_pb::EntitySpecifics::kAppSettingFieldNumber;
131 break; 134 break;
132 case EXTENSION_SETTINGS: 135 case EXTENSION_SETTINGS:
133 return sync_pb::EntitySpecifics::kExtensionSettingFieldNumber; 136 return sync_pb::EntitySpecifics::kExtensionSettingFieldNumber;
134 break; 137 break;
135 case APP_NOTIFICATIONS: 138 case APP_NOTIFICATIONS:
136 return sync_pb::EntitySpecifics::kAppNotificationFieldNumber; 139 return sync_pb::EntitySpecifics::kAppNotificationFieldNumber;
137 break; 140 break;
141 case DEVICE_INFO:
142 return sync_pb::EntitySpecifics::kDeviceInfoFieldNumber;
143 break;
138 default: 144 default:
139 NOTREACHED() << "No known extension for model type."; 145 NOTREACHED() << "No known extension for model type.";
140 return 0; 146 return 0;
141 } 147 }
142 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of " 148 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of "
143 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681"; 149 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681";
144 return 0; 150 return 0;
145 } 151 }
146 152
147 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) { 153 FullModelTypeSet ToFullModelTypeSet(ModelTypeSet in) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 226
221 if (specifics.has_app_setting()) 227 if (specifics.has_app_setting())
222 return APP_SETTINGS; 228 return APP_SETTINGS;
223 229
224 if (specifics.has_extension_setting()) 230 if (specifics.has_extension_setting())
225 return EXTENSION_SETTINGS; 231 return EXTENSION_SETTINGS;
226 232
227 if (specifics.has_app_notification()) 233 if (specifics.has_app_notification())
228 return APP_NOTIFICATIONS; 234 return APP_NOTIFICATIONS;
229 235
236 if (specifics.has_device_info())
237 return DEVICE_INFO;
238
230 return UNSPECIFIED; 239 return UNSPECIFIED;
231 } 240 }
232 241
233 bool ShouldMaintainPosition(ModelType model_type) { 242 bool ShouldMaintainPosition(ModelType model_type) {
234 return model_type == BOOKMARKS; 243 return model_type == BOOKMARKS;
235 } 244 }
236 245
237 ModelTypeSet UserTypes() { 246 ModelTypeSet UserTypes() {
238 ModelTypeSet set; 247 ModelTypeSet set;
239 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) { 248 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 case APPS: 295 case APPS:
287 return "Apps"; 296 return "Apps";
288 case AUTOFILL_PROFILE: 297 case AUTOFILL_PROFILE:
289 return "Autofill Profiles"; 298 return "Autofill Profiles";
290 case APP_SETTINGS: 299 case APP_SETTINGS:
291 return "App settings"; 300 return "App settings";
292 case EXTENSION_SETTINGS: 301 case EXTENSION_SETTINGS:
293 return "Extension settings"; 302 return "Extension settings";
294 case APP_NOTIFICATIONS: 303 case APP_NOTIFICATIONS:
295 return "App Notifications"; 304 return "App Notifications";
305 case DEVICE_INFO:
306 return "Device Info";
296 default: 307 default:
297 break; 308 break;
298 } 309 }
299 NOTREACHED() << "No known extension for model type."; 310 NOTREACHED() << "No known extension for model type.";
300 return "INVALID"; 311 return "INVALID";
301 } 312 }
302 313
303 StringValue* ModelTypeToValue(ModelType model_type) { 314 StringValue* ModelTypeToValue(ModelType model_type) {
304 if (model_type >= FIRST_REAL_MODEL_TYPE) { 315 if (model_type >= FIRST_REAL_MODEL_TYPE) {
305 return Value::CreateStringValue(ModelTypeToString(model_type)); 316 return Value::CreateStringValue(ModelTypeToString(model_type));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 else if (model_type_string == "Sessions") 362 else if (model_type_string == "Sessions")
352 return SESSIONS; 363 return SESSIONS;
353 else if (model_type_string == "Apps") 364 else if (model_type_string == "Apps")
354 return APPS; 365 return APPS;
355 else if (model_type_string == "App settings") 366 else if (model_type_string == "App settings")
356 return APP_SETTINGS; 367 return APP_SETTINGS;
357 else if (model_type_string == "Extension settings") 368 else if (model_type_string == "Extension settings")
358 return EXTENSION_SETTINGS; 369 return EXTENSION_SETTINGS;
359 else if (model_type_string == "App Notifications") 370 else if (model_type_string == "App Notifications")
360 return APP_NOTIFICATIONS; 371 return APP_NOTIFICATIONS;
372 else if (model_type_string == "Device Info")
373 return DEVICE_INFO;
361 else 374 else
362 NOTREACHED() << "No known model type corresponding to " 375 NOTREACHED() << "No known model type corresponding to "
363 << model_type_string << "."; 376 << model_type_string << ".";
364 return UNSPECIFIED; 377 return UNSPECIFIED;
365 } 378 }
366 379
367 std::string ModelTypeSetToString(ModelTypeSet model_types) { 380 std::string ModelTypeSetToString(ModelTypeSet model_types) {
368 std::string result; 381 std::string result;
369 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { 382 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) {
370 if (!result.empty()) { 383 if (!result.empty()) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 case APPS: 432 case APPS:
420 return "google_chrome_apps"; 433 return "google_chrome_apps";
421 case AUTOFILL_PROFILE: 434 case AUTOFILL_PROFILE:
422 return "google_chrome_autofill_profiles"; 435 return "google_chrome_autofill_profiles";
423 case APP_SETTINGS: 436 case APP_SETTINGS:
424 return "google_chrome_app_settings"; 437 return "google_chrome_app_settings";
425 case EXTENSION_SETTINGS: 438 case EXTENSION_SETTINGS:
426 return "google_chrome_extension_settings"; 439 return "google_chrome_extension_settings";
427 case APP_NOTIFICATIONS: 440 case APP_NOTIFICATIONS:
428 return "google_chrome_app_notifications"; 441 return "google_chrome_app_notifications";
442 case DEVICE_INFO:
443 return "google_chrome_device_info";
429 default: 444 default:
430 break; 445 break;
431 } 446 }
432 NOTREACHED() << "No known extension for model type."; 447 NOTREACHED() << "No known extension for model type.";
433 return "INVALID"; 448 return "INVALID";
434 } 449 }
435 450
436 // TODO(akalin): Figure out a better way to do these mappings. 451 // TODO(akalin): Figure out a better way to do these mappings.
437 452
438 namespace { 453 namespace {
439 const char kBookmarkNotificationType[] = "BOOKMARK"; 454 const char kBookmarkNotificationType[] = "BOOKMARK";
440 const char kPreferenceNotificationType[] = "PREFERENCE"; 455 const char kPreferenceNotificationType[] = "PREFERENCE";
441 const char kPasswordNotificationType[] = "PASSWORD"; 456 const char kPasswordNotificationType[] = "PASSWORD";
442 const char kAutofillNotificationType[] = "AUTOFILL"; 457 const char kAutofillNotificationType[] = "AUTOFILL";
443 const char kThemeNotificationType[] = "THEME"; 458 const char kThemeNotificationType[] = "THEME";
444 const char kTypedUrlNotificationType[] = "TYPED_URL"; 459 const char kTypedUrlNotificationType[] = "TYPED_URL";
445 const char kExtensionNotificationType[] = "EXTENSION"; 460 const char kExtensionNotificationType[] = "EXTENSION";
446 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; 461 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING";
447 const char kNigoriNotificationType[] = "NIGORI"; 462 const char kNigoriNotificationType[] = "NIGORI";
448 const char kAppSettingNotificationType[] = "APP_SETTING"; 463 const char kAppSettingNotificationType[] = "APP_SETTING";
449 const char kAppNotificationType[] = "APP"; 464 const char kAppNotificationType[] = "APP";
450 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; 465 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE";
451 const char kSessionNotificationType[] = "SESSION"; 466 const char kSessionNotificationType[] = "SESSION";
452 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; 467 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE";
453 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; 468 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION";
469 const char kDeviceInfoNotificationType[] = "DEVICE_INFO";
454 } // namespace 470 } // namespace
455 471
456 bool RealModelTypeToNotificationType(ModelType model_type, 472 bool RealModelTypeToNotificationType(ModelType model_type,
457 std::string* notification_type) { 473 std::string* notification_type) {
458 switch (model_type) { 474 switch (model_type) {
459 case BOOKMARKS: 475 case BOOKMARKS:
460 *notification_type = kBookmarkNotificationType; 476 *notification_type = kBookmarkNotificationType;
461 return true; 477 return true;
462 case PREFERENCES: 478 case PREFERENCES:
463 *notification_type = kPreferenceNotificationType; 479 *notification_type = kPreferenceNotificationType;
(...skipping 30 matching lines...) Expand all
494 return true; 510 return true;
495 case AUTOFILL_PROFILE: 511 case AUTOFILL_PROFILE:
496 *notification_type = kAutofillProfileNotificationType; 512 *notification_type = kAutofillProfileNotificationType;
497 return true; 513 return true;
498 case EXTENSION_SETTINGS: 514 case EXTENSION_SETTINGS:
499 *notification_type = kExtensionSettingNotificationType; 515 *notification_type = kExtensionSettingNotificationType;
500 return true; 516 return true;
501 case APP_NOTIFICATIONS: 517 case APP_NOTIFICATIONS:
502 *notification_type = kAppNotificationNotificationType; 518 *notification_type = kAppNotificationNotificationType;
503 return true; 519 return true;
520 case DEVICE_INFO:
521 *notification_type = kDeviceInfoNotificationType;
522 return true;
504 default: 523 default:
505 break; 524 break;
506 } 525 }
507 notification_type->clear(); 526 notification_type->clear();
508 return false; 527 return false;
509 } 528 }
510 529
511 bool NotificationTypeToRealModelType(const std::string& notification_type, 530 bool NotificationTypeToRealModelType(const std::string& notification_type,
512 ModelType* model_type) { 531 ModelType* model_type) {
513 if (notification_type == kBookmarkNotificationType) { 532 if (notification_type == kBookmarkNotificationType) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 return true; 567 return true;
549 } else if (notification_type == kAppSettingNotificationType) { 568 } else if (notification_type == kAppSettingNotificationType) {
550 *model_type = APP_SETTINGS; 569 *model_type = APP_SETTINGS;
551 return true; 570 return true;
552 } else if (notification_type == kExtensionSettingNotificationType) { 571 } else if (notification_type == kExtensionSettingNotificationType) {
553 *model_type = EXTENSION_SETTINGS; 572 *model_type = EXTENSION_SETTINGS;
554 return true; 573 return true;
555 } else if (notification_type == kAppNotificationNotificationType) { 574 } else if (notification_type == kAppNotificationNotificationType) {
556 *model_type = APP_NOTIFICATIONS; 575 *model_type = APP_NOTIFICATIONS;
557 return true; 576 return true;
577 } else if (notification_type == kDeviceInfoNotificationType) {
578 *model_type = DEVICE_INFO;;
579 return true;
558 } else { 580 } else {
559 *model_type = UNSPECIFIED; 581 *model_type = UNSPECIFIED;
560 return false; 582 return false;
561 } 583 }
562 } 584 }
563 585
564 bool IsRealDataType(ModelType model_type) { 586 bool IsRealDataType(ModelType model_type) {
565 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; 587 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT;
566 } 588 }
567 589
568 } // namespace syncer 590 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/sync.gyp ('k') | sync/test/engine/test_directory_setter_upper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698