diff options
author | albertb@google.com <albertb@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-02 20:00:51 +0000 |
---|---|---|
committer | albertb@google.com <albertb@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-02 20:00:51 +0000 |
commit | fc5062475b953d2e96dc0ba89a922893e382ef5a (patch) | |
tree | 03f78007ab30bfaa5b497b89987d1a808ed01709 /chrome/browser | |
parent | b0c8acf8a8b6f435510323c0c0435053301d1eed (diff) | |
download | chromium_src-fc5062475b953d2e96dc0ba89a922893e382ef5a.zip chromium_src-fc5062475b953d2e96dc0ba89a922893e382ef5a.tar.gz chromium_src-fc5062475b953d2e96dc0ba89a922893e382ef5a.tar.bz2 |
Sync api changes to support preferences.
BUG=34174
TEST=none
Review URL: http://codereview.chromium.org/561010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37865 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rwxr-xr-x | chrome/browser/sync/engine/syncapi.cc | 23 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncapi.h | 11 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncproto.h | 4 | ||||
-rw-r--r-- | chrome/browser/sync/glue/preference_change_processor.cc | 4 | ||||
-rw-r--r-- | chrome/browser/sync/syncable/model_type.h | 1 | ||||
-rwxr-xr-x | chrome/browser/sync/syncable/syncable.cc | 3 |
6 files changed, 43 insertions, 3 deletions
diff --git a/chrome/browser/sync/engine/syncapi.cc b/chrome/browser/sync/engine/syncapi.cc index c60df3d..7e898ce 100755 --- a/chrome/browser/sync/engine/syncapi.cc +++ b/chrome/browser/sync/engine/syncapi.cc @@ -48,6 +48,7 @@ #include "chrome/browser/sync/notifier/listener/talk_mediator.h" #include "chrome/browser/sync/notifier/listener/talk_mediator_impl.h" #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" +#include "chrome/browser/sync/protocol/preference_specifics.pb.h" #include "chrome/browser/sync/protocol/service_constants.h" #include "chrome/browser/sync/sessions/sync_session_context.h" #include "chrome/browser/sync/syncable/directory_manager.h" @@ -471,6 +472,11 @@ const sync_pb::BookmarkSpecifics& BaseNode::GetBookmarkSpecifics() const { return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::bookmark); } +const sync_pb::PreferenceSpecifics& BaseNode::GetPreferenceSpecifics() const { + DCHECK(GetModelType() == syncable::PREFERENCES); + return GetEntry()->Get(SPECIFICS).GetExtension(sync_pb::preference); +} + syncable::ModelType BaseNode::GetModelType() const { return GetEntry()->GetModelType(); } @@ -517,6 +523,19 @@ void WriteNode::PutBookmarkSpecificsAndMarkForSyncing( PutSpecificsAndMarkForSyncing(entity_specifics); } +void WriteNode::SetPreferenceSpecifics( + const sync_pb::PreferenceSpecifics& new_value) { + DCHECK(GetModelType() == syncable::PREFERENCES); + PutPreferenceSpecificsAndMarkForSyncing(new_value); +} + +void WriteNode::PutPreferenceSpecificsAndMarkForSyncing( + const sync_pb::PreferenceSpecifics& new_value) { + sync_pb::EntitySpecifics entity_specifics; + entity_specifics.MutableExtension(sync_pb::preference)->CopyFrom(new_value); + PutSpecificsAndMarkForSyncing(entity_specifics); +} + void WriteNode::PutSpecificsAndMarkForSyncing( const sync_pb::EntitySpecifics& specifics) { // Skip redundant changes. @@ -586,6 +605,10 @@ bool WriteNode::InitByCreation(syncable::ModelType model_type, PutBookmarkSpecificsAndMarkForSyncing( sync_pb::BookmarkSpecifics::default_instance()); break; + case syncable::PREFERENCES: + PutPreferenceSpecificsAndMarkForSyncing( + sync_pb::PreferenceSpecifics::default_instance()); + break; default: NOTREACHED(); } diff --git a/chrome/browser/sync/engine/syncapi.h b/chrome/browser/sync/engine/syncapi.h index b49d97a..ded5453 100644 --- a/chrome/browser/sync/engine/syncapi.h +++ b/chrome/browser/sync/engine/syncapi.h @@ -67,6 +67,7 @@ class WriteTransaction; namespace sync_pb { class BookmarkSpecifics; class EntitySpecifics; +class PreferenceSpecifics; } namespace sync_api { @@ -135,6 +136,10 @@ class BaseNode { // TODO(ncarter): Remove this datatype-specific accessor. void GetFaviconBytes(std::vector<unsigned char>* output) const; + // Getter specific to the PREFERENCE datatype. Returns protobuf + // data. Can only be called if GetModelType() == PREFERENCE. + const sync_pb::PreferenceSpecifics& GetPreferenceSpecifics() const; + // Returns the local external ID associated with the node. int64 GetExternalId() const; @@ -215,6 +220,10 @@ class WriteNode : public BaseNode { void SetURL(const GURL& url); void SetFaviconBytes(const std::vector<unsigned char>& bytes); + // Set the preference specifics (name and value). + // Should only be called if GetModelType() == PREFERENCE. + void SetPreferenceSpecifics(const sync_pb::PreferenceSpecifics& specifics); + // Implementation of BaseNode's abstract virtual accessors. virtual const syncable::Entry* GetEntry() const; @@ -233,6 +242,8 @@ class WriteNode : public BaseNode { // changes. void PutBookmarkSpecificsAndMarkForSyncing( const sync_pb::BookmarkSpecifics& new_value); + void PutPreferenceSpecificsAndMarkForSyncing( + const sync_pb::PreferenceSpecifics& new_value); void PutSpecificsAndMarkForSyncing( const sync_pb::EntitySpecifics& specifics); diff --git a/chrome/browser/sync/engine/syncproto.h b/chrome/browser/sync/engine/syncproto.h index 1d5f428..ba087df 100644 --- a/chrome/browser/sync/engine/syncproto.h +++ b/chrome/browser/sync/engine/syncproto.h @@ -8,6 +8,7 @@ #define CHROME_BROWSER_SYNC_ENGINE_SYNCPROTO_H_ #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" +#include "chrome/browser/sync/protocol/preference_specifics.pb.h" #include "chrome/browser/sync/protocol/sync.pb.h" #include "chrome/browser/sync/syncable/model_type.h" #include "chrome/browser/sync/syncable/syncable_id.h" @@ -62,6 +63,9 @@ class SyncEntity : public IdWrapper<sync_pb::SyncEntity> { if (specifics().HasExtension(sync_pb::bookmark) || has_bookmarkdata()) return syncable::BOOKMARKS; + if (specifics().HasExtension(sync_pb::preference)) + return syncable::PREFERENCES; + // Loose check for server-created top-level folders that aren't // bound to a particular model type. if (!singleton_tag().empty() && IsFolder()) diff --git a/chrome/browser/sync/glue/preference_change_processor.cc b/chrome/browser/sync/glue/preference_change_processor.cc index a05823b..257b36f 100644 --- a/chrome/browser/sync/glue/preference_change_processor.cc +++ b/chrome/browser/sync/glue/preference_change_processor.cc @@ -42,9 +42,7 @@ void PreferenceChangeProcessor::Observe(NotificationType type, error_handler()->OnUnrecoverableError(); return; } - // TODO(ncarter): Define and use a preferences model_type. - syncable::ModelType model_type = syncable::BOOKMARKS; - if (!sync_node.InitByCreation(model_type, root_node, NULL)) { + if (!sync_node.InitByCreation(syncable::PREFERENCES, root_node, NULL)) { LOG(ERROR) << "Preference node creation failed."; error_handler()->OnUnrecoverableError(); return; diff --git a/chrome/browser/sync/syncable/model_type.h b/chrome/browser/sync/syncable/model_type.h index cc00f4c4..0ec7211 100644 --- a/chrome/browser/sync/syncable/model_type.h +++ b/chrome/browser/sync/syncable/model_type.h @@ -21,6 +21,7 @@ enum ModelType { TOP_LEVEL_FOLDER, // A permanent folder whose children may be of mixed // datatypes (e.g. the "Google Chrome" folder). BOOKMARKS, // A bookmark folder or a bookmark URL object. + PREFERENCES, // A preference folder or a preference object. MODEL_TYPE_COUNT, }; diff --git a/chrome/browser/sync/syncable/syncable.cc b/chrome/browser/sync/syncable/syncable.cc index b8c66b7..d5ce7a6 100755 --- a/chrome/browser/sync/syncable/syncable.cc +++ b/chrome/browser/sync/syncable/syncable.cc @@ -36,6 +36,7 @@ #include "chrome/browser/sync/engine/syncer.h" #include "chrome/browser/sync/engine/syncer_util.h" #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" +#include "chrome/browser/sync/protocol/preference_specifics.pb.h" #include "chrome/browser/sync/protocol/service_constants.h" #include "chrome/browser/sync/syncable/directory_backing_store.h" #include "chrome/browser/sync/syncable/directory_manager.h" @@ -1025,6 +1026,8 @@ syncable::ModelType Entry::GetServerModelType() const { syncable::ModelType Entry::GetModelType() const { if (Get(SPECIFICS).HasExtension(sync_pb::bookmark)) return BOOKMARKS; + if (Get(SPECIFICS).HasExtension(sync_pb::preference)) + return PREFERENCES; if (IsRoot()) return TOP_LEVEL_FOLDER; // Loose check for server-created top-level folders that aren't |