| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 Loading... |
| 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) { |
| 240 set.Put(ModelTypeFromInt(i)); | 249 set.Put(ModelTypeFromInt(i)); |
| 241 } | 250 } |
| 242 return set; | 251 return set; |
| 243 } | 252 } |
| 244 | 253 |
| 245 ModelTypeSet ControlTypes() { | 254 ModelTypeSet ControlTypes() { |
| 246 ModelTypeSet set; | 255 ModelTypeSet set; |
| 247 for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) { | 256 for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) { |
| 248 set.Put(ModelTypeFromInt(i)); | 257 set.Put(ModelTypeFromInt(i)); |
| 249 } | 258 } |
| 259 |
| 260 // TODO(rlarocque): Re-enable this when the server supports it. |
| 261 set.Remove(DEVICE_INFO); |
| 262 |
| 250 return set; | 263 return set; |
| 251 } | 264 } |
| 252 | 265 |
| 253 bool IsControlType(ModelType model_type) { | 266 bool IsControlType(ModelType model_type) { |
| 254 return ControlTypes().Has(model_type); | 267 return ControlTypes().Has(model_type); |
| 255 } | 268 } |
| 256 | 269 |
| 257 const char* ModelTypeToString(ModelType model_type) { | 270 const char* ModelTypeToString(ModelType model_type) { |
| 258 // This is used in serialization routines as well as for displaying debug | 271 // This is used in serialization routines as well as for displaying debug |
| 259 // information. Do not attempt to change these string values unless you know | 272 // information. Do not attempt to change these string values unless you know |
| (...skipping 26 matching lines...) Expand all Loading... |
| 286 case APPS: | 299 case APPS: |
| 287 return "Apps"; | 300 return "Apps"; |
| 288 case AUTOFILL_PROFILE: | 301 case AUTOFILL_PROFILE: |
| 289 return "Autofill Profiles"; | 302 return "Autofill Profiles"; |
| 290 case APP_SETTINGS: | 303 case APP_SETTINGS: |
| 291 return "App settings"; | 304 return "App settings"; |
| 292 case EXTENSION_SETTINGS: | 305 case EXTENSION_SETTINGS: |
| 293 return "Extension settings"; | 306 return "Extension settings"; |
| 294 case APP_NOTIFICATIONS: | 307 case APP_NOTIFICATIONS: |
| 295 return "App Notifications"; | 308 return "App Notifications"; |
| 309 case DEVICE_INFO: |
| 310 return "Device Info"; |
| 296 default: | 311 default: |
| 297 break; | 312 break; |
| 298 } | 313 } |
| 299 NOTREACHED() << "No known extension for model type."; | 314 NOTREACHED() << "No known extension for model type."; |
| 300 return "INVALID"; | 315 return "INVALID"; |
| 301 } | 316 } |
| 302 | 317 |
| 303 StringValue* ModelTypeToValue(ModelType model_type) { | 318 StringValue* ModelTypeToValue(ModelType model_type) { |
| 304 if (model_type >= FIRST_REAL_MODEL_TYPE) { | 319 if (model_type >= FIRST_REAL_MODEL_TYPE) { |
| 305 return Value::CreateStringValue(ModelTypeToString(model_type)); | 320 return Value::CreateStringValue(ModelTypeToString(model_type)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 else if (model_type_string == "Sessions") | 366 else if (model_type_string == "Sessions") |
| 352 return SESSIONS; | 367 return SESSIONS; |
| 353 else if (model_type_string == "Apps") | 368 else if (model_type_string == "Apps") |
| 354 return APPS; | 369 return APPS; |
| 355 else if (model_type_string == "App settings") | 370 else if (model_type_string == "App settings") |
| 356 return APP_SETTINGS; | 371 return APP_SETTINGS; |
| 357 else if (model_type_string == "Extension settings") | 372 else if (model_type_string == "Extension settings") |
| 358 return EXTENSION_SETTINGS; | 373 return EXTENSION_SETTINGS; |
| 359 else if (model_type_string == "App Notifications") | 374 else if (model_type_string == "App Notifications") |
| 360 return APP_NOTIFICATIONS; | 375 return APP_NOTIFICATIONS; |
| 376 else if (model_type_string == "Device Info") |
| 377 return DEVICE_INFO; |
| 361 else | 378 else |
| 362 NOTREACHED() << "No known model type corresponding to " | 379 NOTREACHED() << "No known model type corresponding to " |
| 363 << model_type_string << "."; | 380 << model_type_string << "."; |
| 364 return UNSPECIFIED; | 381 return UNSPECIFIED; |
| 365 } | 382 } |
| 366 | 383 |
| 367 std::string ModelTypeSetToString(ModelTypeSet model_types) { | 384 std::string ModelTypeSetToString(ModelTypeSet model_types) { |
| 368 std::string result; | 385 std::string result; |
| 369 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { | 386 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { |
| 370 if (!result.empty()) { | 387 if (!result.empty()) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 case APPS: | 436 case APPS: |
| 420 return "google_chrome_apps"; | 437 return "google_chrome_apps"; |
| 421 case AUTOFILL_PROFILE: | 438 case AUTOFILL_PROFILE: |
| 422 return "google_chrome_autofill_profiles"; | 439 return "google_chrome_autofill_profiles"; |
| 423 case APP_SETTINGS: | 440 case APP_SETTINGS: |
| 424 return "google_chrome_app_settings"; | 441 return "google_chrome_app_settings"; |
| 425 case EXTENSION_SETTINGS: | 442 case EXTENSION_SETTINGS: |
| 426 return "google_chrome_extension_settings"; | 443 return "google_chrome_extension_settings"; |
| 427 case APP_NOTIFICATIONS: | 444 case APP_NOTIFICATIONS: |
| 428 return "google_chrome_app_notifications"; | 445 return "google_chrome_app_notifications"; |
| 446 case DEVICE_INFO: |
| 447 return "google_chrome_device_info"; |
| 429 default: | 448 default: |
| 430 break; | 449 break; |
| 431 } | 450 } |
| 432 NOTREACHED() << "No known extension for model type."; | 451 NOTREACHED() << "No known extension for model type."; |
| 433 return "INVALID"; | 452 return "INVALID"; |
| 434 } | 453 } |
| 435 | 454 |
| 436 // TODO(akalin): Figure out a better way to do these mappings. | 455 // TODO(akalin): Figure out a better way to do these mappings. |
| 437 | 456 |
| 438 namespace { | 457 namespace { |
| 439 const char kBookmarkNotificationType[] = "BOOKMARK"; | 458 const char kBookmarkNotificationType[] = "BOOKMARK"; |
| 440 const char kPreferenceNotificationType[] = "PREFERENCE"; | 459 const char kPreferenceNotificationType[] = "PREFERENCE"; |
| 441 const char kPasswordNotificationType[] = "PASSWORD"; | 460 const char kPasswordNotificationType[] = "PASSWORD"; |
| 442 const char kAutofillNotificationType[] = "AUTOFILL"; | 461 const char kAutofillNotificationType[] = "AUTOFILL"; |
| 443 const char kThemeNotificationType[] = "THEME"; | 462 const char kThemeNotificationType[] = "THEME"; |
| 444 const char kTypedUrlNotificationType[] = "TYPED_URL"; | 463 const char kTypedUrlNotificationType[] = "TYPED_URL"; |
| 445 const char kExtensionNotificationType[] = "EXTENSION"; | 464 const char kExtensionNotificationType[] = "EXTENSION"; |
| 446 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; | 465 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; |
| 447 const char kNigoriNotificationType[] = "NIGORI"; | 466 const char kNigoriNotificationType[] = "NIGORI"; |
| 448 const char kAppSettingNotificationType[] = "APP_SETTING"; | 467 const char kAppSettingNotificationType[] = "APP_SETTING"; |
| 449 const char kAppNotificationType[] = "APP"; | 468 const char kAppNotificationType[] = "APP"; |
| 450 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; | 469 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; |
| 451 const char kSessionNotificationType[] = "SESSION"; | 470 const char kSessionNotificationType[] = "SESSION"; |
| 452 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; | 471 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; |
| 453 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; | 472 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; |
| 473 const char kDeviceInfoNotificationType[] = "DEVICE_INFO"; |
| 454 } // namespace | 474 } // namespace |
| 455 | 475 |
| 456 bool RealModelTypeToNotificationType(ModelType model_type, | 476 bool RealModelTypeToNotificationType(ModelType model_type, |
| 457 std::string* notification_type) { | 477 std::string* notification_type) { |
| 458 switch (model_type) { | 478 switch (model_type) { |
| 459 case BOOKMARKS: | 479 case BOOKMARKS: |
| 460 *notification_type = kBookmarkNotificationType; | 480 *notification_type = kBookmarkNotificationType; |
| 461 return true; | 481 return true; |
| 462 case PREFERENCES: | 482 case PREFERENCES: |
| 463 *notification_type = kPreferenceNotificationType; | 483 *notification_type = kPreferenceNotificationType; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 494 return true; | 514 return true; |
| 495 case AUTOFILL_PROFILE: | 515 case AUTOFILL_PROFILE: |
| 496 *notification_type = kAutofillProfileNotificationType; | 516 *notification_type = kAutofillProfileNotificationType; |
| 497 return true; | 517 return true; |
| 498 case EXTENSION_SETTINGS: | 518 case EXTENSION_SETTINGS: |
| 499 *notification_type = kExtensionSettingNotificationType; | 519 *notification_type = kExtensionSettingNotificationType; |
| 500 return true; | 520 return true; |
| 501 case APP_NOTIFICATIONS: | 521 case APP_NOTIFICATIONS: |
| 502 *notification_type = kAppNotificationNotificationType; | 522 *notification_type = kAppNotificationNotificationType; |
| 503 return true; | 523 return true; |
| 524 case DEVICE_INFO: |
| 525 *notification_type = kDeviceInfoNotificationType; |
| 526 return true; |
| 504 default: | 527 default: |
| 505 break; | 528 break; |
| 506 } | 529 } |
| 507 notification_type->clear(); | 530 notification_type->clear(); |
| 508 return false; | 531 return false; |
| 509 } | 532 } |
| 510 | 533 |
| 511 bool NotificationTypeToRealModelType(const std::string& notification_type, | 534 bool NotificationTypeToRealModelType(const std::string& notification_type, |
| 512 ModelType* model_type) { | 535 ModelType* model_type) { |
| 513 if (notification_type == kBookmarkNotificationType) { | 536 if (notification_type == kBookmarkNotificationType) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 return true; | 571 return true; |
| 549 } else if (notification_type == kAppSettingNotificationType) { | 572 } else if (notification_type == kAppSettingNotificationType) { |
| 550 *model_type = APP_SETTINGS; | 573 *model_type = APP_SETTINGS; |
| 551 return true; | 574 return true; |
| 552 } else if (notification_type == kExtensionSettingNotificationType) { | 575 } else if (notification_type == kExtensionSettingNotificationType) { |
| 553 *model_type = EXTENSION_SETTINGS; | 576 *model_type = EXTENSION_SETTINGS; |
| 554 return true; | 577 return true; |
| 555 } else if (notification_type == kAppNotificationNotificationType) { | 578 } else if (notification_type == kAppNotificationNotificationType) { |
| 556 *model_type = APP_NOTIFICATIONS; | 579 *model_type = APP_NOTIFICATIONS; |
| 557 return true; | 580 return true; |
| 581 } else if (notification_type == kDeviceInfoNotificationType) { |
| 582 *model_type = DEVICE_INFO;; |
| 583 return true; |
| 558 } else { | 584 } else { |
| 559 *model_type = UNSPECIFIED; | 585 *model_type = UNSPECIFIED; |
| 560 return false; | 586 return false; |
| 561 } | 587 } |
| 562 } | 588 } |
| 563 | 589 |
| 564 bool IsRealDataType(ModelType model_type) { | 590 bool IsRealDataType(ModelType model_type) { |
| 565 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; | 591 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; |
| 566 } | 592 } |
| 567 | 593 |
| 568 } // namespace syncer | 594 } // namespace syncer |
| OLD | NEW |