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

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

Issue 11958029: [Sync] Add support for proxy types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Switch to ProxyTypes Created 7 years, 10 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/syncable/directory_backing_store_unittest.cc ('k') | sync/syncable/model_type_unittest.cc » ('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"
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 (!ProtocolTypes().Has(datatype)) {
31 NOTREACHED() << "Only protocol types have field values.";
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 break; 94 break;
91 case DICTIONARY: 95 case DICTIONARY:
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 ModelTypeSet protocol_types = ProtocolTypes();
101 ModelType model_type = ModelTypeFromInt(i); 105 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good();
102 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number) 106 iter.Inc()) {
103 return model_type; 107 if (GetSpecificsFieldNumberFromModelType(iter.Get()) == field_number)
108 return iter.Get();
104 } 109 }
105 return UNSPECIFIED; 110 return UNSPECIFIED;
106 } 111 }
107 112
108 int GetSpecificsFieldNumberFromModelType(ModelType model_type) { 113 int GetSpecificsFieldNumberFromModelType(ModelType model_type) {
114 if (!ProtocolTypes().Has(model_type)) {
115 NOTREACHED() << "Only protocol types have field values.";
116 return 0;
117 }
109 switch (model_type) { 118 switch (model_type) {
110 case BOOKMARKS: 119 case BOOKMARKS:
111 return sync_pb::EntitySpecifics::kBookmarkFieldNumber; 120 return sync_pb::EntitySpecifics::kBookmarkFieldNumber;
112 break; 121 break;
113 case PASSWORDS: 122 case PASSWORDS:
114 return sync_pb::EntitySpecifics::kPasswordFieldNumber; 123 return sync_pb::EntitySpecifics::kPasswordFieldNumber;
115 break; 124 break;
116 case PREFERENCES: 125 case PREFERENCES:
117 return sync_pb::EntitySpecifics::kPreferenceFieldNumber; 126 return sync_pb::EntitySpecifics::kPreferenceFieldNumber;
118 break; 127 break;
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 if (specifics.has_dictionary()) 287 if (specifics.has_dictionary())
279 return DICTIONARY; 288 return DICTIONARY;
280 289
281 return UNSPECIFIED; 290 return UNSPECIFIED;
282 } 291 }
283 292
284 bool ShouldMaintainPosition(ModelType model_type) { 293 bool ShouldMaintainPosition(ModelType model_type) {
285 return model_type == BOOKMARKS; 294 return model_type == BOOKMARKS;
286 } 295 }
287 296
297 ModelTypeSet ProtocolTypes() {
298 ModelTypeSet set = ModelTypeSet::All();
299 set.RemoveAll(ProxyTypes());
300 return set;
301 }
302
288 ModelTypeSet UserTypes() { 303 ModelTypeSet UserTypes() {
289 ModelTypeSet set; 304 ModelTypeSet set;
305 // TODO(sync): We should be able to build the actual enumset's internal
306 // bitset value here at compile time, rather than performing an iteration
307 // every time.
290 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) { 308 for (int i = FIRST_USER_MODEL_TYPE; i <= LAST_USER_MODEL_TYPE; ++i) {
291 set.Put(ModelTypeFromInt(i)); 309 set.Put(ModelTypeFromInt(i));
292 } 310 }
293 return set; 311 return set;
294 } 312 }
295 313
296 ModelTypeSet EncryptableUserTypes() { 314 ModelTypeSet EncryptableUserTypes() {
297 ModelTypeSet encryptable_user_types = UserTypes(); 315 ModelTypeSet encryptable_user_types = UserTypes();
298 // We never encrypt history delete directives. 316 // We never encrypt history delete directives.
299 encryptable_user_types.Remove(HISTORY_DELETE_DIRECTIVES); 317 encryptable_user_types.Remove(HISTORY_DELETE_DIRECTIVES);
300 // Synced notifications are not encrypted since the server must see changes. 318 // Synced notifications are not encrypted since the server must see changes.
301 encryptable_user_types.Remove(SYNCED_NOTIFICATIONS); 319 encryptable_user_types.Remove(SYNCED_NOTIFICATIONS);
320 // Proxy types have no sync representation and are therefore not encrypted.
321 // Note however that proxy types map to one or more protocol types, which
322 // may or may not be encrypted themselves.
323 encryptable_user_types.RemoveAll(ProxyTypes());
302 return encryptable_user_types; 324 return encryptable_user_types;
303 } 325 }
304 326
305 ModelTypeSet ControlTypes() { 327 ModelTypeSet ControlTypes() {
306 ModelTypeSet set; 328 ModelTypeSet set;
329 // TODO(sync): We should be able to build the actual enumset's internal
330 // bitset value here at compile time, rather than performing an iteration
331 // every time.
307 for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) { 332 for (int i = FIRST_CONTROL_MODEL_TYPE; i <= LAST_CONTROL_MODEL_TYPE; ++i) {
308 set.Put(ModelTypeFromInt(i)); 333 set.Put(ModelTypeFromInt(i));
309 } 334 }
310 335
311 // TODO(albertb): Re-enable this when the server supports it. 336 // TODO(albertb): Re-enable this when the server supports it.
312 set.Remove(PRIORITY_PREFERENCES); 337 set.Remove(PRIORITY_PREFERENCES);
313 338
314 return set; 339 return set;
315 } 340 }
316 341
342 ModelTypeSet ProxyTypes() {
343 ModelTypeSet set;
344 // TODO(zea): add a TABS type here.
345 return set;
346 }
347
317 bool IsControlType(ModelType model_type) { 348 bool IsControlType(ModelType model_type) {
318 return ControlTypes().Has(model_type); 349 return ControlTypes().Has(model_type);
319 } 350 }
320 351
321 const char* ModelTypeToString(ModelType model_type) { 352 const char* ModelTypeToString(ModelType model_type) {
322 // This is used in serialization routines as well as for displaying debug 353 // 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 354 // information. Do not attempt to change these string values unless you know
324 // what you're doing. 355 // what you're doing.
325 switch (model_type) { 356 switch (model_type) {
326 case TOP_LEVEL_FOLDER: 357 case TOP_LEVEL_FOLDER:
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value) { 506 ModelTypeSet ModelTypeSetFromValue(const base::ListValue& value) {
476 ModelTypeSet result; 507 ModelTypeSet result;
477 for (ListValue::const_iterator i = value.begin(); i != value.end(); ++i) { 508 for (ListValue::const_iterator i = value.begin(); i != value.end(); ++i) {
478 result.Put(ModelTypeFromValue(**i)); 509 result.Put(ModelTypeFromValue(**i));
479 } 510 }
480 return result; 511 return result;
481 } 512 }
482 513
483 // TODO(zea): remove all hardcoded tags in model associators and have them use 514 // TODO(zea): remove all hardcoded tags in model associators and have them use
484 // this instead. 515 // this instead.
516 // NOTE: Proxy types should return empty strings (so that we don't NOTREACHED
517 // in tests when we verify they have no root node).
485 std::string ModelTypeToRootTag(ModelType type) { 518 std::string ModelTypeToRootTag(ModelType type) {
486 switch (type) { 519 switch (type) {
487 case BOOKMARKS: 520 case BOOKMARKS:
488 return "google_chrome_bookmarks"; 521 return "google_chrome_bookmarks";
489 case PREFERENCES: 522 case PREFERENCES:
490 return "google_chrome_preferences"; 523 return "google_chrome_preferences";
491 case PASSWORDS: 524 case PASSWORDS:
492 return "google_chrome_passwords"; 525 return "google_chrome_passwords";
493 case AUTOFILL: 526 case AUTOFILL:
494 return "google_chrome_autofill"; 527 return "google_chrome_autofill";
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 case DICTIONARY: 560 case DICTIONARY:
528 return "google_chrome_dictionary"; 561 return "google_chrome_dictionary";
529 default: 562 default:
530 break; 563 break;
531 } 564 }
532 NOTREACHED() << "No known extension for model type."; 565 NOTREACHED() << "No known extension for model type.";
533 return "INVALID"; 566 return "INVALID";
534 } 567 }
535 568
536 // TODO(akalin): Figure out a better way to do these mappings. 569 // TODO(akalin): Figure out a better way to do these mappings.
537 570 // Note: Do not include proxy types in this list. They should never receive
571 // or trigger notifications.
538 namespace { 572 namespace {
539 const char kBookmarkNotificationType[] = "BOOKMARK"; 573 const char kBookmarkNotificationType[] = "BOOKMARK";
540 const char kPreferenceNotificationType[] = "PREFERENCE"; 574 const char kPreferenceNotificationType[] = "PREFERENCE";
541 const char kPasswordNotificationType[] = "PASSWORD"; 575 const char kPasswordNotificationType[] = "PASSWORD";
542 const char kAutofillNotificationType[] = "AUTOFILL"; 576 const char kAutofillNotificationType[] = "AUTOFILL";
543 const char kThemeNotificationType[] = "THEME"; 577 const char kThemeNotificationType[] = "THEME";
544 const char kTypedUrlNotificationType[] = "TYPED_URL"; 578 const char kTypedUrlNotificationType[] = "TYPED_URL";
545 const char kExtensionNotificationType[] = "EXTENSION"; 579 const char kExtensionNotificationType[] = "EXTENSION";
546 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; 580 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING";
547 const char kNigoriNotificationType[] = "NIGORI"; 581 const char kNigoriNotificationType[] = "NIGORI";
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 } 735 }
702 *model_type = UNSPECIFIED; 736 *model_type = UNSPECIFIED;
703 return false; 737 return false;
704 } 738 }
705 739
706 bool IsRealDataType(ModelType model_type) { 740 bool IsRealDataType(ModelType model_type) {
707 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; 741 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT;
708 } 742 }
709 743
710 } // namespace syncer 744 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/syncable/directory_backing_store_unittest.cc ('k') | sync/syncable/model_type_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698