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

Unified Diff: chrome/browser/extensions/extension_sync_data.cc

Issue 7692003: Revert 97482 - Apps/Extensions Sync refactoring -- delete most of the old glue, implement new syn... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_sync_data.cc
===================================================================
--- chrome/browser/extensions/extension_sync_data.cc (revision 97482)
+++ chrome/browser/extensions/extension_sync_data.cc (working copy)
@@ -5,121 +5,25 @@
#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),
- type_(Extension::SYNC_TYPE_NONE) {
-}
+ : uninstalled(false), enabled(false), incognito_enabled(false) {}
-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::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_);
-}
+void ExtensionSyncData::Merge(const ExtensionSyncData& new_data) {
+ CHECK_EQ(id, new_data.id);
+ CHECK(!uninstalled);
+ CHECK(!new_data.uninstalled);
-SyncData ExtensionSyncData::GetSyncData() const {
- sync_pb::EntitySpecifics specifics;
- sync_pb::ExtensionSpecifics* ext_specifics;
+ // Copy version-independent properties.
+ enabled = new_data.enabled;
+ incognito_enabled = new_data.incognito_enabled;
- switch (type_) {
- case Extension::SYNC_TYPE_EXTENSION:
- ext_specifics = specifics.MutableExtension(sync_pb::extension);
- break;
- case Extension::SYNC_TYPE_APP:
- ext_specifics =
- specifics.MutableExtension(sync_pb::app)->mutable_extension();
- break;
- default:
- LOG(FATAL) << "Attempt to get non-syncable data.";
+ // 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;
}
-
- PopulateSyncSpecifics(ext_specifics);
-
- 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.";
- }
-
- 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);
-}
-
« no previous file with comments | « chrome/browser/extensions/extension_sync_data.h ('k') | chrome/browser/extensions/extension_sync_data_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698