OLD | NEW |
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/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/sync/engine/syncproto.h" | 9 #include "chrome/browser/sync/engine/syncproto.h" |
10 #include "chrome/browser/sync/protocol/app_specifics.pb.h" | 10 #include "chrome/browser/sync/protocol/app_specifics.pb.h" |
11 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" | 11 #include "chrome/browser/sync/protocol/autofill_specifics.pb.h" |
12 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" | 12 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" |
13 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" | 13 #include "chrome/browser/sync/protocol/extension_specifics.pb.h" |
14 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" | 14 #include "chrome/browser/sync/protocol/nigori_specifics.pb.h" |
15 #include "chrome/browser/sync/protocol/password_specifics.pb.h" | 15 #include "chrome/browser/sync/protocol/password_specifics.pb.h" |
16 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" | 16 #include "chrome/browser/sync/protocol/preference_specifics.pb.h" |
| 17 #include "chrome/browser/sync/protocol/search_engine_specifics.pb.h" |
17 #include "chrome/browser/sync/protocol/session_specifics.pb.h" | 18 #include "chrome/browser/sync/protocol/session_specifics.pb.h" |
18 #include "chrome/browser/sync/protocol/sync.pb.h" | 19 #include "chrome/browser/sync/protocol/sync.pb.h" |
19 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" | 20 #include "chrome/browser/sync/protocol/theme_specifics.pb.h" |
20 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" | 21 #include "chrome/browser/sync/protocol/typed_url_specifics.pb.h" |
21 | 22 |
22 namespace syncable { | 23 namespace syncable { |
23 | 24 |
24 void AddDefaultExtensionValue(syncable::ModelType datatype, | 25 void AddDefaultExtensionValue(syncable::ModelType datatype, |
25 sync_pb::EntitySpecifics* specifics) { | 26 sync_pb::EntitySpecifics* specifics) { |
26 switch (datatype) { | 27 switch (datatype) { |
(...skipping 17 matching lines...) Expand all Loading... |
44 break; | 45 break; |
45 case TYPED_URLS: | 46 case TYPED_URLS: |
46 specifics->MutableExtension(sync_pb::typed_url); | 47 specifics->MutableExtension(sync_pb::typed_url); |
47 break; | 48 break; |
48 case EXTENSIONS: | 49 case EXTENSIONS: |
49 specifics->MutableExtension(sync_pb::extension); | 50 specifics->MutableExtension(sync_pb::extension); |
50 break; | 51 break; |
51 case NIGORI: | 52 case NIGORI: |
52 specifics->MutableExtension(sync_pb::nigori); | 53 specifics->MutableExtension(sync_pb::nigori); |
53 break; | 54 break; |
| 55 case SEARCH_ENGINES: |
| 56 specifics->MutableExtension(sync_pb::search_engine); |
| 57 break; |
54 case SESSIONS: | 58 case SESSIONS: |
55 specifics->MutableExtension(sync_pb::session); | 59 specifics->MutableExtension(sync_pb::session); |
56 break; | 60 break; |
57 case APPS: | 61 case APPS: |
58 specifics->MutableExtension(sync_pb::app); | 62 specifics->MutableExtension(sync_pb::app); |
59 break; | 63 break; |
60 default: | 64 default: |
61 NOTREACHED() << "No known extension for model type."; | 65 NOTREACHED() << "No known extension for model type."; |
62 } | 66 } |
63 } | 67 } |
(...skipping 30 matching lines...) Expand all Loading... |
94 break; | 98 break; |
95 case TYPED_URLS: | 99 case TYPED_URLS: |
96 return sync_pb::kTypedUrlFieldNumber; | 100 return sync_pb::kTypedUrlFieldNumber; |
97 break; | 101 break; |
98 case EXTENSIONS: | 102 case EXTENSIONS: |
99 return sync_pb::kExtensionFieldNumber; | 103 return sync_pb::kExtensionFieldNumber; |
100 break; | 104 break; |
101 case NIGORI: | 105 case NIGORI: |
102 return sync_pb::kNigoriFieldNumber; | 106 return sync_pb::kNigoriFieldNumber; |
103 break; | 107 break; |
| 108 case SEARCH_ENGINES: |
| 109 return sync_pb::kSearchEngineFieldNumber; |
| 110 break; |
104 case SESSIONS: | 111 case SESSIONS: |
105 return sync_pb::kSessionFieldNumber; | 112 return sync_pb::kSessionFieldNumber; |
106 break; | 113 break; |
107 case APPS: | 114 case APPS: |
108 return sync_pb::kAppFieldNumber; | 115 return sync_pb::kAppFieldNumber; |
109 break; | 116 break; |
110 default: | 117 default: |
111 NOTREACHED() << "No known extension for model type."; | 118 NOTREACHED() << "No known extension for model type."; |
112 return 0; | 119 return 0; |
113 } | 120 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 178 |
172 if (specifics.HasExtension(sync_pb::extension)) | 179 if (specifics.HasExtension(sync_pb::extension)) |
173 return EXTENSIONS; | 180 return EXTENSIONS; |
174 | 181 |
175 if (specifics.HasExtension(sync_pb::nigori)) | 182 if (specifics.HasExtension(sync_pb::nigori)) |
176 return NIGORI; | 183 return NIGORI; |
177 | 184 |
178 if (specifics.HasExtension(sync_pb::app)) | 185 if (specifics.HasExtension(sync_pb::app)) |
179 return APPS; | 186 return APPS; |
180 | 187 |
| 188 if (specifics.HasExtension(sync_pb::search_engine)) |
| 189 return SEARCH_ENGINES; |
| 190 |
181 if (specifics.HasExtension(sync_pb::session)) | 191 if (specifics.HasExtension(sync_pb::session)) |
182 return SESSIONS; | 192 return SESSIONS; |
183 | 193 |
184 return UNSPECIFIED; | 194 return UNSPECIFIED; |
185 } | 195 } |
186 | 196 |
187 std::string ModelTypeToString(ModelType model_type) { | 197 std::string ModelTypeToString(ModelType model_type) { |
188 switch (model_type) { | 198 switch (model_type) { |
189 case BOOKMARKS: | 199 case BOOKMARKS: |
190 return "Bookmarks"; | 200 return "Bookmarks"; |
191 case PREFERENCES: | 201 case PREFERENCES: |
192 return "Preferences"; | 202 return "Preferences"; |
193 case PASSWORDS: | 203 case PASSWORDS: |
194 return "Passwords"; | 204 return "Passwords"; |
195 case AUTOFILL: | 205 case AUTOFILL: |
196 return "Autofill"; | 206 return "Autofill"; |
197 case THEMES: | 207 case THEMES: |
198 return "Themes"; | 208 return "Themes"; |
199 case TYPED_URLS: | 209 case TYPED_URLS: |
200 return "Typed URLs"; | 210 return "Typed URLs"; |
201 case EXTENSIONS: | 211 case EXTENSIONS: |
202 return "Extensions"; | 212 return "Extensions"; |
203 case NIGORI: | 213 case NIGORI: |
204 return "Encryption keys"; | 214 return "Encryption keys"; |
| 215 case SEARCH_ENGINES: |
| 216 return "Search Engines"; |
205 case SESSIONS: | 217 case SESSIONS: |
206 return "Sessions"; | 218 return "Sessions"; |
207 case APPS: | 219 case APPS: |
208 return "Apps"; | 220 return "Apps"; |
209 case AUTOFILL_PROFILE: | 221 case AUTOFILL_PROFILE: |
210 return "Autofill Profiles"; | 222 return "Autofill Profiles"; |
211 default: | 223 default: |
212 break; | 224 break; |
213 } | 225 } |
214 NOTREACHED() << "No known extension for model type."; | 226 NOTREACHED() << "No known extension for model type."; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 else if (model_type_string == "Autofill Profiles") | 262 else if (model_type_string == "Autofill Profiles") |
251 return AUTOFILL_PROFILE; | 263 return AUTOFILL_PROFILE; |
252 else if (model_type_string == "Themes") | 264 else if (model_type_string == "Themes") |
253 return THEMES; | 265 return THEMES; |
254 else if (model_type_string == "Typed URLs") | 266 else if (model_type_string == "Typed URLs") |
255 return TYPED_URLS; | 267 return TYPED_URLS; |
256 else if (model_type_string == "Extensions") | 268 else if (model_type_string == "Extensions") |
257 return EXTENSIONS; | 269 return EXTENSIONS; |
258 else if (model_type_string == "Encryption keys") | 270 else if (model_type_string == "Encryption keys") |
259 return NIGORI; | 271 return NIGORI; |
| 272 else if (model_type_string == "Search Engines") |
| 273 return SEARCH_ENGINES; |
260 else if (model_type_string == "Sessions") | 274 else if (model_type_string == "Sessions") |
261 return SESSIONS; | 275 return SESSIONS; |
262 else if (model_type_string == "Apps") | 276 else if (model_type_string == "Apps") |
263 return APPS; | 277 return APPS; |
264 else | 278 else |
265 NOTREACHED() << "No known model type corresponding to " | 279 NOTREACHED() << "No known model type corresponding to " |
266 << model_type_string << "."; | 280 << model_type_string << "."; |
267 return UNSPECIFIED; | 281 return UNSPECIFIED; |
268 } | 282 } |
269 | 283 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 case AUTOFILL: | 348 case AUTOFILL: |
335 return "google_chrome_autofill"; | 349 return "google_chrome_autofill"; |
336 case THEMES: | 350 case THEMES: |
337 return "google_chrome_themes"; | 351 return "google_chrome_themes"; |
338 case TYPED_URLS: | 352 case TYPED_URLS: |
339 return "google_chrome_typed_urls"; | 353 return "google_chrome_typed_urls"; |
340 case EXTENSIONS: | 354 case EXTENSIONS: |
341 return "google_chrome_extensions"; | 355 return "google_chrome_extensions"; |
342 case NIGORI: | 356 case NIGORI: |
343 return "google_chrome_nigori"; | 357 return "google_chrome_nigori"; |
| 358 case SEARCH_ENGINES: |
| 359 return "google_chrome_search_engines"; |
344 case SESSIONS: | 360 case SESSIONS: |
345 return "google_chrome_sessions"; | 361 return "google_chrome_sessions"; |
346 case APPS: | 362 case APPS: |
347 return "google_chrome_apps"; | 363 return "google_chrome_apps"; |
348 case AUTOFILL_PROFILE: | 364 case AUTOFILL_PROFILE: |
349 return "google_chrome_autofill_profiles"; | 365 return "google_chrome_autofill_profiles"; |
350 default: | 366 default: |
351 break; | 367 break; |
352 } | 368 } |
353 NOTREACHED() << "No known extension for model type."; | 369 NOTREACHED() << "No known extension for model type."; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 return; | 407 return; |
392 } | 408 } |
393 case EXTENSIONS: { | 409 case EXTENSIONS: { |
394 SYNC_FREQ_HISTOGRAM("Sync.FreqExtensions", time); | 410 SYNC_FREQ_HISTOGRAM("Sync.FreqExtensions", time); |
395 return; | 411 return; |
396 } | 412 } |
397 case NIGORI: { | 413 case NIGORI: { |
398 SYNC_FREQ_HISTOGRAM("Sync.FreqNigori", time); | 414 SYNC_FREQ_HISTOGRAM("Sync.FreqNigori", time); |
399 return; | 415 return; |
400 } | 416 } |
| 417 case SEARCH_ENGINES: { |
| 418 SYNC_FREQ_HISTOGRAM("Sync.FreqSearchEngines", time); |
| 419 return; |
| 420 } |
401 case SESSIONS: { | 421 case SESSIONS: { |
402 SYNC_FREQ_HISTOGRAM("Sync.FreqSessions", time); | 422 SYNC_FREQ_HISTOGRAM("Sync.FreqSessions", time); |
403 return; | 423 return; |
404 } | 424 } |
405 case APPS: { | 425 case APPS: { |
406 SYNC_FREQ_HISTOGRAM("Sync.FreqApps", time); | 426 SYNC_FREQ_HISTOGRAM("Sync.FreqApps", time); |
407 return; | 427 return; |
408 } | 428 } |
409 default: | 429 default: |
410 LOG(ERROR) << "No known extension for model type."; | 430 LOG(ERROR) << "No known extension for model type."; |
411 } | 431 } |
412 } | 432 } |
413 | 433 |
414 #undef SYNC_FREQ_HISTOGRAM | 434 #undef SYNC_FREQ_HISTOGRAM |
415 | 435 |
416 // TODO(akalin): Figure out a better way to do these mappings. | 436 // TODO(akalin): Figure out a better way to do these mappings. |
417 | 437 |
418 namespace { | 438 namespace { |
419 const char kBookmarkNotificationType[] = "BOOKMARK"; | 439 const char kBookmarkNotificationType[] = "BOOKMARK"; |
420 const char kPreferenceNotificationType[] = "PREFERENCE"; | 440 const char kPreferenceNotificationType[] = "PREFERENCE"; |
421 const char kPasswordNotificationType[] = "PASSWORD"; | 441 const char kPasswordNotificationType[] = "PASSWORD"; |
422 const char kAutofillNotificationType[] = "AUTOFILL"; | 442 const char kAutofillNotificationType[] = "AUTOFILL"; |
423 const char kThemeNotificationType[] = "THEME"; | 443 const char kThemeNotificationType[] = "THEME"; |
424 const char kTypedUrlNotificationType[] = "TYPED_URL"; | 444 const char kTypedUrlNotificationType[] = "TYPED_URL"; |
425 const char kExtensionNotificationType[] = "EXTENSION"; | 445 const char kExtensionNotificationType[] = "EXTENSION"; |
426 const char kNigoriNotificationType[] = "NIGORI"; | 446 const char kNigoriNotificationType[] = "NIGORI"; |
427 const char kAppNotificationType[] = "APP"; | 447 const char kAppNotificationType[] = "APP"; |
| 448 const char kSearchEngineNotificationType[] = "SEARCH_ENGINE"; |
428 const char kSessionNotificationType[] = "SESSION"; | 449 const char kSessionNotificationType[] = "SESSION"; |
429 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; | 450 const char kAutofillProfileNotificationType[] = "AUTOFILL_PROFILE"; |
430 } // namespace | 451 } // namespace |
431 | 452 |
432 bool RealModelTypeToNotificationType(ModelType model_type, | 453 bool RealModelTypeToNotificationType(ModelType model_type, |
433 std::string* notification_type) { | 454 std::string* notification_type) { |
434 switch (model_type) { | 455 switch (model_type) { |
435 case BOOKMARKS: | 456 case BOOKMARKS: |
436 *notification_type = kBookmarkNotificationType; | 457 *notification_type = kBookmarkNotificationType; |
437 return true; | 458 return true; |
(...skipping 14 matching lines...) Expand all Loading... |
452 return true; | 473 return true; |
453 case EXTENSIONS: | 474 case EXTENSIONS: |
454 *notification_type = kExtensionNotificationType; | 475 *notification_type = kExtensionNotificationType; |
455 return true; | 476 return true; |
456 case NIGORI: | 477 case NIGORI: |
457 *notification_type = kNigoriNotificationType; | 478 *notification_type = kNigoriNotificationType; |
458 return true; | 479 return true; |
459 case APPS: | 480 case APPS: |
460 *notification_type = kAppNotificationType; | 481 *notification_type = kAppNotificationType; |
461 return true; | 482 return true; |
| 483 case SEARCH_ENGINES: |
| 484 *notification_type = kSearchEngineNotificationType; |
| 485 return true; |
462 case SESSIONS: | 486 case SESSIONS: |
463 *notification_type = kSessionNotificationType; | 487 *notification_type = kSessionNotificationType; |
464 return true; | 488 return true; |
465 case AUTOFILL_PROFILE: | 489 case AUTOFILL_PROFILE: |
466 *notification_type = kAutofillProfileNotificationType; | 490 *notification_type = kAutofillProfileNotificationType; |
467 return true; | 491 return true; |
468 default: | 492 default: |
469 break; | 493 break; |
470 } | 494 } |
471 notification_type->clear(); | 495 notification_type->clear(); |
(...skipping 22 matching lines...) Expand all Loading... |
494 return true; | 518 return true; |
495 } else if (notification_type == kExtensionNotificationType) { | 519 } else if (notification_type == kExtensionNotificationType) { |
496 *model_type = EXTENSIONS; | 520 *model_type = EXTENSIONS; |
497 return true; | 521 return true; |
498 } else if (notification_type == kNigoriNotificationType) { | 522 } else if (notification_type == kNigoriNotificationType) { |
499 *model_type = NIGORI; | 523 *model_type = NIGORI; |
500 return true; | 524 return true; |
501 } else if (notification_type == kAppNotificationType) { | 525 } else if (notification_type == kAppNotificationType) { |
502 *model_type = APPS; | 526 *model_type = APPS; |
503 return true; | 527 return true; |
| 528 } else if (notification_type == kSearchEngineNotificationType) { |
| 529 *model_type = SEARCH_ENGINES; |
| 530 return true; |
504 } else if (notification_type == kSessionNotificationType) { | 531 } else if (notification_type == kSessionNotificationType) { |
505 *model_type = SESSIONS; | 532 *model_type = SESSIONS; |
506 return true; | 533 return true; |
507 } else if (notification_type == kAutofillProfileNotificationType) { | 534 } else if (notification_type == kAutofillProfileNotificationType) { |
508 *model_type = AUTOFILL_PROFILE; | 535 *model_type = AUTOFILL_PROFILE; |
509 return true; | 536 return true; |
510 } | 537 } |
511 *model_type = UNSPECIFIED; | 538 *model_type = UNSPECIFIED; |
512 return false; | 539 return false; |
513 } | 540 } |
514 | 541 |
515 } // namespace syncable | 542 } // namespace syncable |
OLD | NEW |