| Index: chrome/browser/extensions/extension_sync_data.cc
|
| diff --git a/chrome/browser/extensions/extension_sync_data.cc b/chrome/browser/extensions/extension_sync_data.cc
|
| index f315552d67e783d60f0b083345a41b4113dd11a4..2cc838756bb6c42e698265bac90ecbede5ac3fd2 100644
|
| --- a/chrome/browser/extensions/extension_sync_data.cc
|
| +++ b/chrome/browser/extensions/extension_sync_data.cc
|
| @@ -5,25 +5,121 @@
|
| #include "chrome/browser/extensions/extension_sync_data.h"
|
|
|
| #include "base/logging.h"
|
| +#include "chrome/browser/extensions/extension_service.h"
|
| +#include "chrome/browser/sync/protocol/app_specifics.pb.h"
|
| +#include "chrome/browser/sync/protocol/extension_specifics.pb.h"
|
|
|
| ExtensionSyncData::ExtensionSyncData()
|
| - : uninstalled(false), enabled(false), incognito_enabled(false) {}
|
| + : uninstalled_(false),
|
| + enabled_(false),
|
| + incognito_enabled_(false),
|
| + type_(Extension::SYNC_TYPE_NONE) {
|
| +}
|
| +
|
| +ExtensionSyncData::ExtensionSyncData(const SyncData& sync_data)
|
| + : uninstalled_(false),
|
| + enabled_(false),
|
| + incognito_enabled_(false),
|
| + type_(Extension::SYNC_TYPE_NONE) {
|
| + PopulateFromSyncData(sync_data);
|
| +}
|
| +
|
| +ExtensionSyncData::ExtensionSyncData(const SyncChange& sync_change)
|
| + : uninstalled_(sync_change.change_type() == SyncChange::ACTION_DELETE) {
|
| + PopulateFromSyncData(sync_change.sync_data());
|
| +}
|
| +
|
| +ExtensionSyncData::ExtensionSyncData(const Extension& extension,
|
| + bool enabled,
|
| + bool incognito_enabled)
|
| + : id_(extension.id()),
|
| + uninstalled_(false),
|
| + enabled_(enabled),
|
| + incognito_enabled_(incognito_enabled),
|
| + type_(extension.GetSyncType()),
|
| + version_(*extension.version()),
|
| + update_url_(extension.update_url()),
|
| + name_(extension.name()) {
|
| +}
|
|
|
| ExtensionSyncData::~ExtensionSyncData() {}
|
|
|
| -void ExtensionSyncData::Merge(const ExtensionSyncData& new_data) {
|
| - CHECK_EQ(id, new_data.id);
|
| - CHECK(!uninstalled);
|
| - CHECK(!new_data.uninstalled);
|
| +void ExtensionSyncData::PopulateSyncSpecifics(
|
| + sync_pb::ExtensionSpecifics* specifics) const {
|
| + DCHECK(Extension::IdIsValid(id_));
|
| + specifics->set_id(id_);
|
| + specifics->set_update_url(update_url_.spec());
|
| + specifics->set_version(version_.GetString());
|
| + specifics->set_enabled(enabled_);
|
| + specifics->set_incognito_enabled(incognito_enabled_);
|
| + specifics->set_name(name_);
|
| +}
|
| +
|
| +SyncData ExtensionSyncData::GetSyncData() const {
|
| + sync_pb::EntitySpecifics specifics;
|
| + sync_pb::ExtensionSpecifics* extension_specifics = NULL;
|
| +
|
| + switch (type_) {
|
| + case Extension::SYNC_TYPE_EXTENSION:
|
| + extension_specifics = specifics.MutableExtension(sync_pb::extension);
|
| + break;
|
| + case Extension::SYNC_TYPE_APP:
|
| + extension_specifics =
|
| + specifics.MutableExtension(sync_pb::app)->mutable_extension();
|
| + break;
|
| + default:
|
| + LOG(FATAL) << "Attempt to get non-syncable data.";
|
| + }
|
| +
|
| + PopulateSyncSpecifics(extension_specifics);
|
|
|
| - // Copy version-independent properties.
|
| - enabled = new_data.enabled;
|
| - incognito_enabled = new_data.incognito_enabled;
|
| + return SyncData::CreateLocalData(id_, name_, specifics);
|
| +}
|
| +
|
| +SyncChange ExtensionSyncData::GetSyncChange(
|
| + SyncChange::SyncChangeType change_type) const {
|
| + return SyncChange(change_type, GetSyncData());
|
| +}
|
| +
|
| +void ExtensionSyncData::PopulateFromExtensionSpecifics(
|
| + const sync_pb::ExtensionSpecifics& specifics) {
|
| + if (!Extension::IdIsValid(specifics.id())) {
|
| + LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics.";
|
| + }
|
| +
|
| + scoped_ptr<Version> specifics_version(
|
| + Version::GetVersionFromString(specifics.version()));
|
| + if (!specifics_version.get()) {
|
| + LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics.";
|
| + }
|
| +
|
| + // The update URL must be either empty or valid.
|
| + GURL specifics_update_url(specifics.update_url());
|
| + if (!specifics_update_url.is_empty() && !specifics_update_url.is_valid()) {
|
| + LOG(FATAL) << "Attempt to sync bad ExtensionSpecifics.";
|
| + }
|
|
|
| - // Copy version-dependent properties if version <= new_data.version.
|
| - if (version.CompareTo(new_data.version) <= 0) {
|
| - version = new_data.version;
|
| - update_url = new_data.update_url;
|
| - name = new_data.name;
|
| + id_ = specifics.id();
|
| + update_url_ = specifics_update_url;
|
| + version_ = *specifics_version;
|
| + enabled_ = specifics.enabled();
|
| + incognito_enabled_ = specifics.incognito_enabled();
|
| + name_ = specifics.name();
|
| +}
|
| +
|
| +void ExtensionSyncData::PopulateFromSyncData(const SyncData& sync_data) {
|
| + const sync_pb::EntitySpecifics& entity_specifics = sync_data.GetSpecifics();
|
| + sync_pb::ExtensionSpecifics extension_expecifics;
|
| + if (entity_specifics.HasExtension(sync_pb::extension)) {
|
| + extension_expecifics = entity_specifics.GetExtension(sync_pb::extension);
|
| + type_ = Extension::SYNC_TYPE_EXTENSION;
|
| + } else if (entity_specifics.HasExtension(sync_pb::app)) {
|
| + extension_expecifics =
|
| + entity_specifics.GetExtension(sync_pb::app).extension();
|
| + type_ = Extension::SYNC_TYPE_APP;
|
| + } else {
|
| + LOG(FATAL) << "Attempt to sync bad EntitySpecifics.";
|
| }
|
| + PopulateFromExtensionSpecifics(extension_expecifics);
|
| }
|
| +
|
|
|