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

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

Issue 10825137: FYI: Control Data + Per-Device Metadata (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add PER_USER_METADATA, refactor some encryption code Created 8 years, 4 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 PER_DEVICE_METADATA:
77 specifics->mutable_per_device_metadata();
78 break;
79 case PER_USER_METADATA:
80 specifics->mutable_per_user_metadata();
81 break;
76 default: 82 default:
77 NOTREACHED() << "No known extension for model type."; 83 NOTREACHED() << "No known extension for model type.";
78 } 84 }
79 } 85 }
80 86
81 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) { 87 ModelType GetModelTypeFromSpecificsFieldNumber(int field_number) {
82 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) {
83 ModelType model_type = ModelTypeFromInt(i); 89 ModelType model_type = ModelTypeFromInt(i);
84 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number) 90 if (GetSpecificsFieldNumberFromModelType(model_type) == field_number)
85 return model_type; 91 return model_type;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 break; 134 break;
129 case APP_SETTINGS: 135 case APP_SETTINGS:
130 return sync_pb::EntitySpecifics::kAppSettingFieldNumber; 136 return sync_pb::EntitySpecifics::kAppSettingFieldNumber;
131 break; 137 break;
132 case EXTENSION_SETTINGS: 138 case EXTENSION_SETTINGS:
133 return sync_pb::EntitySpecifics::kExtensionSettingFieldNumber; 139 return sync_pb::EntitySpecifics::kExtensionSettingFieldNumber;
134 break; 140 break;
135 case APP_NOTIFICATIONS: 141 case APP_NOTIFICATIONS:
136 return sync_pb::EntitySpecifics::kAppNotificationFieldNumber; 142 return sync_pb::EntitySpecifics::kAppNotificationFieldNumber;
137 break; 143 break;
144 case PER_DEVICE_METADATA:
145 return sync_pb::EntitySpecifics::kPerDeviceMetadataFieldNumber;
146 break;
147 case PER_USER_METADATA:
148 return sync_pb::EntitySpecifics::kPerUserMetadataFieldNumber;
149 break;
138 default: 150 default:
139 NOTREACHED() << "No known extension for model type."; 151 NOTREACHED() << "No known extension for model type.";
140 return 0; 152 return 0;
141 } 153 }
142 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of " 154 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of "
143 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681"; 155 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681";
144 return 0; 156 return 0;
145 } 157 }
146 158
147 // Note: keep this consistent with GetModelType in syncable.cc! 159 // Note: keep this consistent with GetModelType in syncable.cc!
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 224
213 if (specifics.has_app_setting()) 225 if (specifics.has_app_setting())
214 return APP_SETTINGS; 226 return APP_SETTINGS;
215 227
216 if (specifics.has_extension_setting()) 228 if (specifics.has_extension_setting())
217 return EXTENSION_SETTINGS; 229 return EXTENSION_SETTINGS;
218 230
219 if (specifics.has_app_notification()) 231 if (specifics.has_app_notification())
220 return APP_NOTIFICATIONS; 232 return APP_NOTIFICATIONS;
221 233
234 if (specifics.has_per_device_metadata())
235 return PER_DEVICE_METADATA;
236
237 if (specifics.has_per_user_metadata())
238 return PER_USER_METADATA;
239
222 return UNSPECIFIED; 240 return UNSPECIFIED;
223 } 241 }
224 242
225 bool ShouldMaintainPosition(ModelType model_type) { 243 bool ShouldMaintainPosition(ModelType model_type) {
226 return model_type == BOOKMARKS; 244 return model_type == BOOKMARKS;
227 } 245 }
228 246
247 bool IsControlType(ModelType model_type) {
248 return ControlTypes().Has(model_type);
249 }
250
251 ModelTypeSet ControlTypes() {
252 ModelTypeSet set;
253 set.Put(NIGORI);
254 set.Put(PER_DEVICE_METADATA);
255 set.Put(PER_USER_METADATA);
256 return set;
257 }
258
259 ModelTypeSet EncryptableTypes() {
260 ModelTypeSet unencryptable_types(PER_DEVICE_METADATA, PER_USER_METADATA);
rlarocque 2012/08/11 01:31:52 Why do these types skip encryption? I believe the
261 return Difference(ModelTypeSet::All(), unencryptable_types);
262 }
263
229 const char* ModelTypeToString(ModelType model_type) { 264 const char* ModelTypeToString(ModelType model_type) {
230 // This is used in serialization routines as well as for displaying debug 265 // This is used in serialization routines as well as for displaying debug
231 // information. Do not attempt to change these string values unless you know 266 // information. Do not attempt to change these string values unless you know
232 // what you're doing. 267 // what you're doing.
233 switch (model_type) { 268 switch (model_type) {
234 case TOP_LEVEL_FOLDER: 269 case TOP_LEVEL_FOLDER:
235 return "Top Level Folder"; 270 return "Top Level Folder";
236 case UNSPECIFIED: 271 case UNSPECIFIED:
237 return "Unspecified"; 272 return "Unspecified";
238 case BOOKMARKS: 273 case BOOKMARKS:
(...skipping 19 matching lines...) Expand all
258 case APPS: 293 case APPS:
259 return "Apps"; 294 return "Apps";
260 case AUTOFILL_PROFILE: 295 case AUTOFILL_PROFILE:
261 return "Autofill Profiles"; 296 return "Autofill Profiles";
262 case APP_SETTINGS: 297 case APP_SETTINGS:
263 return "App settings"; 298 return "App settings";
264 case EXTENSION_SETTINGS: 299 case EXTENSION_SETTINGS:
265 return "Extension settings"; 300 return "Extension settings";
266 case APP_NOTIFICATIONS: 301 case APP_NOTIFICATIONS:
267 return "App Notifications"; 302 return "App Notifications";
303 case PER_DEVICE_METADATA:
304 return "Device Metadata";
305 case PER_USER_METADATA:
306 return "User Metadata";
268 default: 307 default:
269 break; 308 break;
270 } 309 }
271 NOTREACHED() << "No known extension for model type."; 310 NOTREACHED() << "No known extension for model type.";
272 return "INVALID"; 311 return "INVALID";
273 } 312 }
274 313
275 StringValue* ModelTypeToValue(ModelType model_type) { 314 StringValue* ModelTypeToValue(ModelType model_type) {
276 if (model_type >= FIRST_REAL_MODEL_TYPE) { 315 if (model_type >= FIRST_REAL_MODEL_TYPE) {
277 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
323 else if (model_type_string == "Sessions") 362 else if (model_type_string == "Sessions")
324 return SESSIONS; 363 return SESSIONS;
325 else if (model_type_string == "Apps") 364 else if (model_type_string == "Apps")
326 return APPS; 365 return APPS;
327 else if (model_type_string == "App settings") 366 else if (model_type_string == "App settings")
328 return APP_SETTINGS; 367 return APP_SETTINGS;
329 else if (model_type_string == "Extension settings") 368 else if (model_type_string == "Extension settings")
330 return EXTENSION_SETTINGS; 369 return EXTENSION_SETTINGS;
331 else if (model_type_string == "App Notifications") 370 else if (model_type_string == "App Notifications")
332 return APP_NOTIFICATIONS; 371 return APP_NOTIFICATIONS;
372 else if (model_type_string == "Device Metadata")
373 return PER_DEVICE_METADATA;
374 else if (model_type_string == "User Metadata")
375 return PER_USER_METADATA;
333 else 376 else
334 NOTREACHED() << "No known model type corresponding to " 377 NOTREACHED() << "No known model type corresponding to "
335 << model_type_string << "."; 378 << model_type_string << ".";
336 return UNSPECIFIED; 379 return UNSPECIFIED;
337 } 380 }
338 381
339 std::string ModelTypeSetToString(ModelTypeSet model_types) { 382 std::string ModelTypeSetToString(ModelTypeSet model_types) {
340 std::string result; 383 std::string result;
341 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { 384 for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) {
342 if (!result.empty()) { 385 if (!result.empty()) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 case APPS: 434 case APPS:
392 return "google_chrome_apps"; 435 return "google_chrome_apps";
393 case AUTOFILL_PROFILE: 436 case AUTOFILL_PROFILE:
394 return "google_chrome_autofill_profiles"; 437 return "google_chrome_autofill_profiles";
395 case APP_SETTINGS: 438 case APP_SETTINGS:
396 return "google_chrome_app_settings"; 439 return "google_chrome_app_settings";
397 case EXTENSION_SETTINGS: 440 case EXTENSION_SETTINGS:
398 return "google_chrome_extension_settings"; 441 return "google_chrome_extension_settings";
399 case APP_NOTIFICATIONS: 442 case APP_NOTIFICATIONS:
400 return "google_chrome_app_notifications"; 443 return "google_chrome_app_notifications";
444 case PER_DEVICE_METADATA:
445 return "google_chrome_per_device_metadata";
446 case PER_USER_METADATA:
447 return "google_chrome_per_user_metadata";
401 default: 448 default:
402 break; 449 break;
403 } 450 }
404 NOTREACHED() << "No known extension for model type."; 451 NOTREACHED() << "No known extension for model type.";
405 return "INVALID"; 452 return "INVALID";
406 } 453 }
407 454
408 // TODO(akalin): Figure out a better way to do these mappings. 455 // TODO(akalin): Figure out a better way to do these mappings.
409 456
410 namespace { 457 namespace {
411 const char kBookmarkNotificationType[] = "BOOKMARK"; 458 const char kBookmarkNotificationType[] = "BOOKMARK";
412 const char kPreferenceNotificationType[] = "PREFERENCE"; 459 const char kPreferenceNotificationType[] = "PREFERENCE";
413 const char kPasswordNotificationType[] = "PASSWORD"; 460 const char kPasswordNotificationType[] = "PASSWORD";
414 const char kAutofillNotificationType[] = "AUTOFILL"; 461 const char kAutofillNotificationType[] = "AUTOFILL";
415 const char kThemeNotificationType[] = "THEME"; 462 const char kThemeNotificationType[] = "THEME";
416 const char kTypedUrlNotificationType[] = "TYPED_URL"; 463 const char kTypedUrlNotificationType[] = "TYPED_URL";
417 const char kExtensionNotificationType[] = "EXTENSION"; 464 const char kExtensionNotificationType[] = "EXTENSION";
418 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING"; 465 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING";
419 const char kNigoriNotificationType[] = "NIGORI"; 466 const char kNigoriNotificationType[] = "NIGORI";
420 const char kAppSettingNotificationType[] = "APP_SETTING"; 467 const char kAppSettingNotificationType[] = "APP_SETTING";
421 const char kAppNotificationType[] = "APP"; 468 const char kAppNotificationType[] = "APP";
422 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; 469 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE";
423 const char kSessionNotificationType[] = "SESSION"; 470 const char kSessionNotificationType[] = "SESSION";
424 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; 471 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE";
425 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION"; 472 const char kAppNotificationNotificationType[] = "APP_NOTIFICATION";
473 const char kPerDeviceNotificationType[] = "PER_DEVICE_METADATA";
474 const char kPerUserNotificationType[] = "PER_USER_METADATA";
426 } // namespace 475 } // namespace
427 476
428 bool RealModelTypeToNotificationType(ModelType model_type, 477 bool RealModelTypeToNotificationType(ModelType model_type,
429 std::string* notification_type) { 478 std::string* notification_type) {
430 switch (model_type) { 479 switch (model_type) {
431 case BOOKMARKS: 480 case BOOKMARKS:
432 *notification_type = kBookmarkNotificationType; 481 *notification_type = kBookmarkNotificationType;
433 return true; 482 return true;
434 case PREFERENCES: 483 case PREFERENCES:
435 *notification_type = kPreferenceNotificationType; 484 *notification_type = kPreferenceNotificationType;
(...skipping 30 matching lines...) Expand all
466 return true; 515 return true;
467 case AUTOFILL_PROFILE: 516 case AUTOFILL_PROFILE:
468 *notification_type = kAutofillProfileNotificationType; 517 *notification_type = kAutofillProfileNotificationType;
469 return true; 518 return true;
470 case EXTENSION_SETTINGS: 519 case EXTENSION_SETTINGS:
471 *notification_type = kExtensionSettingNotificationType; 520 *notification_type = kExtensionSettingNotificationType;
472 return true; 521 return true;
473 case APP_NOTIFICATIONS: 522 case APP_NOTIFICATIONS:
474 *notification_type = kAppNotificationNotificationType; 523 *notification_type = kAppNotificationNotificationType;
475 return true; 524 return true;
525 case PER_DEVICE_METADATA:
526 *notification_type = kPerDeviceNotificationType;
527 return true;
528 case PER_USER_METADATA:
529 *notification_type = kPerUserNotificationType;
530 return true;
476 default: 531 default:
477 break; 532 break;
478 } 533 }
479 notification_type->clear(); 534 notification_type->clear();
480 return false; 535 return false;
481 } 536 }
482 537
483 bool NotificationTypeToRealModelType(const std::string& notification_type, 538 bool NotificationTypeToRealModelType(const std::string& notification_type,
484 ModelType* model_type) { 539 ModelType* model_type) {
485 if (notification_type == kBookmarkNotificationType) { 540 if (notification_type == kBookmarkNotificationType) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 return true; 575 return true;
521 } else if (notification_type == kAppSettingNotificationType) { 576 } else if (notification_type == kAppSettingNotificationType) {
522 *model_type = APP_SETTINGS; 577 *model_type = APP_SETTINGS;
523 return true; 578 return true;
524 } else if (notification_type == kExtensionSettingNotificationType) { 579 } else if (notification_type == kExtensionSettingNotificationType) {
525 *model_type = EXTENSION_SETTINGS; 580 *model_type = EXTENSION_SETTINGS;
526 return true; 581 return true;
527 } else if (notification_type == kAppNotificationNotificationType) { 582 } else if (notification_type == kAppNotificationNotificationType) {
528 *model_type = APP_NOTIFICATIONS; 583 *model_type = APP_NOTIFICATIONS;
529 return true; 584 return true;
585 } else if (notification_type == kPerDeviceNotificationType) {
586 *model_type = PER_DEVICE_METADATA;;
587 return true;
588 } else if (notification_type == kPerUserNotificationType) {
589 *model_type = PER_USER_METADATA;;
590 return true;
530 } else { 591 } else {
531 *model_type = UNSPECIFIED; 592 *model_type = UNSPECIFIED;
532 return false; 593 return false;
533 } 594 }
534 } 595 }
535 596
536 bool IsRealDataType(ModelType model_type) { 597 bool IsRealDataType(ModelType model_type) {
537 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; 598 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT;
538 } 599 }
539 600
540 } // namespace syncer 601 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698