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

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

Issue 7977018: Enable sync for the settings from the Extension Settings API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix race condition in ExtensionSettingsUIWrapper::Core Created 9 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 | « chrome/browser/sync/syncable/model_type.h ('k') | chrome/browser/sync/util/cryptographer.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/sync/syncable/model_type.h" 5 #include "chrome/browser/sync/syncable/model_type.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/string_split.h" 8 #include "base/string_split.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "chrome/browser/sync/engine/syncproto.h" 10 #include "chrome/browser/sync/engine/syncproto.h"
11 #include "chrome/browser/sync/protocol/app_specifics.pb.h" 11 #include "chrome/browser/sync/protocol/app_specifics.pb.h"
12 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" 12 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h"
13 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" 13 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h"
14 #include "chrome/browser/sync/protocol/extension_setting_specifics.pb.h"
14 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" 15 #include "chrome/browser/sync/protocol/extension_specifics.pb.h"
15 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" 16 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h"
16 #include "chrome/browser/sync/protocol/password_specifics.pb.h" 17 #include "chrome/browser/sync/protocol/password_specifics.pb.h"
17 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" 18 #include "chrome/browser/sync/protocol/preference_specifics.pb.h"
18 #include "chrome/browser/sync/protocol/search_engine_specifics.pb.h" 19 #include "chrome/browser/sync/protocol/search_engine_specifics.pb.h"
19 #include "chrome/browser/sync/protocol/session_specifics.pb.h" 20 #include "chrome/browser/sync/protocol/session_specifics.pb.h"
20 #include "chrome/browser/sync/protocol/sync.pb.h" 21 #include "chrome/browser/sync/protocol/sync.pb.h"
21 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" 22 #include "chrome/browser/sync/protocol/theme_specifics.pb.h"
22 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" 23 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h"
23 24
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 break; 56 break;
56 case SEARCH_ENGINES: 57 case SEARCH_ENGINES:
57 specifics->MutableExtension(sync_pb::search_engine); 58 specifics->MutableExtension(sync_pb::search_engine);
58 break; 59 break;
59 case SESSIONS: 60 case SESSIONS:
60 specifics->MutableExtension(sync_pb::session); 61 specifics->MutableExtension(sync_pb::session);
61 break; 62 break;
62 case APPS: 63 case APPS:
63 specifics->MutableExtension(sync_pb::app); 64 specifics->MutableExtension(sync_pb::app);
64 break; 65 break;
66 case EXTENSION_SETTINGS:
67 specifics->MutableExtension(sync_pb::extension_setting);
68 break;
65 default: 69 default:
66 NOTREACHED() << "No known extension for model type."; 70 NOTREACHED() << "No known extension for model type.";
67 } 71 }
68 } 72 }
69 73
70 ModelType GetModelTypeFromExtensionFieldNumber(int field_number) { 74 ModelType GetModelTypeFromExtensionFieldNumber(int field_number) {
71 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { 75 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
72 ModelType model_type = ModelTypeFromInt(i); 76 ModelType model_type = ModelTypeFromInt(i);
73 if (GetExtensionFieldNumberFromModelType(model_type) == field_number) 77 if (GetExtensionFieldNumberFromModelType(model_type) == field_number)
74 return model_type; 78 return model_type;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 break; 112 break;
109 case SEARCH_ENGINES: 113 case SEARCH_ENGINES:
110 return sync_pb::kSearchEngineFieldNumber; 114 return sync_pb::kSearchEngineFieldNumber;
111 break; 115 break;
112 case SESSIONS: 116 case SESSIONS:
113 return sync_pb::kSessionFieldNumber; 117 return sync_pb::kSessionFieldNumber;
114 break; 118 break;
115 case APPS: 119 case APPS:
116 return sync_pb::kAppFieldNumber; 120 return sync_pb::kAppFieldNumber;
117 break; 121 break;
122 case EXTENSION_SETTINGS:
123 return sync_pb::kExtensionSettingFieldNumber;
124 break;
118 default: 125 default:
119 NOTREACHED() << "No known extension for model type."; 126 NOTREACHED() << "No known extension for model type.";
120 return 0; 127 return 0;
121 } 128 }
122 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of " 129 NOTREACHED() << "Needed for linux_keep_shadow_stacks because of "
123 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681"; 130 << "http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20681";
124 return 0; 131 return 0;
125 } 132 }
126 133
127 // Note: keep this consistent with GetModelType in syncable.cc! 134 // Note: keep this consistent with GetModelType in syncable.cc!
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 192
186 if (specifics.HasExtension(sync_pb::app)) 193 if (specifics.HasExtension(sync_pb::app))
187 return APPS; 194 return APPS;
188 195
189 if (specifics.HasExtension(sync_pb::search_engine)) 196 if (specifics.HasExtension(sync_pb::search_engine))
190 return SEARCH_ENGINES; 197 return SEARCH_ENGINES;
191 198
192 if (specifics.HasExtension(sync_pb::session)) 199 if (specifics.HasExtension(sync_pb::session))
193 return SESSIONS; 200 return SESSIONS;
194 201
202 if (specifics.HasExtension(sync_pb::extension_setting))
203 return EXTENSION_SETTINGS;
204
195 return UNSPECIFIED; 205 return UNSPECIFIED;
196 } 206 }
197 207
198 bool ShouldMaintainPosition(ModelType model_type) { 208 bool ShouldMaintainPosition(ModelType model_type) {
199 return model_type == BOOKMARKS; 209 return model_type == BOOKMARKS;
200 } 210 }
201 211
202 std::string ModelTypeToString(ModelType model_type) { 212 std::string ModelTypeToString(ModelType model_type) {
203 switch (model_type) { 213 switch (model_type) {
204 case BOOKMARKS: 214 case BOOKMARKS:
(...skipping 13 matching lines...) Expand all
218 case NIGORI: 228 case NIGORI:
219 return "Encryption keys"; 229 return "Encryption keys";
220 case SEARCH_ENGINES: 230 case SEARCH_ENGINES:
221 return "Search Engines"; 231 return "Search Engines";
222 case SESSIONS: 232 case SESSIONS:
223 return "Sessions"; 233 return "Sessions";
224 case APPS: 234 case APPS:
225 return "Apps"; 235 return "Apps";
226 case AUTOFILL_PROFILE: 236 case AUTOFILL_PROFILE:
227 return "Autofill Profiles"; 237 return "Autofill Profiles";
238 case EXTENSION_SETTINGS:
239 return "Extension settings";
228 default: 240 default:
229 break; 241 break;
230 } 242 }
231 NOTREACHED() << "No known extension for model type."; 243 NOTREACHED() << "No known extension for model type.";
232 return "INVALID"; 244 return "INVALID";
233 } 245 }
234 246
235 StringValue* ModelTypeToValue(ModelType model_type) { 247 StringValue* ModelTypeToValue(ModelType model_type) {
236 if (model_type >= syncable::FIRST_REAL_MODEL_TYPE) { 248 if (model_type >= syncable::FIRST_REAL_MODEL_TYPE) {
237 return Value::CreateStringValue(ModelTypeToString(model_type)); 249 return Value::CreateStringValue(ModelTypeToString(model_type));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 else if (model_type_string == "Extensions") 300 else if (model_type_string == "Extensions")
289 return EXTENSIONS; 301 return EXTENSIONS;
290 else if (model_type_string == "Encryption keys") 302 else if (model_type_string == "Encryption keys")
291 return NIGORI; 303 return NIGORI;
292 else if (model_type_string == "Search Engines") 304 else if (model_type_string == "Search Engines")
293 return SEARCH_ENGINES; 305 return SEARCH_ENGINES;
294 else if (model_type_string == "Sessions") 306 else if (model_type_string == "Sessions")
295 return SESSIONS; 307 return SESSIONS;
296 else if (model_type_string == "Apps") 308 else if (model_type_string == "Apps")
297 return APPS; 309 return APPS;
310 else if (model_type_string == "Extension settings")
311 return EXTENSION_SETTINGS;
298 else 312 else
299 NOTREACHED() << "No known model type corresponding to " 313 NOTREACHED() << "No known model type corresponding to "
300 << model_type_string << "."; 314 << model_type_string << ".";
301 return UNSPECIFIED; 315 return UNSPECIFIED;
302 } 316 }
303 317
304 std::string ModelTypeBitSetToString(const ModelTypeBitSet& model_types) { 318 std::string ModelTypeBitSetToString(const ModelTypeBitSet& model_types) {
305 std::string result; 319 std::string result;
306 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { 320 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
307 if (model_types[i]) { 321 if (model_types[i]) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 case NIGORI: 394 case NIGORI:
381 return "google_chrome_nigori"; 395 return "google_chrome_nigori";
382 case SEARCH_ENGINES: 396 case SEARCH_ENGINES:
383 return "google_chrome_search_engines"; 397 return "google_chrome_search_engines";
384 case SESSIONS: 398 case SESSIONS:
385 return "google_chrome_sessions"; 399 return "google_chrome_sessions";
386 case APPS: 400 case APPS:
387 return "google_chrome_apps"; 401 return "google_chrome_apps";
388 case AUTOFILL_PROFILE: 402 case AUTOFILL_PROFILE:
389 return "google_chrome_autofill_profiles"; 403 return "google_chrome_autofill_profiles";
404 case EXTENSION_SETTINGS:
405 return "google_chrome_extension_settings";
390 default: 406 default:
391 break; 407 break;
392 } 408 }
393 NOTREACHED() << "No known extension for model type."; 409 NOTREACHED() << "No known extension for model type.";
394 return "INVALID"; 410 return "INVALID";
395 } 411 }
396 412
397 // For now, this just implements UMA_HISTOGRAM_LONG_TIMES. This can be adjusted 413 // For now, this just implements UMA_HISTOGRAM_LONG_TIMES. This can be adjusted
398 // if we feel the min, max, or bucket count amount are not appropriate. 414 // if we feel the min, max, or bucket count amount are not appropriate.
399 #define SYNC_FREQ_HISTOGRAM(name, time) UMA_HISTOGRAM_CUSTOM_TIMES( \ 415 #define SYNC_FREQ_HISTOGRAM(name, time) UMA_HISTOGRAM_CUSTOM_TIMES( \
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 return; 459 return;
444 } 460 }
445 case SESSIONS: { 461 case SESSIONS: {
446 SYNC_FREQ_HISTOGRAM("Sync.FreqSessions", time); 462 SYNC_FREQ_HISTOGRAM("Sync.FreqSessions", time);
447 return; 463 return;
448 } 464 }
449 case APPS: { 465 case APPS: {
450 SYNC_FREQ_HISTOGRAM("Sync.FreqApps", time); 466 SYNC_FREQ_HISTOGRAM("Sync.FreqApps", time);
451 return; 467 return;
452 } 468 }
469 case EXTENSION_SETTINGS: {
470 SYNC_FREQ_HISTOGRAM("Sync.FreqExtensionSettings", time);
471 return;
472 }
453 default: 473 default:
454 LOG(ERROR) << "No known extension for model type."; 474 LOG(ERROR) << "No known extension for model type.";
455 } 475 }
456 } 476 }
457 477
458 #undef SYNC_FREQ_HISTOGRAM 478 #undef SYNC_FREQ_HISTOGRAM
459 479
460 // TODO(akalin): Figure out a better way to do these mappings. 480 // TODO(akalin): Figure out a better way to do these mappings.
461 481
462 namespace { 482 namespace {
463 const char kBookmarkNotificationType[] = "BOOKMARK"; 483 const char kBookmarkNotificationType[] = "BOOKMARK";
464 const char kPreferenceNotificationType[] = "PREFERENCE"; 484 const char kPreferenceNotificationType[] = "PREFERENCE";
465 const char kPasswordNotificationType[] = "PASSWORD"; 485 const char kPasswordNotificationType[] = "PASSWORD";
466 const char kAutofillNotificationType[] = "AUTOFILL"; 486 const char kAutofillNotificationType[] = "AUTOFILL";
467 const char kThemeNotificationType[] = "THEME"; 487 const char kThemeNotificationType[] = "THEME";
468 const char kTypedUrlNotificationType[] = "TYPED_URL"; 488 const char kTypedUrlNotificationType[] = "TYPED_URL";
469 const char kExtensionNotificationType[] = "EXTENSION"; 489 const char kExtensionNotificationType[] = "EXTENSION";
490 const char kExtensionSettingNotificationType[] = "EXTENSION_SETTING";
470 const char kNigoriNotificationType[] = "NIGORI"; 491 const char kNigoriNotificationType[] = "NIGORI";
471 const char kAppNotificationType[] = "APP"; 492 const char kAppNotificationType[] = "APP";
472 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; 493 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE";
473 const char kSessionNotificationType[] = "SESSION"; 494 const char kSessionNotificationType[] = "SESSION";
474 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; 495 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE";
475 } // namespace 496 } // namespace
476 497
477 bool RealModelTypeToNotificationType(ModelType model_type, 498 bool RealModelTypeToNotificationType(ModelType model_type,
478 std::string* notification_type) { 499 std::string* notification_type) {
479 switch (model_type) { 500 switch (model_type) {
(...skipping 26 matching lines...) Expand all
506 return true; 527 return true;
507 case SEARCH_ENGINES: 528 case SEARCH_ENGINES:
508 *notification_type = kSearchEngineNotificationType; 529 *notification_type = kSearchEngineNotificationType;
509 return true; 530 return true;
510 case SESSIONS: 531 case SESSIONS:
511 *notification_type = kSessionNotificationType; 532 *notification_type = kSessionNotificationType;
512 return true; 533 return true;
513 case AUTOFILL_PROFILE: 534 case AUTOFILL_PROFILE:
514 *notification_type = kAutofillProfileNotificationType; 535 *notification_type = kAutofillProfileNotificationType;
515 return true; 536 return true;
537 case EXTENSION_SETTINGS:
538 *notification_type = kExtensionSettingNotificationType;
539 return true;
516 default: 540 default:
517 break; 541 break;
518 } 542 }
519 notification_type->clear(); 543 notification_type->clear();
520 return false; 544 return false;
521 } 545 }
522 546
523 bool NotificationTypeToRealModelType(const std::string& notification_type, 547 bool NotificationTypeToRealModelType(const std::string& notification_type,
524 ModelType* model_type) { 548 ModelType* model_type) {
525 if (notification_type == kBookmarkNotificationType) { 549 if (notification_type == kBookmarkNotificationType) {
(...skipping 25 matching lines...) Expand all
551 return true; 575 return true;
552 } else if (notification_type == kSearchEngineNotificationType) { 576 } else if (notification_type == kSearchEngineNotificationType) {
553 *model_type = SEARCH_ENGINES; 577 *model_type = SEARCH_ENGINES;
554 return true; 578 return true;
555 } else if (notification_type == kSessionNotificationType) { 579 } else if (notification_type == kSessionNotificationType) {
556 *model_type = SESSIONS; 580 *model_type = SESSIONS;
557 return true; 581 return true;
558 } else if (notification_type == kAutofillProfileNotificationType) { 582 } else if (notification_type == kAutofillProfileNotificationType) {
559 *model_type = AUTOFILL_PROFILE; 583 *model_type = AUTOFILL_PROFILE;
560 return true; 584 return true;
585 } else if (notification_type == kExtensionSettingNotificationType) {
586 *model_type = EXTENSION_SETTINGS;
587 return true;
561 } 588 }
562 *model_type = UNSPECIFIED; 589 *model_type = UNSPECIFIED;
563 return false; 590 return false;
564 } 591 }
565 592
566 ModelTypeSet GetAllRealModelTypes() { 593 ModelTypeSet GetAllRealModelTypes() {
567 ModelTypeSet all_types; 594 ModelTypeSet all_types;
568 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { 595 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) {
569 all_types.insert(ModelTypeFromInt(i)); 596 all_types.insert(ModelTypeFromInt(i));
570 } 597 }
571 return all_types; 598 return all_types;
572 } 599 }
573 600
574 bool IsRealDataType(ModelType model_type) { 601 bool IsRealDataType(ModelType model_type) {
575 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT; 602 return model_type >= FIRST_REAL_MODEL_TYPE && model_type < MODEL_TYPE_COUNT;
576 } 603 }
577 604
578 } // namespace syncable 605 } // namespace syncable
OLDNEW
« no previous file with comments | « chrome/browser/sync/syncable/model_type.h ('k') | chrome/browser/sync/util/cryptographer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698