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

Side by Side Diff: chrome/browser/sync/engine/syncapi.cc

Issue 6995008: Implement new SyncAPI and convert Preferences to it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase and fix compile Created 9 years, 7 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/engine/syncapi.h ('k') | chrome/browser/sync/engine/syncer_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) 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/engine/syncapi.h" 5 #include "chrome/browser/sync/engine/syncapi.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <bitset> 8 #include <bitset>
9 #include <iomanip> 9 #include <iomanip>
10 #include <list> 10 #include <list>
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 GetUnencryptedSpecifics(GetEntry()); 402 GetUnencryptedSpecifics(GetEntry());
403 return unencrypted.GetExtension(sync_pb::nigori); 403 return unencrypted.GetExtension(sync_pb::nigori);
404 } 404 }
405 405
406 const sync_pb::PasswordSpecificsData& BaseNode::GetPasswordSpecifics() const { 406 const sync_pb::PasswordSpecificsData& BaseNode::GetPasswordSpecifics() const {
407 DCHECK_EQ(syncable::PASSWORDS, GetModelType()); 407 DCHECK_EQ(syncable::PASSWORDS, GetModelType());
408 DCHECK(password_data_.get()); 408 DCHECK(password_data_.get());
409 return *password_data_; 409 return *password_data_;
410 } 410 }
411 411
412 const sync_pb::PreferenceSpecifics& BaseNode::GetPreferenceSpecifics() const {
413 DCHECK_EQ(syncable::PREFERENCES, GetModelType());
414 const sync_pb::EntitySpecifics& unencrypted =
415 GetUnencryptedSpecifics(GetEntry());
416 return unencrypted.GetExtension(sync_pb::preference);
417 }
418
419 const sync_pb::ThemeSpecifics& BaseNode::GetThemeSpecifics() const { 412 const sync_pb::ThemeSpecifics& BaseNode::GetThemeSpecifics() const {
420 DCHECK_EQ(syncable::THEMES, GetModelType()); 413 DCHECK_EQ(syncable::THEMES, GetModelType());
421 const sync_pb::EntitySpecifics& unencrypted = 414 const sync_pb::EntitySpecifics& unencrypted =
422 GetUnencryptedSpecifics(GetEntry()); 415 GetUnencryptedSpecifics(GetEntry());
423 return unencrypted.GetExtension(sync_pb::theme); 416 return unencrypted.GetExtension(sync_pb::theme);
424 } 417 }
425 418
426 const sync_pb::TypedUrlSpecifics& BaseNode::GetTypedUrlSpecifics() const { 419 const sync_pb::TypedUrlSpecifics& BaseNode::GetTypedUrlSpecifics() const {
427 DCHECK_EQ(syncable::TYPED_URLS, GetModelType()); 420 DCHECK_EQ(syncable::TYPED_URLS, GetModelType());
428 const sync_pb::EntitySpecifics& unencrypted = 421 const sync_pb::EntitySpecifics& unencrypted =
429 GetUnencryptedSpecifics(GetEntry()); 422 GetUnencryptedSpecifics(GetEntry());
430 return unencrypted.GetExtension(sync_pb::typed_url); 423 return unencrypted.GetExtension(sync_pb::typed_url);
431 } 424 }
432 425
433 const sync_pb::ExtensionSpecifics& BaseNode::GetExtensionSpecifics() const { 426 const sync_pb::ExtensionSpecifics& BaseNode::GetExtensionSpecifics() const {
434 DCHECK_EQ(syncable::EXTENSIONS, GetModelType()); 427 DCHECK_EQ(syncable::EXTENSIONS, GetModelType());
435 const sync_pb::EntitySpecifics& unencrypted = 428 const sync_pb::EntitySpecifics& unencrypted =
436 GetUnencryptedSpecifics(GetEntry()); 429 GetUnencryptedSpecifics(GetEntry());
437 return unencrypted.GetExtension(sync_pb::extension); 430 return unencrypted.GetExtension(sync_pb::extension);
438 } 431 }
439 432
440 const sync_pb::SessionSpecifics& BaseNode::GetSessionSpecifics() const { 433 const sync_pb::SessionSpecifics& BaseNode::GetSessionSpecifics() const {
441 DCHECK_EQ(syncable::SESSIONS, GetModelType()); 434 DCHECK_EQ(syncable::SESSIONS, GetModelType());
442 const sync_pb::EntitySpecifics& unencrypted = 435 const sync_pb::EntitySpecifics& unencrypted =
443 GetUnencryptedSpecifics(GetEntry()); 436 GetUnencryptedSpecifics(GetEntry());
444 return unencrypted.GetExtension(sync_pb::session); 437 return unencrypted.GetExtension(sync_pb::session);
445 } 438 }
446 439
440 const sync_pb::EntitySpecifics& BaseNode::GetEntitySpecifics() const {
441 const sync_pb::EntitySpecifics& unencrypted =
442 GetUnencryptedSpecifics(GetEntry());
443 return unencrypted;
444 }
445
447 syncable::ModelType BaseNode::GetModelType() const { 446 syncable::ModelType BaseNode::GetModelType() const {
448 return GetEntry()->GetModelType(); 447 return GetEntry()->GetModelType();
449 } 448 }
450 449
451 //////////////////////////////////// 450 ////////////////////////////////////
452 // WriteNode member definitions 451 // WriteNode member definitions
453 void WriteNode::EncryptIfNecessary(sync_pb::EntitySpecifics* unencrypted) { 452 void WriteNode::EncryptIfNecessary(sync_pb::EntitySpecifics* unencrypted) {
454 syncable::ModelType type = syncable::GetModelTypeFromSpecifics(*unencrypted); 453 syncable::ModelType type = syncable::GetModelTypeFromSpecifics(*unencrypted);
455 DCHECK_NE(type, syncable::UNSPECIFIED); 454 DCHECK_NE(type, syncable::UNSPECIFIED);
456 DCHECK_NE(type, syncable::PASSWORDS); // Passwords use their own encryption. 455 DCHECK_NE(type, syncable::PASSWORDS); // Passwords use their own encryption.
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 return; 592 return;
594 } 593 }
595 594
596 sync_pb::PasswordSpecifics new_value; 595 sync_pb::PasswordSpecifics new_value;
597 if (!cryptographer->Encrypt(data, new_value.mutable_encrypted())) { 596 if (!cryptographer->Encrypt(data, new_value.mutable_encrypted())) {
598 NOTREACHED(); 597 NOTREACHED();
599 } 598 }
600 PutPasswordSpecificsAndMarkForSyncing(new_value); 599 PutPasswordSpecificsAndMarkForSyncing(new_value);
601 } 600 }
602 601
603 void WriteNode::SetPreferenceSpecifics(
604 const sync_pb::PreferenceSpecifics& new_value) {
605 DCHECK_EQ(syncable::PREFERENCES, GetModelType());
606 PutPreferenceSpecificsAndMarkForSyncing(new_value);
607 }
608
609 void WriteNode::SetThemeSpecifics( 602 void WriteNode::SetThemeSpecifics(
610 const sync_pb::ThemeSpecifics& new_value) { 603 const sync_pb::ThemeSpecifics& new_value) {
611 DCHECK_EQ(syncable::THEMES, GetModelType()); 604 DCHECK_EQ(syncable::THEMES, GetModelType());
612 PutThemeSpecificsAndMarkForSyncing(new_value); 605 PutThemeSpecificsAndMarkForSyncing(new_value);
613 } 606 }
614 607
615 void WriteNode::SetSessionSpecifics( 608 void WriteNode::SetSessionSpecifics(
616 const sync_pb::SessionSpecifics& new_value) { 609 const sync_pb::SessionSpecifics& new_value) {
617 DCHECK_EQ(syncable::SESSIONS, GetModelType()); 610 DCHECK_EQ(syncable::SESSIONS, GetModelType());
618 PutSessionSpecificsAndMarkForSyncing(new_value); 611 PutSessionSpecificsAndMarkForSyncing(new_value);
619 } 612 }
620 613
614 void WriteNode::SetEntitySpecifics(
615 const sync_pb::EntitySpecifics& new_value) {
616 syncable::ModelType specifics_type =
617 syncable::GetModelTypeFromSpecifics(new_value);
618 DCHECK_EQ(specifics_type, GetModelType());
619 sync_pb::EntitySpecifics entity_specifics;
620 entity_specifics.CopyFrom(new_value);
621 EncryptIfNecessary(&entity_specifics);
622 PutSpecificsAndMarkForSyncing(entity_specifics);
623 }
624
621 void WriteNode::ResetFromSpecifics() { 625 void WriteNode::ResetFromSpecifics() {
622 sync_pb::EntitySpecifics new_data; 626 sync_pb::EntitySpecifics new_data;
623 new_data.CopyFrom(GetUnencryptedSpecifics(GetEntry())); 627 new_data.CopyFrom(GetUnencryptedSpecifics(GetEntry()));
624 EncryptIfNecessary(&new_data); 628 EncryptIfNecessary(&new_data);
625 PutSpecificsAndMarkForSyncing(new_data); 629 PutSpecificsAndMarkForSyncing(new_data);
626 } 630 }
627 631
628 void WriteNode::PutPasswordSpecificsAndMarkForSyncing( 632 void WriteNode::PutPasswordSpecificsAndMarkForSyncing(
629 const sync_pb::PasswordSpecifics& new_value) { 633 const sync_pb::PasswordSpecifics& new_value) {
630 sync_pb::EntitySpecifics entity_specifics; 634 sync_pb::EntitySpecifics entity_specifics;
631 entity_specifics.MutableExtension(sync_pb::password)->CopyFrom(new_value); 635 entity_specifics.MutableExtension(sync_pb::password)->CopyFrom(new_value);
632 PutSpecificsAndMarkForSyncing(entity_specifics); 636 PutSpecificsAndMarkForSyncing(entity_specifics);
633 } 637 }
634 638
635 void WriteNode::PutPreferenceSpecificsAndMarkForSyncing(
636 const sync_pb::PreferenceSpecifics& new_value) {
637 sync_pb::EntitySpecifics entity_specifics;
638 entity_specifics.MutableExtension(sync_pb::preference)->CopyFrom(new_value);
639 EncryptIfNecessary(&entity_specifics);
640 PutSpecificsAndMarkForSyncing(entity_specifics);
641 }
642
643 void WriteNode::SetTypedUrlSpecifics( 639 void WriteNode::SetTypedUrlSpecifics(
644 const sync_pb::TypedUrlSpecifics& new_value) { 640 const sync_pb::TypedUrlSpecifics& new_value) {
645 DCHECK_EQ(syncable::TYPED_URLS, GetModelType()); 641 DCHECK_EQ(syncable::TYPED_URLS, GetModelType());
646 PutTypedUrlSpecificsAndMarkForSyncing(new_value); 642 PutTypedUrlSpecificsAndMarkForSyncing(new_value);
647 } 643 }
648 644
649 void WriteNode::SetExtensionSpecifics( 645 void WriteNode::SetExtensionSpecifics(
650 const sync_pb::ExtensionSpecifics& new_value) { 646 const sync_pb::ExtensionSpecifics& new_value) {
651 DCHECK_EQ(syncable::EXTENSIONS, GetModelType()); 647 DCHECK_EQ(syncable::EXTENSIONS, GetModelType());
652 PutExtensionSpecificsAndMarkForSyncing(new_value); 648 PutExtensionSpecificsAndMarkForSyncing(new_value);
(...skipping 2356 matching lines...) Expand 10 before | Expand all | Expand 10 after
3009 void SyncManager::TriggerOnIncomingNotificationForTest( 3005 void SyncManager::TriggerOnIncomingNotificationForTest(
3010 const syncable::ModelTypeBitSet& model_types) { 3006 const syncable::ModelTypeBitSet& model_types) {
3011 syncable::ModelTypePayloadMap model_types_with_payloads = 3007 syncable::ModelTypePayloadMap model_types_with_payloads =
3012 syncable::ModelTypePayloadMapFromBitSet(model_types, 3008 syncable::ModelTypePayloadMapFromBitSet(model_types,
3013 std::string()); 3009 std::string());
3014 3010
3015 data_->OnIncomingNotification(model_types_with_payloads); 3011 data_->OnIncomingNotification(model_types_with_payloads);
3016 } 3012 }
3017 3013
3018 } // namespace sync_api 3014 } // namespace sync_api
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/syncapi.h ('k') | chrome/browser/sync/engine/syncer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698