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" |
11 #include "sync/protocol/app_specifics.pb.h" | 11 #include "sync/protocol/app_specifics.pb.h" |
12 #include "sync/protocol/autofill_specifics.pb.h" | 12 #include "sync/protocol/autofill_specifics.pb.h" |
13 #include "sync/protocol/bookmark_specifics.pb.h" | 13 #include "sync/protocol/bookmark_specifics.pb.h" |
14 #include "sync/protocol/extension_setting_specifics.pb.h" | 14 #include "sync/protocol/extension_setting_specifics.pb.h" |
15 #include "sync/protocol/extension_specifics.pb.h" | 15 #include "sync/protocol/extension_specifics.pb.h" |
16 #include "sync/protocol/nigori_specifics.pb.h" | 16 #include "sync/protocol/nigori_specifics.pb.h" |
17 #include "sync/protocol/password_specifics.pb.h" | 17 #include "sync/protocol/password_specifics.pb.h" |
18 #include "sync/protocol/preference_specifics.pb.h" | 18 #include "sync/protocol/preference_specifics.pb.h" |
19 #include "sync/protocol/search_engine_specifics.pb.h" | 19 #include "sync/protocol/search_engine_specifics.pb.h" |
20 #include "sync/protocol/session_specifics.pb.h" | 20 #include "sync/protocol/session_specifics.pb.h" |
21 #include "sync/protocol/sync.pb.h" | 21 #include "sync/protocol/sync.pb.h" |
22 #include "sync/protocol/theme_specifics.pb.h" | 22 #include "sync/protocol/theme_specifics.pb.h" |
23 #include "sync/protocol/typed_url_specifics.pb.h" | 23 #include "sync/protocol/typed_url_specifics.pb.h" |
24 #include "sync/syncable/syncable_proto_util.h" | 24 #include "sync/syncable/syncable_proto_util.h" |
25 | 25 |
26 namespace syncer { | 26 namespace syncer { |
27 | 27 |
28 void AddDefaultFieldValue(ModelType datatype, | 28 void AddDefaultFieldValue(ModelType datatype, |
29 sync_pb::EntitySpecifics* specifics) { | 29 sync_pb::EntitySpecifics* specifics) { |
30 if (VirtualTypes().Has(datatype)) { | |
31 NOTREACHED() << "Virtual types have no default field."; | |
32 return; | |
33 } | |
30 switch (datatype) { | 34 switch (datatype) { |
31 case BOOKMARKS: | 35 case BOOKMARKS: |
32 specifics->mutable_bookmark(); | 36 specifics->mutable_bookmark(); |
33 break; | 37 break; |
34 case PASSWORDS: | 38 case PASSWORDS: |
35 specifics->mutable_password(); | 39 specifics->mutable_password(); |
36 break; | 40 break; |
37 case PREFERENCES: | 41 case PREFERENCES: |
38 specifics->mutable_preference(); | 42 specifics->mutable_preference(); |
39 break; | 43 break; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 specifics->mutable_dictionary(); | 96 specifics->mutable_dictionary(); |
93 break; | 97 break; |
94 default: | 98 default: |
95 NOTREACHED() << "No known extension for model type."; | 99 NOTREACHED() << "No known extension for model type."; |
96 } | 100 } |
97 } | 101 } |
98 | 102 |
99 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { | 103 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { |
100 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 104 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
101 ModelType model_type = ModelTypeFromInt(i); | 105 ModelType model_type = ModelTypeFromInt(i); |
106 if (VirtualTypes().Has(model_type)) | |
107 continue; | |
102 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number) | 108 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number) |
103 return model_type; | 109 return model_type; |
104 } | 110 } |
105 return UNSPECIFIED; | 111 return UNSPECIFIED; |
106 } | 112 } |
107 | 113 |
108 int GetSpecificsFieldNumberFromModelType(ModelType model_type) { | 114 int GetSpecificsFieldNumberFromModelType(ModelType model_type) { |
115 if (VirtualTypes().Has(model_type)) { | |
116 NOTREACHED() << "Virtual types have no field number."; | |
117 return 0; | |
118 } | |
109 switch (model_type) { | 119 switch (model_type) { |
110 case BOOKMARKS: | 120 case BOOKMARKS: |
111 return sync_pb::EntitySpecifics::kBookmarkFieldNumber; | 121 return sync_pb::EntitySpecifics::kBookmarkFieldNumber; |
112 break; | 122 break; |
113 case PASSWORDS: | 123 case PASSWORDS: |
114 return sync_pb::EntitySpecifics::kPasswordFieldNumber; | 124 return sync_pb::EntitySpecifics::kPasswordFieldNumber; |
115 break; | 125 break; |
116 case PREFERENCES: | 126 case PREFERENCES: |
117 return sync_pb::EntitySpecifics::kPreferenceFieldNumber; | 127 return sync_pb::EntitySpecifics::kPreferenceFieldNumber; |
118 break; | 128 break; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
292 } | 302 } |
293 return set; | 303 return set; |
294 } | 304 } |
295 | 305 |
296 ModelTypeSet EncryptableUserTypes() { | 306 ModelTypeSet EncryptableUserTypes() { |
297 ModelTypeSet encryptable_user_types = UserTypes(); | 307 ModelTypeSet encryptable_user_types = UserTypes(); |
298 // We never encrypt history delete directives. | 308 // We never encrypt history delete directives. |
299 encryptable_user_types.Remove(HISTORY_DELETE_DIRECTIVES); | 309 encryptable_user_types.Remove(HISTORY_DELETE_DIRECTIVES); |
300 // Synced notifications are not encrypted since the server must see changes. | 310 // Synced notifications are not encrypted since the server must see changes. |
301 encryptable_user_types.Remove(SYNCED_NOTIFICATIONS); | 311 encryptable_user_types.Remove(SYNCED_NOTIFICATIONS); |
312 // Virtual types have no sync representation and are therefore not encrypted | |
313 // either. Their underlying implicit types may or may not be encrypted | |
314 // though. | |
tim (not reviewing)
2013/02/05 02:41:58
'Their underlying implicit types may or may not be
Nicolas Zea
2013/02/07 01:18:48
Done.
| |
315 encryptable_user_types.RemoveAll(VirtualTypes()); | |
302 return encryptable_user_types; | 316 return encryptable_user_types; |
303 } | 317 } |
304 | 318 |
305 ModelTypeSet ControlTypes() { | 319 ModelTypeSet ControlTypes() { |
306 ModelTypeSet set; | 320 ModelTypeSet set; |
307 for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) { | 321 for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) { |
308 set.Put(ModelTypeFromInt(i)); | 322 set.Put(ModelTypeFromInt(i)); |
309 } | 323 } |
310 | 324 |
311 // TODO(albertb): Re-enable this when the server supports it. | 325 // TODO(albertb): Re-enable this when the server supports it. |
312 set.Remove(PRIORITY_PREFERENCES); | 326 set.Remove(PRIORITY_PREFERENCES); |
313 | 327 |
314 return set; | 328 return set; |
315 } | 329 } |
316 | 330 |
331 ModelTypeSet VirtualTypes() { | |
332 ModelTypeSet set; | |
333 // TODO(zea): add a TABS type here. | |
334 return set; | |
335 } | |
336 | |
317 bool IsControlType(ModelType model_type) { | 337 bool IsControlType(ModelType model_type) { |
318 return ControlTypes().Has(model_type); | 338 return ControlTypes().Has(model_type); |
319 } | 339 } |
320 | 340 |
321 const char* ModelTypeToString(ModelType model_type) { | 341 const char* ModelTypeToString(ModelType model_type) { |
322 // This is used in serialization routines as well as for displaying debug | 342 // This is used in serialization routines as well as for displaying debug |
323 // information. Do not attempt to change these string values unless you know | 343 // information. Do not attempt to change these string values unless you know |
324 // what you're doing. | 344 // what you're doing. |
325 switch (model_type) { | 345 switch (model_type) { |
326 case TOP_LEVEL_FOLDER: | 346 case TOP_LEVEL_FOLDER: |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
475 ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value) { | 495 ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value) { |
476 ModelTypeSet result; | 496 ModelTypeSet result; |
477 for (ListValue::const_iterator i = value.begin(); i != value.end(); ++i) { | 497 for (ListValue::const_iterator i = value.begin(); i != value.end(); ++i) { |
478 result.Put(ModelTypeFromValue(**i)); | 498 result.Put(ModelTypeFromValue(**i)); |
479 } | 499 } |
480 return result; | 500 return result; |
481 } | 501 } |
482 | 502 |
483 // TODO(zea): remove all hardcoded tags in model associators and have them use | 503 // TODO(zea): remove all hardcoded tags in model associators and have them use |
484 // this instead. | 504 // this instead. |
505 // NOTE: Virtual types should return empty strings (so that we don't NOTREACHED | |
506 // in tests when we verify they have no root node). | |
485 std::string ModelTypeToRootTag(ModelType type) { | 507 std::string ModelTypeToRootTag(ModelType type) { |
486 switch (type) { | 508 switch (type) { |
487 case BOOKMARKS: | 509 case BOOKMARKS: |
488 return "google_chrome_bookmarks"; | 510 return "google_chrome_bookmarks"; |
489 case PREFERENCES: | 511 case PREFERENCES: |
490 return "google_chrome_preferences"; | 512 return "google_chrome_preferences"; |
491 case PASSWORDS: | 513 case PASSWORDS: |
492 return "google_chrome_passwords"; | 514 return "google_chrome_passwords"; |
493 case AUTOFILL: | 515 case AUTOFILL: |
494 return "google_chrome_autofill"; | 516 return "google_chrome_autofill"; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
527 case DICTIONARY: | 549 case DICTIONARY: |
528 return "google_chrome_dictionary"; | 550 return "google_chrome_dictionary"; |
529 default: | 551 default: |
530 break; | 552 break; |
531 } | 553 } |
532 NOTREACHED() << "No known extension for model type."; | 554 NOTREACHED() << "No known extension for model type."; |
533 return "INVALID"; | 555 return "INVALID"; |
534 } | 556 } |
535 | 557 |
536 // TODO(akalin): Figure out a better way to do these mappings. | 558 // TODO(akalin): Figure out a better way to do these mappings. |
537 | 559 // Note: Do not include virtual types in this list. They should never receive |
560 // or trigger notifications. | |
538 namespace { | 561 namespace { |
539 const char kBookmarkNotificationType[] = "BOOKMARK"; | 562 const char kBookmarkNotificationType[] = "BOOKMARK"; |
540 const char kPreferenceNotificationType[] = "PREFERENCE"; | 563 const char kPreferenceNotificationType[] = "PREFERENCE"; |
541 const char kPasswordNotificationType[] = "PASSWORD"; | 564 const char kPasswordNotificationType[] = "PASSWORD"; |
542 const char kAutofillNotificationType[] = "AUTOFILL"; | 565 const char kAutofillNotificationType[] = "AUTOFILL"; |
543 const char kThemeNotificationType[] = "THEME"; | 566 const char kThemeNotificationType[] = "THEME"; |
544 const char kTypedUrlNotificationType[] = "TYPED_URL"; | 567 const char kTypedUrlNotificationType[] = "TYPED_URL"; |
545 const char kExtensionNotificationType[] = "EXTENSION"; | 568 const char kExtensionNotificationType[] = "EXTENSION"; |
546 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; | 569 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; |
547 const char kNigoriNotificationType[] = "NIGORI"; | 570 const char kNigoriNotificationType[] = "NIGORI"; |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
701 } | 724 } |
702 *model_type = UNSPECIFIED; | 725 *model_type = UNSPECIFIED; |
703 return false; | 726 return false; |
704 } | 727 } |
705 | 728 |
706 bool IsRealDataType(ModelType model_type) { | 729 bool IsRealDataType(ModelType model_type) { |
707 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; | 730 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; |
708 } | 731 } |
709 | 732 |
710 } // namespace syncer | 733 } // namespace syncer |
OLD | NEW |